mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
NEW: updateAttributes hook in FormField
This commit is contained in:
parent
730c4d3733
commit
5f31983ded
@ -438,6 +438,10 @@ class FormField extends RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows customization through an 'updateAttributes' hook on the base class.
|
||||
* Existing attributes are passed in as the first argument and can be manipulated,
|
||||
* but any attributes added through a subclass implementation won't be included.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes() {
|
||||
@ -456,7 +460,11 @@ class FormField extends RequestHandler {
|
||||
$attrs['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
return array_merge($attrs, $this->attributes);
|
||||
$attrs = array_merge($attrs, $this->attributes);
|
||||
|
||||
$this->extend('updateAttributes', $attrs);
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,10 @@
|
||||
*/
|
||||
class FormFieldTest extends SapphireTest {
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'FormField' => array('FormFieldTest_Extension')
|
||||
);
|
||||
|
||||
public function testDefaultClasses() {
|
||||
Config::nest();
|
||||
|
||||
@ -232,4 +236,21 @@ class FormFieldTest extends SapphireTest {
|
||||
}
|
||||
}
|
||||
|
||||
public function testUpdateAttributes() {
|
||||
$field = new FormField('MyField');
|
||||
$this->assertArrayHasKey('extended', $field->getAttributes());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class FormFieldTest_Extension extends Extension implements TestOnly {
|
||||
|
||||
public function updateAttributes(&$attrs) {
|
||||
$attrs['extended'] = true;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user