mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FEATURE: added extend() call to enable FieldHolder() html to be customized via extensions.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88104 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
aa127e52c9
commit
620aa651aa
@ -405,6 +405,23 @@ class FormField extends RequestHandler {
|
|||||||
// $MessageType is also used in {@link extraClass()} with a "holder-" prefix
|
// $MessageType is also used in {@link extraClass()} with a "holder-" prefix
|
||||||
$messageBlock = (!empty($Message)) ? "<span class=\"message $MessageType\">$Message</span>" : "";
|
$messageBlock = (!empty($Message)) ? "<span class=\"message $MessageType\">$Message</span>" : "";
|
||||||
|
|
||||||
|
$values = array(
|
||||||
|
'Title' => $Title,
|
||||||
|
'Message' => $Message,
|
||||||
|
'MessageType' => $MessageType,
|
||||||
|
'RightTitle' => $RightTitle,
|
||||||
|
'Type' => $Type,
|
||||||
|
'extraClass' => $extraClass,
|
||||||
|
'Name' => $Name,
|
||||||
|
'Field' => $Field
|
||||||
|
);
|
||||||
|
|
||||||
|
// allow form field html to be decorated.
|
||||||
|
$subTemplates = $this->extend('updateFieldHolder', $values);
|
||||||
|
if($subTemplates && is_array($subTemplates)) {
|
||||||
|
return array_pop($subTemplates);
|
||||||
|
}
|
||||||
|
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<div id="$Name" class="field $Type $extraClass">$titleBlock<div class="middleColumn">$Field</div>$rightTitleBlock$messageBlock</div>
|
<div id="$Name" class="field $Type $extraClass">$titleBlock<div class="middleColumn">$Field</div>$rightTitleBlock$messageBlock</div>
|
||||||
HTML;
|
HTML;
|
||||||
|
@ -85,5 +85,30 @@ class FormFieldTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to ensure that subclassing the form field FieldHolder updates the html
|
||||||
|
* the field produces
|
||||||
|
*/
|
||||||
|
function testCustomFieldOverridesTemplate() {
|
||||||
|
$orignal = new TextField('Name');
|
||||||
|
$orignalHTML = $orignal->FieldHolder();
|
||||||
|
|
||||||
|
Object::add_extension('FormField', 'FormFieldTest_CustomFormSubclass');
|
||||||
|
$textField = new TextField('Name');
|
||||||
|
$newHTML = $textField->FieldHolder();
|
||||||
|
|
||||||
|
$this->assertNotSame($orignalHTML, $newHTML);
|
||||||
|
$this->assertSame($newHTML, '<li id="Name"></li>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormFieldTest_CustomFormSubclass extends Extension implements TestOnly {
|
||||||
|
|
||||||
|
function updateFieldHolder(array $array) {
|
||||||
|
extract($array);
|
||||||
|
return <<<HTML
|
||||||
|
<li id="$Name"></li>
|
||||||
|
HTML;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user