コード例 #1
0
 /**
  * Replace the existing ContentType field with a drop-down list of templates
  * derived from extend.provideAvailableTemplates.
  *
  * @param FieldList $fields
  */
 public function updateCMSFields(FieldList $fields)
 {
     $fields->removeByName(self::FieldName);
     $contentTypes = [];
     $this()->extend('provideContentTypes', $contentTypes);
     $fields->addFieldToTab(parent::get_config_setting('tab_name'), $this->makeDropdownField($contentTypes, $this()->{self::FieldName}), parent::get_config_setting('insert_field_before'));
 }
コード例 #2
0
 /**
  * This should be updateCMSFields and configured to be called last but configuration
  * priority does not seem to work to force this to be the last loaded/called extension.
  *
  * For now will call via extend.manualUpdate with the field list in ArtisanModel.getCMSFields
  *
  * @param FieldList $fields
  */
 public function manualUpdateCMSFields(FieldList $fields)
 {
     //        $formFields = $fields->dataFields();
     $formFields = $fields->VisibleFields();
     $selectorFieldName = parent::get_config_setting('selector_field_name');
     $hiddenCSSClass = parent::get_config_setting('hidden_css_class');
     $provider = Injector::inst()->get('AdaptableFormMetaDataProvider');
     $defaultFieldNames = $provider->getDefaultFieldNames();
     // keep track of fields we have encountered in the spec, other fields will be hidden,
     // we can initialise this to defaultFieldNames as we don't want to hide these ever
     $handled = array_combine($defaultFieldNames, $defaultFieldNames);
     // we want to get the form so we can remove fields later
     $form = null;
     $metaData = $provider->getMetaData();
     // the master list of content types by field name
     $this->contentTypes = [];
     foreach ($metaData as $contentType => $fieldSpec) {
         if (isset($fieldSpec['FormFields'])) {
             $fieldDefinitions = $fieldSpec['FormFields'];
             $specFields = array_merge($fieldDefinitions, $defaultFieldNames);
             $this->processFieldList($formFields, $contentType, $selectorFieldName, $specFields, $defaultFieldNames, $handled);
         }
     }
     $this->hideUnhandled($formFields, $handled, $hiddenCSSClass);
 }
コード例 #3
0
 public function onBeforeWrite()
 {
     $maxExistingSort = DataObject::get($this()->class)->max(self::FieldName);
     if (!$this()->{self::FieldName}) {
         $this()->{self::FieldName} = $maxExistingSort + 1;
     }
     parent::onBeforeWrite();
 }
コード例 #4
0
 public function updateCMSFields(FieldList $fields)
 {
     // remove if already scaffolded so we can add as editable grid field
     $fields->removeByName(self::RelationshipName);
     if ($this->showOnCMSForm()) {
         $gridField = $this->makeEditableGridField(self::FieldName, $this->getFieldLabel(), self::RelatedModelClass, $this->ArtisanHasBlocks());
         $fields->addFieldToTab(parent::get_config_setting('tab_name'), $gridField);
     }
 }
コード例 #5
0
 /**
  * Return a listbox with the record column value.
  *
  * @return array
  */
 public function provideEditableGridFields(array &$fields)
 {
     if (parent::get_config_setting('add_to_grid')) {
         $fields = array_merge($fields, [self::FieldName => ['title' => $this->getFieldLabel(), 'callback' => function ($record, $column, GridField $grid) {
             $config = $grid->getConfig();
             $config->getComponentByType('GridField');
             return $this->makeListboxField($record->{$column});
         }]]);
     }
 }
コード例 #6
0
 public function provideEditableGridFields(array &$fields)
 {
     // if config is true or an array with fields
     if ($config = parent::get_config_setting('add_to_grid')) {
         $summaryFields = $this->config()->get('summary_fields');
         // if config is true then use config.summary_fields
         if (is_bool($config)) {
             $config = $summaryFields;
         }
         // set fields to intersection of config.add_to_grid and config.summary_fields
         $fields = array_merge($fields, array_intersect_key($config, ['Title' => ['title' => $this->getFieldLabel('TitleLabel'), 'field' => 'TextField'], 'SubTitle' => ['title' => $this->getFieldLabel('SubTitleLabel'), 'field' => 'TextField']]));
     }
 }
コード例 #7
0
 /**
  * Add a tab with an upload field to the owner.config.images_tab_name or self.config.tab_name tab.
  *
  * @param FieldList $fields
  */
 public function updateCMSFields(FieldList $fields)
 {
     $fields->removeByName(self::FieldName);
     if ($this->showOnCMSForm()) {
         // tab name can be set on the owner config.images_tab_name or use the extensions config.tab_name
         $tabName = $this()->config()->get('images_tab_name') ?: parent::get_config_setting('tab_name');
         $fields->addFieldToTab($tabName, $field = new DisplayLogicWrapper(new SelectUploadField(self::FieldName, $this->getFieldLabel(), $this()->{self::FieldName}())));
         if ($label = $this()->getTranslationForContentType('ImagesLabel')) {
             $field->setTitle($label);
         }
         if ($note = $this()->getTranslationForContentType('ImagesNote')) {
             $field->setRightTitle($note);
         }
     }
 }
コード例 #8
0
 /**
  * Provide extra classes which can be set on the inner block (not container) level. May be
  * disabled using config.add_to_form in concrete class.
  *
  * @param array $classes - map of css-class => display-title suitable for us in a listbox/dropdown
  * @return void
  */
 protected function provideCSSClasses(array &$classes = [])
 {
     $classes = array_merge(parent::get_config_setting(static::FieldName), $classes);
 }