Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Add tab to Page via module

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

Page: 1
Go to End
Author Topic: 393 Views
  • omnicurse
    Community Member
    8 Posts

    Add tab to Page via module Link to this post


    I'm trying to create a standalone module that will add a new tab to the standard Page type page in the CMS.

    This was easy enough to do using a DataExtension but then whenever I tried to add a dataobject to that dataextension via the gridfield I was getting "canView()[..]" errors.

    So I back tracked and in my module created a file named Page and added the code I wanted in there and that worked fine with the exception that when I created another module using the same method, the CMS would only show the first module and not the second.

    Whats the best approach here? Should I be using a DataExtesion and figuring out what I can't attach objects to it? Or should I be figuring out why having two modules with both the class Page override the last loaded?


    class QuestionAnswer extends DataExtension
    private static $db = array(
    'TestTextField' => 'Varchar(3)',

    private static $has_many = array(
    'FAQ' => 'FAQ'

    public function updateCMSFields(FieldList $fields)
    $fields->addFieldsToTab('Root.QuestionsAndAnswers', array(
    GridField::create('FAQ', 'Questions and Answers', FAQ::get(), GridFieldConfig_RecordEditor::create())

    class FAQ extends DataObject
    private static $db = array(
    'Title' => 'Varchar(155)',
    'Answer' => 'HTMLText',
    'SortOrder' => 'Int'

    private static $has_one = array(
    'QuestionAnswer' => 'QuestionAnswer'

    This technically works, but obviously returns all the FAQ objects, rather than just the ones you'd expect. Can someone explain how to resolve this? Using..

    GridField::create('FAQ', 'Questions and Answers', $this->FAQ(), GridFieldConfig_RecordEditor::create())

    Just returns a white screen (even when in dev, with php debugging enabled) so I'm a little lost.

    edit again:

    I've solved it by making the dataobject FAQ belong to Page and then referencing $this->owner->FAQ() on the gridfield. This feels really dirty and hackery... Is there a better solution?

  • Willr
    Forum Moderator
    5497 Posts

    Re: Add tab to Page via module Link to this post

    'QuestionAnswer' you cannot link a relation to this object. The extension is on Page correct? so you should link the relation to 'Page'.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.