NEW: updateAttributes hook in FormField

This commit is contained in:
Ingo Schommer 2015-02-08 19:14:31 +13:00 committed by Will Rossiter
parent 730c4d3733
commit 5f31983ded
2 changed files with 30 additions and 1 deletions

View File

@ -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;
}
/**

View File

@ -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;
}
}