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

extraFields in GridFields making crazy things


Reply


267 Views

Avatar
Bereusei

Community Member, 94 Posts

4 March 2014 at 11:06pm

Edited: 04/03/2014 11:07pm

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?