public function testMessagesInsideNestedCompositeFields() { $fieldGroup = new FieldGroup(new CompositeField($textField = new TextField('TestField', 'Test Field'), $emailField = new EmailField('TestEmailField', 'Test Email Field'))); $textField->setError('Test error message', 'warning'); $emailField->setError('Test error message', 'error'); $this->assertEquals('Test error message, Test error message.', $fieldGroup->Message()); $this->assertEquals('warning. error', $fieldGroup->MessageType()); }
public function getSchemaDataDefaults() { $schema = parent::getSchemaDataDefaults(); $schema['data']['popoverTitle'] = $this->getPopoverTitle(); $schema['data']['placement'] = $this->getPlacement(); return $schema; }
/** * Test that groups can be added to a fieldlist */ public function testFieldgroup() { $fields = new FieldList(); $tab = new Tab('Root'); $fields->push($tab); $fields->addFieldsToTab('Root', array($group1 = new FieldGroup(new TextField('Name'), new EmailField('Email')), $group2 = new FieldGroup(new TextField('Company'), new TextareaField('Address')))); /* Check that the field objects were created */ $this->assertNotNull($fields->dataFieldByName('Name')); $this->assertNotNull($fields->dataFieldByName('Email')); $this->assertNotNull($fields->dataFieldByName('Company')); $this->assertNotNull($fields->dataFieldByName('Address')); /* The field objects in the set should be the same as the ones we created */ $this->assertSame($fields->dataFieldByName('Name'), $group1->fieldByName('Name')); $this->assertSame($fields->dataFieldByName('Email'), $group1->fieldByName('Email')); $this->assertSame($fields->dataFieldByName('Company'), $group2->fieldByName('Company')); $this->assertSame($fields->dataFieldByName('Address'), $group2->fieldByName('Address')); /* We'll have 2 fields directly inside the tab */ $this->assertEquals(2, $tab->Fields()->Count()); }
protected function getFormFieldAttributesTab($record, $context = []) { /** @var Tab $tab */ $tab = parent::getFormFieldAttributesTab($record, $context); $alignments = array('leftAlone' => _t('AssetAdmin.AlignmentLeftAlone', 'On the left, on its own.'), 'center' => _t('AssetAdmin.AlignmentCenter', 'Centered, on its own.'), 'left' => _t('AssetAdmin.AlignmentLeft', 'On the left, with text wrapping around.'), 'right' => _t('AssetAdmin.AlignmentRight', 'On the right, with text wrapping around.')); $tab->push(DropdownField::create('Alignment', _t('AssetAdmin.Alignment', 'Alignment'), $alignments)); $tab->push(FieldGroup::create(_t('AssetAdmin.ImageSpecs', 'Dimensions'), TextField::create('InsertWidth', _t('AssetAdmin.ImageWidth', 'Width'))->setMaxLength(5)->addExtraClass('flexbox-area-grow'), TextField::create('InsertHeight', _t('AssetAdmin.ImageHeight', 'Height'))->setMaxLength(5)->addExtraClass('flexbox-area-grow'))->addExtraClass('fill-width')); $tab->insertBefore('Caption', TextField::create('AltText', _t('AssetAdmin.AltText', 'Alternative text (alt)'))->setDescription(_t('AssetAdmin.AltTextDescription', 'Shown to screen readers or if image can\'t be displayed'))); $tab->insertAfter('AltText', TextField::create('TitleTooltip', _t('AssetAdmin.TitleTooltip', 'Title text (tooltip)'))->setDescription(_t('AssetAdmin.TitleTooltipDescription', 'For additional information about the image'))->setValue($record->Title)); return $tab; }
/** * @param array $properties * @return string */ public function Field($properties = array()) { foreach ($this->getChildren() as $field) { /** @var FormField $field */ $field->setDisabled($this->isDisabled()); $field->setReadonly($this->IsReadonly()); $field->setForm($this->getForm()); } return parent::Field($properties); }
/** * @return FieldList */ public function getFields() { $fields = new FieldList(CompositeField::create(CompositeField::create(LiteralField::create("ImageFull", $this->getPreview()))->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'), CompositeField::create($this->getDetailFields())->setName("FilePreviewData")->addExtraClass('cms-file-info-data'))->setName("FilePreview")->addExtraClass('cms-file-info'), TextField::create('CaptionText', _t('HTMLEditorField.CAPTIONTEXT', 'Caption text')), DropdownField::create('CSSClass', _t('HTMLEditorField.CSSCLASS', 'Alignment / style'), array('leftAlone' => _t('HTMLEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'), 'center' => _t('HTMLEditorField.CSSCLASSCENTER', 'Centered, on its own.'), 'left' => _t('HTMLEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'), 'right' => _t('HTMLEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'))), FieldGroup::create(_t('HTMLEditorField.IMAGEDIMENSIONS', 'Dimensions'), TextField::create('Width', _t('HTMLEditorField.IMAGEWIDTHPX', 'Width'), $this->getInsertWidth())->setMaxLength(5), TextField::create('Height', " x " . _t('HTMLEditorField.IMAGEHEIGHTPX', 'Height'), $this->getInsertHeight())->setMaxLength(5))->addExtraClass('dimensions last'), HiddenField::create('URL', false, $this->getURL()), HiddenField::create('FileID', false, $this->getFileID())); return $fields; }
/** * Get the search context from {@link File}, used to create the search form * as well as power the /search API endpoint. * * @return SearchContext */ public function getSearchContext() { $context = File::singleton()->getDefaultSearchContext(); // Customize fields $dateHeader = HeaderField::create('Date', _t('CMSSearch.FILTERDATEHEADING', 'Date'), 4); $dateFrom = DateField::create('CreatedFrom', _t('CMSSearch.FILTERDATEFROM', 'From'))->setConfig('showcalendar', true); $dateTo = DateField::create('CreatedTo', _t('CMSSearch.FILTERDATETO', 'To'))->setConfig('showcalendar', true); $dateGroup = FieldGroup::create($dateHeader, $dateFrom, $dateTo); $context->addField($dateGroup); /** @skipUpgrade */ $appCategories = array('archive' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryArchive', 'Archive'), 'audio' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryAudio', 'Audio'), 'document' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryDocument', 'Document'), 'flash' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryFlash', 'Flash', 'The fileformat'), 'image' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryImage', 'Image'), 'video' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryVideo', 'Video')); $context->addField($typeDropdown = new DropdownField('AppCategory', _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Filetype', 'File type'), $appCategories)); $typeDropdown->setEmptyString(' '); $currentfolderLabel = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CurrentFolderOnly', 'Limit to current folder?'); $context->addField(new CheckboxField('CurrentFolderOnly', $currentfolderLabel)); $context->getFields()->removeByName('Title'); return $context; }
public function getHTMLFragments($gridField) { $list = $gridField->getList(); if (!$this->checkDataType($list)) { return null; } /** @var Filterable $list */ $forTemplate = new ArrayData(array()); $forTemplate->Fields = new ArrayList(); $columns = $gridField->getColumns(); $filterArguments = $gridField->State->GridFieldFilterHeader->Columns->toArray(); $currentColumn = 0; foreach ($columns as $columnField) { $currentColumn++; $metadata = $gridField->getColumnMetadata($columnField); $title = $metadata['title']; $fields = new FieldGroup(); if ($title && $list->canFilterBy($columnField)) { $value = ''; if (isset($filterArguments[$columnField])) { $value = $filterArguments[$columnField]; } $field = new TextField('filter[' . $gridField->getName() . '][' . $columnField . ']', '', $value); $field->addExtraClass('grid-field__sort-field'); $field->addExtraClass('no-change-track'); $field->setAttribute('placeholder', _t('GridField.FilterBy', "Filter by ") . _t('GridField.' . $metadata['title'], $metadata['title'])); $fields->push($field); $fields->push(GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('btn font-icon-cancel btn--no-text ss-gridfield-button-reset')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)); } if ($currentColumn == count($columns)) { $fields->push(GridField_FormAction::create($gridField, 'filter', false, 'filter', null)->addExtraClass('btn font-icon-search btn--no-text btn--icon-large grid-field__filter-submit ss-gridfield-button-filter')->setAttribute('title', _t('GridField.Filter', "Filter"))->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField)); $fields->push(GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('btn font-icon-cancel btn--no-text grid-field__filter-clear ss-gridfield-button-close')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)); $fields->addExtraClass('filter-buttons'); $fields->addExtraClass('no-change-track'); } $forTemplate->Fields->push($fields); } $templates = SSViewer::get_templates_by_class($this, '_Row', __CLASS__); return array('header' => $forTemplate->renderWith($templates)); }