diff --git a/application/forms/Authentication/LoginForm.php b/application/forms/Authentication/LoginForm.php index bdf8956a3..0d9b8dedc 100644 --- a/application/forms/Authentication/LoginForm.php +++ b/application/forms/Authentication/LoginForm.php @@ -26,34 +26,34 @@ class LoginForm extends Form */ public function createElements($formData) { - return array( - $this->createElement( - 'text', - 'username', - array( - 'required' => true, - 'label' => t('Username'), - 'placeholder' => t('Please enter your username...'), - 'class' => false === isset($formData['username']) ? 'autofocus' : '' - ) - ), - $this->createElement( - 'password', - 'password', - array( - 'required' => true, - 'label' => t('Password'), - 'placeholder' => t('...and your password'), - 'class' => isset($formData['username']) ? 'autofocus' : '' - ) - ), - $this->createElement( - 'hidden', - 'redirect', - array( - 'value' => Url::fromRequest()->getParam('redirect') - ) + $this->addElement( + 'text', + 'username', + array( + 'required' => true, + 'label' => t('Username'), + 'placeholder' => t('Please enter your username...'), + 'class' => false === isset($formData['username']) ? 'autofocus' : '' ) ); + $this->addElement( + 'password', + 'password', + array( + 'required' => true, + 'label' => t('Password'), + 'placeholder' => t('...and your password'), + 'class' => isset($formData['username']) ? 'autofocus' : '' + ) + ); + $this->addElement( + 'hidden', + 'redirect', + array( + 'value' => Url::fromRequest()->getParam('redirect') + ) + ); + + return $this; } } diff --git a/application/forms/Config/Authentication/AutologinBackendForm.php b/application/forms/Config/Authentication/AutologinBackendForm.php index cb4d100a0..4f4df73e3 100644 --- a/application/forms/Config/Authentication/AutologinBackendForm.php +++ b/application/forms/Config/Authentication/AutologinBackendForm.php @@ -25,52 +25,52 @@ class AutologinBackendForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'name', - array( - 'required' => true, - 'label' => t('Backend Name'), - 'description' => t('The name of this authentication backend'), - 'validators' => array( + $this->addElement( + 'text', + 'name', + array( + 'required' => true, + 'label' => t('Backend Name'), + 'description' => t('The name of this authentication backend'), + 'validators' => array( + array( + 'Regex', + false, array( - 'Regex', - false, - array( - 'pattern' => '/^[^\\[\\]:]+$/', - 'messages' => array( - 'regexNotMatch' => 'The backend name cannot contain \'[\', \']\' or \':\'.' - ) + 'pattern' => '/^[^\\[\\]:]+$/', + 'messages' => array( + 'regexNotMatch' => 'The backend name cannot contain \'[\', \']\' or \':\'.' ) ) ) ) - ), - $this->createElement( - 'text', - 'strip_username_regexp', - array( - 'required' => true, - 'label' => t('Backend Domain Pattern'), - 'description' => t('The domain pattern of this authentication backend'), - 'value' => '/\@[^$]+$/', - 'validators' => array( - new Zend_Validate_Callback(function ($value) { - return @preg_match($value, '') !== false; - }) - ) - ) - ), - $this->createElement( - 'hidden', - 'backend', - array( - 'required' => true, - 'value' => 'autologin' + ) + ); + $this->addElement( + 'text', + 'strip_username_regexp', + array( + 'required' => true, + 'label' => t('Backend Domain Pattern'), + 'description' => t('The domain pattern of this authentication backend'), + 'value' => '/\@[^$]+$/', + 'validators' => array( + new Zend_Validate_Callback(function ($value) { + return @preg_match($value, '') !== false; + }) ) ) ); + $this->addElement( + 'hidden', + 'backend', + array( + 'required' => true, + 'value' => 'autologin' + ) + ); + + return $this; } /** diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php index 603aaeb79..23335f8fa 100644 --- a/application/forms/Config/Authentication/DbBackendForm.php +++ b/application/forms/Config/Authentication/DbBackendForm.php @@ -48,37 +48,37 @@ class DbBackendForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'name', - array( - 'required' => true, - 'label' => t('Backend Name'), - 'description' => t('The name of this authentication provider'), - ) - ), - $this->createElement( - 'select', - 'resource', - array( - 'required' => true, - 'label' => t('Database Connection'), - 'description' => t('The database connection to use for authenticating with this provider'), - 'multiOptions' => false === empty($this->resources) - ? array_combine($this->resources, $this->resources) - : array() - ) - ), - $this->createElement( - 'hidden', - 'backend', - array( - 'required' => true, - 'value' => 'db' - ) + $this->addElement( + 'text', + 'name', + array( + 'required' => true, + 'label' => t('Backend Name'), + 'description' => t('The name of this authentication provider'), ) ); + $this->addElement( + 'select', + 'resource', + array( + 'required' => true, + 'label' => t('Database Connection'), + 'description' => t('The database connection to use for authenticating with this provider'), + 'multiOptions' => false === empty($this->resources) + ? array_combine($this->resources, $this->resources) + : array() + ) + ); + $this->addElement( + 'hidden', + 'backend', + array( + 'required' => true, + 'value' => 'db' + ) + ); + + return $this; } /** diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php index 79949e2de..9db773708 100644 --- a/application/forms/Config/Authentication/LdapBackendForm.php +++ b/application/forms/Config/Authentication/LdapBackendForm.php @@ -47,57 +47,57 @@ class LdapBackendForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'name', - array( - 'required' => true, - 'label' => t('Backend Name'), - 'description' => t('The name of this authentication backend') - ) - ), - $this->createElement( - 'select', - 'resource', - array( - 'required' => true, - 'label' => t('LDAP Resource'), - 'description' => t('The resource to use for authenticating with this provider'), - 'multiOptions' => false === empty($this->resources) - ? array_combine($this->resources, $this->resources) - : array() - ) - ), - $this->createElement( - 'text', - 'user_class', - array( - 'required' => true, - 'label' => t('LDAP User Object Class'), - 'description' => t('The object class used for storing users on the ldap server'), - 'value' => 'inetOrgPerson' - ) - ), - $this->createElement( - 'text', - 'user_name_attribute', - array( - 'required' => true, - 'label' => t('LDAP User Name Attribute'), - 'description' => t('The attribute name used for storing the user name on the ldap server'), - 'value' => 'uid' - ) - ), - $this->createElement( - 'hidden', - 'backend', - array( - 'required' => true, - 'value' => 'ldap' - ) + $this->addElement( + 'text', + 'name', + array( + 'required' => true, + 'label' => t('Backend Name'), + 'description' => t('The name of this authentication backend') ) ); + $this->addElement( + 'select', + 'resource', + array( + 'required' => true, + 'label' => t('LDAP Resource'), + 'description' => t('The resource to use for authenticating with this provider'), + 'multiOptions' => false === empty($this->resources) + ? array_combine($this->resources, $this->resources) + : array() + ) + ); + $this->addElement( + 'text', + 'user_class', + array( + 'required' => true, + 'label' => t('LDAP User Object Class'), + 'description' => t('The object class used for storing users on the ldap server'), + 'value' => 'inetOrgPerson' + ) + ); + $this->addElement( + 'text', + 'user_name_attribute', + array( + 'required' => true, + 'label' => t('LDAP User Name Attribute'), + 'description' => t('The attribute name used for storing the user name on the ldap server'), + 'value' => 'uid' + ) + ); + $this->addElement( + 'hidden', + 'backend', + array( + 'required' => true, + 'value' => 'ldap' + ) + ); + + return $this; } /** diff --git a/application/forms/Config/AuthenticationBackendConfigForm.php b/application/forms/Config/AuthenticationBackendConfigForm.php index f91044446..9068ed25a 100644 --- a/application/forms/Config/AuthenticationBackendConfigForm.php +++ b/application/forms/Config/AuthenticationBackendConfigForm.php @@ -299,8 +299,7 @@ class AuthenticationBackendConfigForm extends ConfigForm $backendTypes['autologin'] = t('Autologin'); } - $elements = array(); - $elements[] = $this->createElement( + $this->addElement( 'select', 'type', array( @@ -315,9 +314,11 @@ class AuthenticationBackendConfigForm extends ConfigForm if (isset($formData['force_creation']) && $formData['force_creation']) { // In case another error occured and the checkbox was displayed before - $elements[] = $this->getForceCreationCheckbox(); + $this->addElement($this->getForceCreationCheckbox()); } - return array_merge($elements, $this->getBackendForm($backendType)->createElements($formData)); + $this->addElements($this->getBackendForm($backendType)->createElements($formData)->getElements()); + + return $this; } } diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php index 7f3b746e4..fda695886 100644 --- a/application/forms/Config/General/ApplicationConfigForm.php +++ b/application/forms/Config/General/ApplicationConfigForm.php @@ -27,14 +27,12 @@ class ApplicationConfigForm extends Form */ public function createElements(array $formData) { - $elements = array(); - $languages = array(); foreach (Translator::getAvailableLocaleCodes() as $language) { $languages[$language] = $language; } - $elements[] = $this->createElement( + $this->addElement( 'select', 'global_language', array( @@ -52,7 +50,7 @@ class ApplicationConfigForm extends Form $tzList[$tz] = $tz; } - $elements[] = $this->createElement( + $this->addElement( 'select', 'global_timezone', array( @@ -67,7 +65,7 @@ class ApplicationConfigForm extends Form ) ); - $elements[] = $this->createElement( + $this->addElement( 'text', 'global_modulePath', array( @@ -82,7 +80,7 @@ class ApplicationConfigForm extends Form ) ); - $elements[] = $this->createElement( + $this->addElement( 'select', 'preferences_type', array( @@ -104,7 +102,7 @@ class ApplicationConfigForm extends Form } } - $elements[] = $this->createElement( + $this->addElement( 'select', 'preferences_resource', array( @@ -115,6 +113,6 @@ class ApplicationConfigForm extends Form ); } - return $elements; + return $this; } } diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php index 07f2e4d78..135dd9e28 100644 --- a/application/forms/Config/General/LoggingConfigForm.php +++ b/application/forms/Config/General/LoggingConfigForm.php @@ -23,9 +23,7 @@ class LoggingConfigForm extends Form */ public function createElements(array $formData) { - $elements = array(); - - $elements[] = $this->createElement( + $this->addElement( 'select', 'logging_level', array( @@ -41,7 +39,7 @@ class LoggingConfigForm extends Form ) ) ); - $elements[] = $this->createElement( + $this->addElement( 'select', 'logging_type', array( @@ -57,7 +55,7 @@ class LoggingConfigForm extends Form ); if (false === isset($formData['logging_type']) || $formData['logging_type'] === 'syslog') { - $elements[] = $this->createElement( + $this->addElement( 'text', 'logging_application', array( @@ -79,7 +77,7 @@ class LoggingConfigForm extends Form ) ) ); - $elements[] = $this->createElement( + $this->addElement( 'select', 'logging_facility', array( @@ -92,7 +90,7 @@ class LoggingConfigForm extends Form ) ); } elseif ($formData['logging_type'] === 'file') { - $elements[] = $this->createElement( + $this->addElement( 'text', 'logging_target', array( @@ -105,7 +103,7 @@ class LoggingConfigForm extends Form ); } - return $elements; + return $this; } /** diff --git a/application/forms/Config/GeneralConfigForm.php b/application/forms/Config/GeneralConfigForm.php index ea89e1b76..ffb0a7d1c 100644 --- a/application/forms/Config/GeneralConfigForm.php +++ b/application/forms/Config/GeneralConfigForm.php @@ -31,11 +31,10 @@ class GeneralConfigForm extends ConfigForm { $appConfigForm = new ApplicationConfigForm(); $loggingConfigForm = new LoggingConfigForm(); + $this->addElements($appConfigForm->createElements($formData)->getElements()); + $this->addElements($loggingConfigForm->createElements($formData)->getElements()); - return array_merge( - $appConfigForm->createElements($formData), - $loggingConfigForm->createElements($formData) - ); + return $this; } /** diff --git a/application/forms/Config/Resource/DbResourceForm.php b/application/forms/Config/Resource/DbResourceForm.php index e5ae4b9a7..4fd7297d9 100644 --- a/application/forms/Config/Resource/DbResourceForm.php +++ b/application/forms/Config/Resource/DbResourceForm.php @@ -29,31 +29,31 @@ class DbResourceForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'select', - 'db', - array( - 'required' => true, - 'label' => t('Database Type'), - 'description' => t('The type of SQL database'), - 'multiOptions' => array( - 'mysql' => 'MySQL', - 'pgsql' => 'PostgreSQL' - //'oracle' => 'Oracle' - ) + $this->addElement( + 'select', + 'db', + array( + 'required' => true, + 'label' => t('Database Type'), + 'description' => t('The type of SQL database'), + 'multiOptions' => array( + 'mysql' => 'MySQL', + 'pgsql' => 'PostgreSQL' + //'oracle' => 'Oracle' ) - ), - $this->createElement( - 'text', - 'host', - array ( - 'required' => true, - 'label' => t('Host'), - 'description' => t('The hostname of the database'), - 'value' => 'localhost' - ) - ), + ) + ); + $this->addElement( + 'text', + 'host', + array ( + 'required' => true, + 'label' => t('Host'), + 'description' => t('The hostname of the database'), + 'value' => 'localhost' + ) + ); + $this->addElement( new Number( array( 'required' => true, @@ -62,36 +62,38 @@ class DbResourceForm extends Form 'description' => t('The port to use'), 'value' => 3306 ) - ), - $this->createElement( - 'text', - 'dbname', - array( - 'required' => true, - 'label' => t('Database Name'), - 'description' => t('The name of the database to use') - ) - ), - $this->createElement( - 'text', - 'username', - array ( - 'required' => true, - 'label' => t('Username'), - 'description' => t('The user name to use for authentication') - ) - ), - $this->createElement( - 'password', - 'password', - array( - 'required' => true, - 'renderPassword' => true, - 'label' => t('Password'), - 'description' => t('The password to use for authentication') - ) ) ); + $this->addElement( + 'text', + 'dbname', + array( + 'required' => true, + 'label' => t('Database Name'), + 'description' => t('The name of the database to use') + ) + ); + $this->addElement( + 'text', + 'username', + array ( + 'required' => true, + 'label' => t('Username'), + 'description' => t('The user name to use for authentication') + ) + ); + $this->addElement( + 'password', + 'password', + array( + 'required' => true, + 'renderPassword' => true, + 'label' => t('Password'), + 'description' => t('The password to use for authentication') + ) + ); + + return $this; } /** diff --git a/application/forms/Config/Resource/FileResourceForm.php b/application/forms/Config/Resource/FileResourceForm.php index 422979585..d1d33a749 100644 --- a/application/forms/Config/Resource/FileResourceForm.php +++ b/application/forms/Config/Resource/FileResourceForm.php @@ -25,26 +25,26 @@ class FileResourceForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'filename', - array( - 'required' => true, - 'label' => t('Filepath'), - 'description' => t('The filename to fetch information from'), - 'validators' => array(new ReadablePathValidator()) - ) - ), - $this->createElement( - 'text', - 'fields', - array( - 'required' => true, - 'label' => t('Pattern'), - 'description' => t('The regular expression by which to identify columns') - ) + $this->addElement( + 'text', + 'filename', + array( + 'required' => true, + 'label' => t('Filepath'), + 'description' => t('The filename to fetch information from'), + 'validators' => array(new ReadablePathValidator()) ) ); + $this->addElement( + 'text', + 'fields', + array( + 'required' => true, + 'label' => t('Pattern'), + 'description' => t('The regular expression by which to identify columns') + ) + ); + + return $this; } } diff --git a/application/forms/Config/Resource/LdapResourceForm.php b/application/forms/Config/Resource/LdapResourceForm.php index 3b3075dc7..6196f3a17 100644 --- a/application/forms/Config/Resource/LdapResourceForm.php +++ b/application/forms/Config/Resource/LdapResourceForm.php @@ -29,17 +29,17 @@ class LdapResourceForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'hostname', - array( - 'required' => true, - 'label' => t('Host'), - 'description' => t('The hostname or address of the LDAP server to use for authentication'), - 'value' => 'localhost' - ) - ), + $this->addElement( + 'text', + 'hostname', + array( + 'required' => true, + 'label' => t('Host'), + 'description' => t('The hostname or address of the LDAP server to use for authentication'), + 'value' => 'localhost' + ) + ); + $this->addElement( new Number( array( 'required' => true, @@ -48,36 +48,38 @@ class LdapResourceForm extends Form 'description' => t('The port of the LDAP server to use for authentication'), 'value' => 389 ) - ), - $this->createElement( - 'text', - 'root_dn', - array( - 'required' => true, - 'label' => t('Root DN'), - 'description' => t('The path where users can be found on the ldap server') - ) - ), - $this->createElement( - 'text', - 'bind_dn', - array( - 'required' => true, - 'label' => t('Bind DN'), - 'description' => t('The user dn to use for querying the ldap server') - ) - ), - $this->createElement( - 'password', - 'bind_pw', - array( - 'required' => true, - 'renderPassword' => true, - 'label' => t('Bind Password'), - 'description' => t('The password to use for querying the ldap server') - ) ) ); + $this->addElement( + 'text', + 'root_dn', + array( + 'required' => true, + 'label' => t('Root DN'), + 'description' => t('The path where users can be found on the ldap server') + ) + ); + $this->addElement( + 'text', + 'bind_dn', + array( + 'required' => true, + 'label' => t('Bind DN'), + 'description' => t('The user dn to use for querying the ldap server') + ) + ); + $this->addElement( + 'password', + 'bind_pw', + array( + 'required' => true, + 'renderPassword' => true, + 'label' => t('Bind Password'), + 'description' => t('The password to use for querying the ldap server') + ) + ); + + return $this; } /** diff --git a/application/forms/Config/Resource/LivestatusResourceForm.php b/application/forms/Config/Resource/LivestatusResourceForm.php index e7e49a375..92534f220 100644 --- a/application/forms/Config/Resource/LivestatusResourceForm.php +++ b/application/forms/Config/Resource/LivestatusResourceForm.php @@ -29,18 +29,18 @@ class LivestatusResourceForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'socket', - array( - 'required' => true, - 'label' => t('Socket'), - 'description' => t('The path to your livestatus socket used for querying monitoring data'), - 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/rw/livestatus') - ) + $this->addElement( + 'text', + 'socket', + array( + 'required' => true, + 'label' => t('Socket'), + 'description' => t('The path to your livestatus socket used for querying monitoring data'), + 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/rw/livestatus') ) ); + + return $this; } /** diff --git a/application/forms/Config/Resource/StatusdatResourceForm.php b/application/forms/Config/Resource/StatusdatResourceForm.php index 69c3d9040..f150056d1 100644 --- a/application/forms/Config/Resource/StatusdatResourceForm.php +++ b/application/forms/Config/Resource/StatusdatResourceForm.php @@ -26,29 +26,29 @@ class StatusdatResourceForm extends Form */ public function createElements(array $formData) { - return array( - $this->createElement( - 'text', - 'status_file', - array( - 'required' => true, - 'label' => t('Filepath'), - 'description' => t('Location of your icinga status.dat file'), - 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/status.dat'), - 'validators' => array(new ReadablePathValidator()) - ) - ), - $this->createElement( - 'text', - 'object_file', - array( - 'required' => true, - 'label' => t('Filepath'), - 'description' => t('Location of your icinga objects.cache file'), - 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/objects.cache'), - 'validators' => array(new ReadablePathValidator()) - ) + $this->addElement( + 'text', + 'status_file', + array( + 'required' => true, + 'label' => t('Filepath'), + 'description' => t('Location of your icinga status.dat file'), + 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/status.dat'), + 'validators' => array(new ReadablePathValidator()) ) ); + $this->addElement( + 'text', + 'object_file', + array( + 'required' => true, + 'label' => t('Filepath'), + 'description' => t('Location of your icinga objects.cache file'), + 'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/objects.cache'), + 'validators' => array(new ReadablePathValidator()) + ) + ); + + return $this; } } diff --git a/application/forms/Config/ResourceConfigForm.php b/application/forms/Config/ResourceConfigForm.php index 9a3ae7793..d9ec4dad3 100644 --- a/application/forms/Config/ResourceConfigForm.php +++ b/application/forms/Config/ResourceConfigForm.php @@ -224,35 +224,35 @@ class ResourceConfigForm extends ConfigForm $resourceTypes['db'] = t('SQL Database'); } - $elements = array( - $this->createElement( - 'text', - 'name', - array( - 'required' => true, - 'label' => t('Resource Name'), - 'description' => t('The unique name of this resource') - ) - ), - $this->createElement( - 'select', - 'type', - array( - 'required' => true, - 'autosubmit' => true, - 'label' => t('Resource Type'), - 'description' => t('The type of resource'), - 'multiOptions' => $resourceTypes, - 'value' => $resourceType - ) + $this->addElement( + 'text', + 'name', + array( + 'required' => true, + 'label' => t('Resource Name'), + 'description' => t('The unique name of this resource') + ) + ); + $this->addElement( + 'select', + 'type', + array( + 'required' => true, + 'autosubmit' => true, + 'label' => t('Resource Type'), + 'description' => t('The type of resource'), + 'multiOptions' => $resourceTypes, + 'value' => $resourceType ) ); if (isset($formData['force_creation']) && $formData['force_creation']) { // In case another error occured and the checkbox was displayed before - $elements[] = $this->getForceCreationCheckbox(); + $this->addElement($this->getForceCreationCheckbox()); } - return array_merge($elements, $this->getResourceForm($resourceType)->createElements($formData)); + $this->addElements($this->getResourceForm($resourceType)->createElements($formData)->getElements()); + + return $this; } } diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 2c0fb2a89..13ed535e3 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -269,8 +269,8 @@ class Form extends Zend_Form public function create(array $formData = array()) { if (false === $this->created) { - $this->addElements($this->createElements($formData)); - $this->addFormIdentification() + $this->createElements($formData) + ->addFormIdentification() ->addCsrfCounterMeasure() ->addSubmitButton(); @@ -287,17 +287,17 @@ class Form extends Zend_Form } /** - * Create and return the elements to add to this form + * Create and add elements to this form * * Intended to be implemented by concrete form classes. * * @param array $formData The data sent by the user * - * @return array + * @return self */ public function createElements(array $formData) { - return array(); + return $this; } /**