/**
  * Setup the CMS Fields
  *
  * @param FieldList
  */
 public function updateCMSFields(FieldList $fields)
 {
     if (!$this->supportsElemental()) {
         return false;
     }
     // add an empty holder for content as some module explicitly use insert
     // after content.
     $fields->replaceField('Content', new LiteralField('Content', ''));
     $adder = new ElementalGridFieldAddNewMultiClass();
     $list = $this->getAvailableTypes();
     $adder->setClasses($list);
     $area = $this->owner->ElementArea();
     if (!$area->exists() || !$area->isInDB()) {
         $area->write();
         $this->owner->ElementAreaID = $area->ID;
         $this->owner->write();
     }
     $gridField = GridField::create('ElementArea', Config::inst()->get("ElementPageExtension", 'elements_title'), $this->owner->ElementArea()->Elements(), GridFieldConfig_RelationEditor::create()->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldDeleteAction')->removeComponentsByType('GridFieldAddExistingAutocompleter')->addComponent(new ElementalGridFieldAddExistingAutocompleter())->addComponent(new ElementalGridFieldDeleteAction())->addComponent($adder)->addComponent(new GridFieldSortableRows('Sort')));
     $config = $gridField->getConfig();
     $paginator = $config->getComponentByType('GridFieldPaginator');
     $paginator->setItemsPerPage(100);
     $config->removeComponentsByType('GridFieldDetailForm');
     $config->addComponent(new VersionedDataObjectDetailsForm());
     $fields->addFieldToTab('Root.Main', $gridField);
     return $fields;
 }
 /**
  * Setup the CMS Fields
  *
  * @return FieldList
  */
 public function updateCMSFields(FieldList $fields)
 {
     // redirector pages should not have elements
     if (is_a($this->owner, 'RedirectorPage')) {
         return;
     } else {
         if ($ignored = Config::inst()->get('ElementPageExtension', 'ignored_classes')) {
             foreach ($ignored as $check) {
                 if (is_a($this->owner, $check)) {
                     return;
                 }
             }
         }
     }
     // add an empty holder for content as some module explicitly use insert
     // after content.
     $fields->replaceField('Content', new LiteralField('Content', ''));
     $adder = new ElementalGridFieldAddNewMultiClass();
     if (is_array($this->owner->config()->get('allowed_elements'))) {
         $list = $this->owner->config()->get('allowed_elements');
     } else {
         $classes = ClassInfo::subclassesFor('BaseElement');
         $list = array();
         unset($classes['BaseElement']);
         foreach ($classes as $class) {
             $inst = singleton($class);
             if ($inst->canCreate()) {
                 $list[$class] = singleton($class)->i18n_singular_name();
             }
         }
     }
     if (method_exists($this->owner, 'sortElementalOptions')) {
         $this->owner->sortElementalOptions($list);
     } else {
         asort($list);
     }
     $adder->setClasses($list);
     $area = $this->owner->ElementArea();
     if (!$area->exists() || !$area->isInDB()) {
         $area->write();
         $this->owner->ElementAreaID = $area->ID;
         $this->owner->write();
     }
     $gridField = GridField::create('ElementArea', Config::inst()->get("ElementPageExtension", 'elements_title'), $this->owner->ElementArea()->Elements(), GridFieldConfig_RelationEditor::create()->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldAddExistingAutocompleter')->removeComponentsByType('GridFieldDeleteAction')->addComponent(new GridFieldDeleteAction(false))->addComponent($adder)->addComponent(new GridFieldSortableRows('Sort')));
     $config = $gridField->getConfig();
     $paginator = $config->getComponentByType('GridFieldPaginator');
     $paginator->setItemsPerPage(100);
     $config->removeComponentsByType('GridFieldDetailForm');
     $config->addComponent(new VersionedDataObjectDetailsForm());
     $fields->addFieldToTab('Root.Main', $gridField, 'Metadata');
     return $fields;
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $elements = $this->Elements();
     $isInDb = $this->isInDB();
     $this->beforeUpdateCMSFields(function ($fields) use($elements, $isInDb) {
         $fields->removeByName('Root.Elements');
         $fields->removeByName('Elements');
         $desc = HTMLEditorField::create('ListDescription', 'List Description');
         $desc->setRightTitle('Optional');
         $fields->addFieldToTab('Root.Main', $desc);
         if ($isInDb) {
             $adder = new ElementalGridFieldAddNewMultiClass();
             $list = $this->getAvailableTypes();
             if ($list) {
                 $adder->setClasses($list);
             }
             $config = GridFieldConfig_RecordEditor::create(100);
             $config->addComponent(new GridFieldSortableRows('Sort'));
             $config->removeComponentsByType('GridFieldAddNewButton');
             $config->removeComponentsByType('GridFieldSortableHeader');
             $config->removeComponentsByType('GridFieldDeleteAction');
             $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
             $config->addComponent(new GridFieldTitleHeader());
             $config->addComponent(new ElementalGridFieldDeleteAction());
             $config->addComponent($adder);
             $config->addComponent($autocompleter = new ElementalGridFieldAddExistingAutocompleter());
             if ($list) {
                 $autocompleter->setSearchList(BaseElement::get()->filter('ClassName', array_keys($list)));
             }
             $config->removeComponentsByType('GridFieldDetailForm');
             $config->addComponent(new VersionedDataObjectDetailsForm());
             $widgetArea = new GridField('Elements', Config::inst()->get("ElementPageExtension", 'elements_title'), $elements, $config);
             $fields->addFieldToTab('Root.Main', $widgetArea);
         } else {
             $fields->addFieldToTab('Root.Main', LiteralField::create('warn', '<p class="message notice">Once you save this object you will be able to add items</p>'));
         }
     });
     return parent::getCMSFields();
 }
 /**
  * Setup the CMS Fields
  *
  * @param FieldList
  */
 public function updateCMSFields(FieldList $fields)
 {
     if (!$this->supportsElemental()) {
         return;
     }
     // add an empty holder for content as some module explicitly use insert
     // after content.
     $fields->replaceField('Content', new LiteralField('Content', ''));
     $adder = new ElementalGridFieldAddNewMultiClass();
     $list = $this->getAvailableTypes();
     if ($list) {
         $adder->setClasses($list);
     }
     $area = $this->owner->ElementArea();
     if ($this->owner->exists() && (!$area->exists() || !$area->isInDB())) {
         $area->write();
         $this->owner->ElementAreaID = $area->ID;
         $this->owner->write();
     }
     $gridField = GridField::create('ElementArea', Config::inst()->get("ElementPageExtension", 'elements_title'), $area->AllElements(), GridFieldConfig_RelationEditor::create()->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldSortableHeader')->removeComponentsByType('GridFieldDeleteAction')->removeComponentsByType('GridFieldAddExistingAutocompleter')->addComponent($autocomplete = new ElementalGridFieldAddExistingAutocompleter())->addComponent(new ElementalGridFieldDeleteAction())->addComponent(new GridFieldTitleHeader())->addComponent($adder)->addComponent(new GridFieldSortableRows('Sort')));
     if ($list) {
         $autocomplete->setSearchList(BaseElement::get()->filter('ClassName', array_keys($list)));
     }
     $config = $gridField->getConfig();
     $paginator = $config->getComponentByType('GridFieldPaginator');
     $paginator->setItemsPerPage(100);
     if (!$this->owner->config()->disable_element_publish_button) {
         $config->removeComponentsByType('GridFieldDetailForm');
         $config->addComponent($obj = new VersionedDataObjectDetailsForm());
     }
     if ($this->owner instanceof SiteTree && $fields->findOrMakeTab('Root.Main')->fieldByName('Metadata')) {
         $fields->addFieldToTab('Root.Main', $gridField, 'Metadata');
     } else {
         $fields->addFieldToTab('Root.Main', $gridField);
     }
     return $fields;
 }