Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created November 21, 2012 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/4124420 to your computer and use it in GitHub Desktop.
Save svandragt/4124420 to your computer and use it in GitHub Desktop.
Debug shows steps, but gridfield doesn't if author is not admin.
Debug shows steps, but gridfield doesn't if author is not admin. I can open the step if I know the url though, but the gridfield says 'no items found'.
<?php
class HowtoPage extends DocumentPage {
public static $has_many = array(
'Steps' => 'Step',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
Debug::show($this->Steps()); // shows steps when exist
$gf_config = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
$gridfield = new GridField("Steps", "Steps:", $this->Steps()->sort(array('SortOrder' => 'asc', 'ID'=>'asc')), $gf_config);
$fields->insertAfter($gridfield, "Content"); // shows gridfield but with 'no items found'
return $fields;
}
}
@svandragt
Copy link
Author

Solution: add the following methods to the Step.php DataObject:

public function canView($member = null) {
return $this->HowtoPage()->canView($member);
}

public function canEdit($member = null) {
    return $this->HowtoPage()->canEdit($member);
}

public function canDelete($member = null) {
    return $this->HowtoPage()->canDelete($member);
}

public function canCreate($member = null) {
    return $this->HowtoPage()->canCreate($member);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment