/**
  * Return a {@link Form} instance allowing a user to
  * add links in the TinyMCE content editor.
  *
  * @return Form
  */
 public function LinkForm()
 {
     $siteTree = TreeDropdownField::create('internal', _t('HTMLEditorField.PAGE', "Page"), 'SilverStripe\\CMS\\Model\\SiteTree', 'ID', 'MenuTitle', true);
     // mimic the SiteTree::getMenuTitle(), which is bypassed when the search is performed
     $siteTree->setSearchFunction(array($this, 'siteTreeSearchCallback'));
     $numericLabelTmpl = '<span class="step-label"><span class="flyout">Step %d.</span>' . '<span class="title">%s</span></span>';
     $form = new Form($this->controller, "{$this->name}/LinkForm", new FieldList($headerWrap = new CompositeField(new LiteralField('Heading', sprintf('<h3 class="htmleditorfield-mediaform-heading insert">%s</h3>', _t('HTMLEditorField.LINK', 'Insert Link')))), $contentComposite = new CompositeField(OptionsetField::create('LinkType', DBField::create_field('HTMLFragment', sprintf($numericLabelTmpl, '1', _t('HTMLEditorField.LINKTO', 'Link type'))), array('internal' => _t('HTMLEditorField.LINKINTERNAL', 'Link to a page on this site'), 'external' => _t('HTMLEditorField.LINKEXTERNAL', 'Link to another website'), 'anchor' => _t('HTMLEditorField.LINKANCHOR', 'Link to an anchor on this page'), 'email' => _t('HTMLEditorField.LINKEMAIL', 'Link to an email address'), 'file' => _t('HTMLEditorField.LINKFILE', 'Link to download a file')), 'internal'), LiteralField::create('Step2', '<div class="step2">' . sprintf($numericLabelTmpl, '2', _t('HTMLEditorField.LINKDETAILS', 'Link details')) . '</div>'), $siteTree, TextField::create('external', _t('HTMLEditorField.URL', 'URL'), 'http://'), EmailField::create('email', _t('HTMLEditorField.EMAIL', 'Email address')), $fileField = UploadField::create('file', _t('HTMLEditorField.FILE', 'SilverStripe\\Assets\\File')), TextField::create('Anchor', _t('HTMLEditorField.ANCHORVALUE', 'Anchor')), TextField::create('Subject', _t('HTMLEditorField.SUBJECT', 'Email subject')), TextField::create('Description', _t('HTMLEditorField.LINKDESCR', 'Link description')), CheckboxField::create('TargetBlank', _t('HTMLEditorField.LINKOPENNEWWIN', 'Open link in a new window?')), HiddenField::create('Locale', null, $this->controller->Locale))), new FieldList());
     $headerWrap->setName('HeaderWrap');
     $headerWrap->addExtraClass('CompositeField composite cms-content-header form-group--no-label ');
     $contentComposite->setName('ContentBody');
     $contentComposite->addExtraClass('ss-insert-link content');
     $fileField->setAllowedMaxFileNumber(1);
     $form->unsetValidator();
     $form->loadDataFrom($this);
     $form->addExtraClass('htmleditorfield-form htmleditorfield-linkform cms-mediaform-content');
     $this->extend('updateLinkForm', $form);
     return $form;
 }
 public function testValidation()
 {
     $field = OptionsetField::create('Test', 'Testing', array("One" => "One", "Two" => "Two", "Five" => "Five"));
     $validator = new RequiredFields('Test');
     /** @skipUpgrade */
     $form = new Form($this, 'Form', new FieldList($field), new FieldList(), $validator);
     $field->setValue("One");
     $this->assertTrue($field->validate($validator));
     //non-existent value should make the field invalid
     $field->setValue("Three");
     $this->assertFalse($field->validate($validator));
     //empty string should pass field-level validation...
     $field->setValue('');
     $this->assertTrue($field->validate($validator));
     // ... but should not pass "RequiredFields" validation
     $this->assertFalse($form->validate());
     //disabled items shouldn't validate
     $field->setDisabledItems(array('Five'));
     $field->setValue('Five');
     $this->assertFalse($field->validate($validator));
 }