[icinga-checkins] icinga.org: icingaweb2/feature/redesign-7144: Form: Add our element and decorator paths instead of calling createIcingaFormElement

git at icinga.org git at icinga.org
Tue Nov 18 16:36:39 CET 2014


Module: icingaweb2
Branch: feature/redesign-7144
Commit: f9d70624765c8d5d5d00621e56dcbd6d87797b1d
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=f9d70624765c8d5d5d00621e56dcbd6d87797b1d

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Tue Nov 18 12:51:06 2014 +0100

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

createIcingaFormElement lacks all stuff applied in Zend_Form::createElement().

---

 library/Icinga/Web/Form.php |   39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php
index 20484c3..854a6fa 100644
--- a/library/Icinga/Web/Form.php
+++ b/library/Icinga/Web/Form.php
@@ -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);
-        }
+        $el = parent::createElement($type, $name, $options);
 
         if ($el && $el->getAttrib('autosubmit')) {
             $noScript = new NoScriptApply(); // Non-JS environments
@@ -739,25 +751,6 @@ class Form extends Zend_Form
     }
 
     /**
-     * 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
      *
      * @param   Zend_View_Interface     $view   The view context to use



More information about the icinga-checkins mailing list