Skip to content

Commit

Permalink
Form: Add our element and decorator paths instead of calling createIc…
Browse files Browse the repository at this point in the history
…ingaFormElement

createIcingaFormElement lacks all stuff applied in Zend_Form::createElement().
  • Loading branch information
lippserd committed Nov 18, 2014
1 parent 26c0fe7 commit f9d7062
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions library/Icinga/Web/Form.php
Expand Up @@ -11,7 +11,6 @@
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
Expand Down Expand Up @@ -139,6 +138,21 @@ public function __construct($options = null)
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);
}

Expand Down Expand Up @@ -464,9 +478,7 @@ public function createElement($type, $name, $options = null)
$options = array('decorators' => static::$defaultElementDecorators);
}

if (($el = $this->createIcingaFormElement($type, $name, $options)) === null) {
$el = parent::createElement($type, $name, $options);
}
$el = parent::createElement($type, $name, $options);

if ($el && $el->getAttrib('autosubmit')) {
$noScript = new NoScriptApply(); // Non-JS environments
Expand Down Expand Up @@ -738,25 +750,6 @@ protected function getRequestData()
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
*
Expand Down

0 comments on commit f9d7062

Please sign in to comment.