/** * @test */ public function testGettersAndSetters() { $field = new SegmentField('Example'); $modifier = SegmentFieldTestModifier::create(); $field->setModifiers(array($modifier)); $form = $this->getNewFormMock(); $request = $this->getNewRequestMock(); $field->setForm($form)->suggest($request); $modifiers = $field->getModifiers(); $this->assertSame($modifier, $modifiers[0]); $this->assertSame($form, $modifiers[0]->getForm()); $this->assertSame($field, $modifiers[0]->getField()); $this->assertSame($request, $modifiers[0]->getRequest()); }
/** * @return FieldList */ public function getCMSFields() { $fields = new FieldList(new TabSet('Root')); // Main tab $fields->addFieldsToTab('Root.Main', array(ReadonlyField::create('Type', _t('EditableFormField.TYPE', 'Type'), $this->i18n_singular_name()), LiteralField::create('MergeField', _t('EditableFormField.MERGEFIELDNAME', '<div class="field readonly">' . '<label class="left">Merge field</label>' . '<div class="middleColumn">' . '<span class="readonly">$' . $this->Name . '</span>' . '</div>' . '</div>')), TextField::create('Title'), TextField::create('Default', _t('EditableFormField.DEFAULT', 'Default value')), TextField::create('RightTitle', _t('EditableFormField.RIGHTTITLE', 'Right title')), SegmentField::create('Name')->setModifiers(array(UnderscoreSegmentFieldModifier::create()->setDefault('FieldName'), DisambiguationSegmentFieldModifier::create()))->setPreview($this->Name))); // Custom settings if (!empty(self::$allowed_css)) { $cssList = array(); foreach (self::$allowed_css as $k => $v) { if (!is_array($v)) { $cssList[$k] = $v; } elseif ($k === $this->ClassName) { $cssList = array_merge($cssList, $v); } } $fields->addFieldToTab('Root.Main', DropdownField::create('ExtraClass', _t('EditableFormField.EXTRACLASS_TITLE', 'Extra Styling/Layout'), $cssList)->setDescription(_t('EditableFormField.EXTRACLASS_SELECT', 'Select from the list of allowed styles'))); } else { $fields->addFieldToTab('Root.Main', TextField::create('ExtraClass', _t('EditableFormField.EXTRACLASS_Title', 'Extra CSS classes'))->setDescription(_t('EditableFormField.EXTRACLASS_MULTIPLE', 'Separate each CSS class with a single space'))); } // Validation $validationFields = $this->getFieldValidationOptions(); if ($validationFields) { $fields->addFieldsToTab('Root.Validation', $this->getFieldValidationOptions()); } $allowedClasses = array_keys($this->getEditableFieldClasses(false)); $self = $this; $editableColumns = new GridFieldEditableColumns(); $editableColumns->setDisplayFields(array('Display' => '', 'ConditionFieldID' => function ($record, $column, $grid) use($allowedClasses, $self) { return DropdownField::create($column, '', EditableFormField::get()->filter(array('ParentID' => $self->ParentID, 'ClassName' => $allowedClasses))->exclude(array('ID' => $self->ID))->map('ID', 'Title')); }, 'ConditionOption' => function ($record, $column, $grid) { $options = Config::inst()->get('EditableCustomRule', 'condition_options'); return DropdownField::create($column, '', $options); }, 'FieldValue' => function ($record, $column, $grid) { return TextField::create($column); }, 'ParentID' => function ($record, $column, $grid) use($self) { return HiddenField::create($column, '', $self->ID); })); // Custom rules $customRulesConfig = GridFieldConfig::create()->addComponents($editableColumns, new GridFieldButtonRow(), new GridFieldToolbarHeader(), new GridFieldAddNewInlineButton(), new GridFieldDeleteAction()); $fields->addFieldsToTab('Root.DisplayRules', array(CheckboxField::create('ShowOnLoad')->setDescription(_t('EditableFormField.SHOWONLOAD', 'Initial visibility before processing these rules')), GridField::create('DisplayRules', _t('EditableFormField.CUSTOMRULES', 'Custom Rules'), $this->DisplayRules(), $customRulesConfig))); $this->extend('updateCMSFields', $fields); return $fields; }