/** * 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 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 internalCheck($email, $checkText, $expectSuccess) { $field = new EmailField("MyEmail"); $field->setValue($email); $val = new EmailFieldTest_Validator(); try { $field->validate($val); // If we expect failure and processing gets here without an exception, the test failed $this->assertTrue($expectSuccess, $checkText . " (/{$email}/ passed validation, but not expected to)"); } catch (Exception $e) { if ($e instanceof PHPUnit_Framework_AssertionFailedError) { throw $e; } else { if ($expectSuccess) { $this->assertTrue(false, $checkText . ": " . $e->GetMessage() . " (/{$email}/ did not pass validation, but was expected to)"); } } } }