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.

Form Questions /

Table Field not displaying 'delete' option for non Administrators


Reply


2 Posts   1038 Views

Avatar
Spyk

Community Member, 2 Posts

3 December 2010 at 10:46am

Edited: 03/12/2010 11:05am

Hi there,

Within my template I have a TableField that is only displaying the Delete icon when the user has Full Administrative rights.
Does anyone know why my contend editors can't delete data in the TableField?

Here's the section of code:

function getCMSFields() {

$fields = parent::getCMSFields();

//Program Rank Fields

$Top10ProgramsTable = new TableField('Top10ProgramsField', 'ProgramRank',array('Rank'=>'Rank','Program'=>'Program', 'Channel'=>'Channel', 'Audience'=>'Audience'), array('Rank'=>'TextField', 'Program'=>'TextField', 'Channel'=>'TextField', 'Audience'=>'TextField'), "MyNewsletterID",$this->ID);

$Top10ProgramsTable->setExtraData(array('MyNewsletterID' => $this->ID ? $this->ID : '$RecordID'));

$Top10ProgramsTable->setPermissions(array('edit', 'add', 'delete')); //adding and removing this line doesn't affect the outcome

return $fields;

}

static $has_many = array(
'Top10Programs' => 'ProgramRank');

class ProgramRank extends DataObject {

static $db = array(
'Rank' => 'Text',
'Program' => 'Text',
'Channel' => 'Text',
'Audience' => 'Text'

);

static $has_one = array(
'MyNewsletter' => 'TwoColumnNewsletter'
);

}

Thank you

Avatar
sktzoootech

Community Member, 5 Posts

30 March 2013 at 1:48pm

Hi there,

I was looking for a solution for the same problem via google but unfortunately I couldn't find one. So I started looking for some answers through the codes found in the core SS framework. I found out that on line 50 of the TableField.ss template, it shows that <% if Can(delete) %> ... <% end_if %> doesn't get executed because Can(delete) is always null within the context of the loop block (lines 44 to 52). So even if you have set the mode to "delete" explicitly via the setPermissions method, it doesn't work.

So the work around for this issue is to copy the file TableField.ss from the folder "sapphire/templates/" to your themes folder "themes/mysite". After you copy the template file, replace line 50 with <% if Top.Can(delete) %> to make sure the Can method refers to the context outside of the loop block.

You can actually directly edit the "TableField.ss" which is part of core SS but its bad practice. It is ideal to keep your core files untouched by copying templates that needs revisions to your themes folder. Anyways, the templates found in the themes folder has higher precedence than the ones found in the core SS templates folder.

I hope the above makes sense to anyone who have the same issue. :)