public function testValidation()
 {
     $field = CompositeField::create($fieldOne = DropdownField::create('A'), $fieldTwo = TextField::create('B'));
     $validator = new RequiredFields();
     $this->assertFalse($field->validate($validator), "Validation fails when child is invalid");
     $fieldOne->setEmptyString('empty');
     $this->assertTrue($field->validate($validator), "Validates when children are valid");
 }
Пример #2
0
 /**
  * @uses FormField::name_to_label()
  *
  * @param string $name Identifier of the tab, without characters like dots or spaces
  * @param string|FormField $titleOrField Natural language title of the tabset, or first tab.
  * If its left out, the class uses {@link FormField::name_to_label()} to produce a title
  * from the {@link $name} parameter.
  * @param FormField ...$fields All following parameters are inserted as children to this tab
  */
 public function __construct($name, $titleOrField = null, $fields = null)
 {
     if (!is_string($name)) {
         throw new InvalidArgumentException('Invalid string parameter for $name');
     }
     // Get following arguments
     $fields = func_get_args();
     array_shift($fields);
     // Detect title from second argument, if it is a string
     if ($titleOrField && is_string($titleOrField)) {
         $title = $titleOrField;
         array_shift($fields);
     } else {
         $title = static::name_to_label($name);
     }
     // Remaining arguments are child fields
     parent::__construct($fields);
     // Assign name and title (not assigned by parent constructor)
     $this->setName($name);
     $this->setTitle($title);
     $this->setID(Convert::raw2htmlid($name));
 }
Пример #3
0
 /**
  * Inserts a field after a particular field in a FieldList.
  *
  * @param string $insertAfter Name of the field to insert after
  * @param FormField $field The form field to insert
  * @return FormField|null
  */
 public function insertAfter($insertAfter, $field)
 {
     if ($field instanceof Tab || $field instanceof TabSet) {
         $field->setTabSet($this);
     }
     return parent::insertAfter($insertAfter, $field);
 }
 /**
  * Return a {@link Form} instance allowing a user to
  * add images and flash objects to the TinyMCE content editor.
  *
  * @return Form
  */
 public function MediaForm()
 {
     // TODO Handle through GridState within field - currently this state set too late to be useful here (during
     // request handling)
     $parentID = $this->getAttachParentID();
     $fileFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(7), new GridFieldDeleteAction(), new GridFieldDetailForm());
     $fileField = GridField::create('Files', false, null, $fileFieldConfig);
     $fileField->setList($this->getFiles($parentID));
     $fileField->setAttribute('data-selectable', true);
     $fileField->setAttribute('data-multiselect', true);
     /** @var GridFieldDataColumns $columns */
     $columns = $fileField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
     $columns->setDisplayFields(array('StripThumbnail' => false, 'Title' => _t('File.Title'), 'Created' => File::singleton()->fieldLabel('Created')));
     $columns->setFieldCasting(array('Created' => 'DBDatetime->Nice'));
     $fromCMS = new CompositeField($select = TreeDropdownField::create('ParentID', "", 'SilverStripe\\Assets\\Folder')->addExtraClass('noborder')->setValue($parentID), $fileField);
     $fromCMS->addExtraClass('content ss-uploadfield htmleditorfield-from-cms');
     $select->addExtraClass('content-select');
     $URLDescription = _t('HTMLEditorField.URLDESCRIPTION', 'Insert videos and images from the web into your page simply by entering the URL of the file. Make sure you have the rights or permissions before sharing media directly from the web.<br /><br />Please note that files are not added to the file store of the CMS but embeds the file from its original location, if for some reason the file is no longer available in its original location it will no longer be viewable on this page.');
     $fromWeb = new CompositeField($description = new LiteralField('URLDescription', '<div class="url-description">' . $URLDescription . '</div>'), $remoteURL = new TextField('RemoteURL', 'http://'), new LiteralField('addURLImage', '<button type="button" class="action ui-action-constructive ui-button field font-icon-plus add-url">' . _t('HTMLEditorField.BUTTONADDURL', 'Add url') . '</button>'));
     $remoteURL->addExtraClass('remoteurl');
     $fromWeb->addExtraClass('content ss-uploadfield htmleditorfield-from-web');
     Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/AssetUploadField.css', '/'));
     $computerUploadField = UploadField::create('AssetUploadField', '');
     $computerUploadField->setConfig('previewMaxWidth', 40);
     $computerUploadField->setConfig('previewMaxHeight', 30);
     $computerUploadField->addExtraClass('toolbar toolbar--content ss-assetuploadfield htmleditorfield-from-computer');
     $computerUploadField->removeExtraClass('ss-uploadfield');
     $computerUploadField->setTemplate('SilverStripe\\Forms\\HTMLEditorField_UploadField');
     $computerUploadField->setFolderName(Upload::config()->get('uploads_folder'));
     $defaultPanel = new CompositeField($computerUploadField, $fromCMS);
     $fromWebPanel = new CompositeField($fromWeb);
     $defaultPanel->addExtraClass('htmleditorfield-default-panel');
     $fromWebPanel->addExtraClass('htmleditorfield-web-panel');
     $allFields = new CompositeField($defaultPanel, $fromWebPanel, $editComposite = new CompositeField(new LiteralField('contentEdit', '<div class="content-edit ss-uploadfield-files files"></div>')));
     $allFields->addExtraClass('ss-insert-media');
     $headings = new CompositeField(new LiteralField('Heading', sprintf('<h3 class="htmleditorfield-mediaform-heading insert">%s</h3>', _t('HTMLEditorField.INSERTMEDIA', 'Insert media from')) . sprintf('<h3 class="htmleditorfield-mediaform-heading update">%s</h3>', _t('HTMLEditorField.UpdateMEDIA', 'Update media'))));
     $headings->addExtraClass('cms-content-header');
     $editComposite->addExtraClass('ss-assetuploadfield');
     $fields = new FieldList($headings, $allFields);
     $form = new Form($this->controller, "{$this->name}/MediaForm", $fields, new FieldList());
     $form->unsetValidator();
     $form->disableSecurityToken();
     $form->loadDataFrom($this);
     $form->addExtraClass('htmleditorfield-form htmleditorfield-mediaform cms-dialog-content');
     // Allow other people to extend the fields being added to the imageform
     $this->extend('updateMediaForm', $form);
     return $form;
 }
 /**
  * Returns the name (ID) for the element.
  * In some cases the FieldGroup doesn't have a title, but we still want
  * the ID / name to be set. This code, generates the ID from the nested children
  *
  * TODO this is temporary, and should be removed when FormTemplateHelper is updated to handle ID
  *  for CompositeFields with no name
  */
 public function getName()
 {
     if ($this->name) {
         return $this->name;
     }
     if (!$this->title) {
         return parent::getName();
     }
     return preg_replace("/[^a-zA-Z0-9]+/", "", $this->title);
 }
 /**
  * @inheritdoc
  *
  * @param string $name
  * @param string $title
  * @param array|FieldList $children
  */
 public function __construct($name, $title, $children)
 {
     parent::__construct($children);
     $this->setName($name);
     $this->setTitle($title);
 }
 public function FieldHolder($properties = array())
 {
     return parent::FieldHolder($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;
 }