Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Allowing Content Authors to edit dataobject in Gridfield


Reply


4 Posts   963 Views

Avatar
James Bolitho

Community Member, 33 Posts

15 August 2012 at 5:33am

Edited: 05/12/2012 10:37am

Hi,

I am having a bit of trouble working out how to allow Content Authors to create, edit, publish and delete records through the Gridfield.

In Silverstripe 2.4 I just used to add the following code to the dataobject that was being managed through a complex table field for example but this doesn't seem to work for the Gridfield in 3.0:

function canEdit() { return true; }
function canDelete() { return true; }
function canCreate() { return true; }
function canPublish() { return true; }

I am sure I am missing something simple so would be grateful if anyone could point me in the right direction.

Cheers,

Jim

[bold]Edit[/bold]

I was right I just missed out something really obvious. Just needed to add canView. This is what I ended up using for information:

function canEdit($member = null)
{
return true;
}
function canDelete($member = null)
{
return true;
}
function canCreate($member = null)
{
return true;
}
function canPublish($member = null)
{
return true;
}
function canView($member = null)
{
return true;
}

Avatar
Chris Dangerfield

Community Member, 8 Posts

9 October 2013 at 9:43am

Edited: 09/10/2013 4:24pm

Thanks for this James - really helpful!

And, just so that others don't make the same mistake - don't include the canPublish() permission, as that seems to be just on SiteTree and when I included this it mucked things up for me.

Avatar
kinglozzer

Community Member, 164 Posts

9 October 2013 at 9:17pm

Just for reference, the way I usually do this is:

/**
* @return boolean
*/
public function canView($member = null) {
   return Permission::check('CMS_ACCESS_CMSMain');
}

/**
* @return boolean
*/
public function canCreate($member = null) {
   return Permission::check('CMS_ACCESS_CMSMain');
}

/**
* @return boolean
*/
public function canEdit($member=null) {
   return Permission::check('CMS_ACCESS_CMSMain');
}

/**
* @return boolean
*/
public function canDelete($member = null) {
   return Permission::check('CMS_ACCESS_CMSMain');
}

Avatar
cmc

Community Member, 23 Posts

16 October 2013 at 4:27am

Thanks for this answer and thanks for using a descriptive subject line. After searching Google and Silvertripe.org with variations including "content editors" and "dataextension" I was about to start a separate topic. Fortunately I saw this in the topic list first.