Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » extraFields in GridFields making crazy things

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

Page: 1
Go to End
Author Topic: 230 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    extraFields in GridFields making crazy things Link to this post

    Hey guys,

    I´ve working with many_many_extraFields to generate TextFields in related DataObjects.
    But after setting the extraFields, I can´t call the variables in the related object (like: $this->ID, $this->Title).

    MyParent.php

    class MyParent extends DataObject{
       private static $db = array(
          "Title" => "Varchar(255)"
       );

       static $many_many = array(
          'MyChildren' => 'MyChild'
       );

       public static $many_many_extraFields = array(
    'MyChildren' => array('Foo' => 'Varchar(255)')
    );

       public function getCMSFields(){
          $fields = parent::getCMSFields();
          
          $config = GridFieldConfig_RecordEditor::create();
          $childrenFields = singleton('MyChild')->getCMSFields();
    $childrenFields->addFieldToTab('Root.Main', TextField::create('ManyMany[Foo]', 'Foo'));
          $config->getComponentByType('GridFieldDetailForm')->setFields($childrenFields);

          $gridfield = new GridField("MyChildren", "MyChild", $this->MyChildren(), $config);
          
          $fields->addFieldToTab("Root.Main", $gridfield);

          return $fields;
       }
    }

    MyChild.php

    class MyChild extends DataObject{
       private static $db = array(
          "Title" => "Varchar(255)"
       );

       private static $belongs_many_many = array(
          "MyParents" => "MyParent"
       );

       public function getCMSFields(){
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Main", new LiteralField("Foo", $this->ID));
          return $fields;
       }
    }

    Has anyone a solution or a workaround?

    230 Views
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.