BaseFormElement: move attribute callbacks to...

...dedicated methods, this allows to override them
This commit is contained in:
Thomas Gelf 2018-06-15 14:57:07 +02:00
parent e7fc4d3009
commit 5e19d3bada

View File

@ -41,10 +41,18 @@ abstract class BaseFormElement extends BaseHtmlElement
/** /**
* Link constructor. * Link constructor.
* @param $name * @param $name
* @param $value
* @param \dipl\Html\Attributes|array|null $attributes * @param \dipl\Html\Attributes|array|null $attributes
*/ */
public function __construct($name, $attributes = null) public function __construct($name, $attributes = null)
{
$this->registerAttributeCallbacks();
if ($attributes !== null) {
$this->addAttributes($attributes);
}
$this->setName($name);
}
protected function registerAttributeCallbacks()
{ {
$this->getAttributes() $this->getAttributes()
->registerAttributeCallback('label', [$this, 'getNoAttribute'], [$this, 'setLabel']) ->registerAttributeCallback('label', [$this, 'getNoAttribute'], [$this, 'setLabel'])
@ -53,10 +61,6 @@ abstract class BaseFormElement extends BaseHtmlElement
->registerAttributeCallback('description', [$this, 'getNoAttribute'], [$this, 'setDescription']) ->registerAttributeCallback('description', [$this, 'getNoAttribute'], [$this, 'setDescription'])
->registerAttributeCallback('validators', null, [$this, 'setValidators']) ->registerAttributeCallback('validators', null, [$this, 'setValidators'])
->registerAttributeCallback('required', [$this, 'getRequiredAttribute'], [$this, 'setRequired']); ->registerAttributeCallback('required', [$this, 'getRequiredAttribute'], [$this, 'setRequired']);
if ($attributes !== null) {
$this->addAttributes($attributes);
}
$this->setName($name);
} }
/** /**