Form: Add our element and decorator paths instead of calling createIcingaFormElement

createIcingaFormElement lacks all stuff applied in Zend_Form::createElement().
This commit is contained in:
Eric Lippmann 2014-11-18 12:51:06 +01:00
parent 26c0fe7637
commit f9d7062476
1 changed files with 16 additions and 23 deletions

View File

@ -11,7 +11,6 @@ use Zend_View_Interface;
use Icinga\Application\Icinga;
use Icinga\Web\Form\Decorator\NoScriptApply;
use Icinga\Web\Form\Element\CsrfCounterMeasure;
use Icinga\Web\Form\FormElement;
/**
* Base class for forms providing CSRF protection, confirmation logic and auto submission
@ -139,6 +138,21 @@ class Form extends Zend_Form
throw new LogicException('The option `onSuccess\' is not callable');
}
// Zend's plugin loader reverses the order of added prefix paths thus trying our paths first before trying
// Zend paths
$this->addPrefixPaths(array(
array(
'prefix' => 'Icinga\\Web\\Form\\Element\\',
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Element'),
'type' => static::ELEMENT
),
array(
'prefix' => 'Icinga\\Web\\Form\\Decorator\\',
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Decorator'),
'type' => static::DECORATOR
)
));
parent::__construct($options);
}
@ -464,9 +478,7 @@ class Form extends Zend_Form
$options = array('decorators' => static::$defaultElementDecorators);
}
if (($el = $this->createIcingaFormElement($type, $name, $options)) === null) {
$el = parent::createElement($type, $name, $options);
}
if ($el && $el->getAttrib('autosubmit')) {
$noScript = new NoScriptApply(); // Non-JS environments
@ -738,25 +750,6 @@ class Form extends Zend_Form
return array();
}
/**
* Create a new element located in the Icinga Web 2 library
*
* @param string $type The type of the element
* @param string $name The name of the element
* @param mixed $options The options for the element
*
* @return NULL|FormElement NULL in case the element is not found in the Icinga Web 2 library
*
* @see Form::$defaultElementDecorators For Icinga Web 2's default element decorators.
*/
protected function createIcingaFormElement($type, $name, $options = null)
{
$className = 'Icinga\\Web\\Form\\Element\\' . ucfirst($type);
if (class_exists($className)) {
return new $className($name, $options);
}
}
/**
* Render this form
*