mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Form::createElements() should add elements instead of returning them
In case createElements() would still return the elements while requiring the caller to add them to the form all form dependent configurations get lost. (displaygroups, belongTo, ...) Wizards or parent forms can still retrieve only input relevant fields by just calling createElements() and getElements(). refs #5525
This commit is contained in:
parent
dd3901e891
commit
54a834266c
@ -26,8 +26,7 @@ class LoginForm extends Form
|
||||
*/
|
||||
public function createElements($formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'username',
|
||||
array(
|
||||
@ -36,8 +35,8 @@ class LoginForm extends Form
|
||||
'placeholder' => t('Please enter your username...'),
|
||||
'class' => false === isset($formData['username']) ? 'autofocus' : ''
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'password',
|
||||
'password',
|
||||
array(
|
||||
@ -46,14 +45,15 @@ class LoginForm extends Form
|
||||
'placeholder' => t('...and your password'),
|
||||
'class' => isset($formData['username']) ? 'autofocus' : ''
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'redirect',
|
||||
array(
|
||||
'value' => Url::fromRequest()->getParam('redirect')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ class AutologinBackendForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
@ -46,8 +45,8 @@ class AutologinBackendForm extends Form
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'strip_username_regexp',
|
||||
array(
|
||||
@ -61,16 +60,17 @@ class AutologinBackendForm extends Form
|
||||
})
|
||||
)
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'backend',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => 'autologin'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,8 +48,7 @@ class DbBackendForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
@ -57,8 +56,8 @@ class DbBackendForm extends Form
|
||||
'label' => t('Backend Name'),
|
||||
'description' => t('The name of this authentication provider'),
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource',
|
||||
array(
|
||||
@ -69,16 +68,17 @@ class DbBackendForm extends Form
|
||||
? array_combine($this->resources, $this->resources)
|
||||
: array()
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'backend',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => 'db'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,8 +47,7 @@ class LdapBackendForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
@ -56,8 +55,8 @@ class LdapBackendForm extends Form
|
||||
'label' => t('Backend Name'),
|
||||
'description' => t('The name of this authentication backend')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource',
|
||||
array(
|
||||
@ -68,8 +67,8 @@ class LdapBackendForm extends Form
|
||||
? array_combine($this->resources, $this->resources)
|
||||
: array()
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'user_class',
|
||||
array(
|
||||
@ -78,8 +77,8 @@ class LdapBackendForm extends Form
|
||||
'description' => t('The object class used for storing users on the ldap server'),
|
||||
'value' => 'inetOrgPerson'
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'user_name_attribute',
|
||||
array(
|
||||
@ -88,16 +87,17 @@ class LdapBackendForm extends Form
|
||||
'description' => t('The attribute name used for storing the user name on the ldap server'),
|
||||
'value' => 'uid'
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'backend',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => 'ldap'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,8 +29,7 @@ class DbResourceForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'select',
|
||||
'db',
|
||||
array(
|
||||
@ -43,8 +42,8 @@ class DbResourceForm extends Form
|
||||
//'oracle' => 'Oracle'
|
||||
)
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'host',
|
||||
array (
|
||||
@ -53,7 +52,8 @@ class DbResourceForm extends Form
|
||||
'description' => t('The hostname of the database'),
|
||||
'value' => 'localhost'
|
||||
)
|
||||
),
|
||||
);
|
||||
$this->addElement(
|
||||
new Number(
|
||||
array(
|
||||
'required' => true,
|
||||
@ -62,8 +62,9 @@ class DbResourceForm extends Form
|
||||
'description' => t('The port to use'),
|
||||
'value' => 3306
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'dbname',
|
||||
array(
|
||||
@ -71,8 +72,8 @@ class DbResourceForm extends Form
|
||||
'label' => t('Database Name'),
|
||||
'description' => t('The name of the database to use')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'username',
|
||||
array (
|
||||
@ -80,8 +81,8 @@ class DbResourceForm extends Form
|
||||
'label' => t('Username'),
|
||||
'description' => t('The user name to use for authentication')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'password',
|
||||
'password',
|
||||
array(
|
||||
@ -90,8 +91,9 @@ class DbResourceForm extends Form
|
||||
'label' => t('Password'),
|
||||
'description' => t('The password to use for authentication')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,8 +25,7 @@ class FileResourceForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'filename',
|
||||
array(
|
||||
@ -35,8 +34,8 @@ class FileResourceForm extends Form
|
||||
'description' => t('The filename to fetch information from'),
|
||||
'validators' => array(new ReadablePathValidator())
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'fields',
|
||||
array(
|
||||
@ -44,7 +43,8 @@ class FileResourceForm extends Form
|
||||
'label' => t('Pattern'),
|
||||
'description' => t('The regular expression by which to identify columns')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ class LdapResourceForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'hostname',
|
||||
array(
|
||||
@ -39,7 +38,8 @@ class LdapResourceForm extends Form
|
||||
'description' => t('The hostname or address of the LDAP server to use for authentication'),
|
||||
'value' => 'localhost'
|
||||
)
|
||||
),
|
||||
);
|
||||
$this->addElement(
|
||||
new Number(
|
||||
array(
|
||||
'required' => true,
|
||||
@ -48,8 +48,9 @@ class LdapResourceForm extends Form
|
||||
'description' => t('The port of the LDAP server to use for authentication'),
|
||||
'value' => 389
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'root_dn',
|
||||
array(
|
||||
@ -57,8 +58,8 @@ class LdapResourceForm extends Form
|
||||
'label' => t('Root DN'),
|
||||
'description' => t('The path where users can be found on the ldap server')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'bind_dn',
|
||||
array(
|
||||
@ -66,8 +67,8 @@ class LdapResourceForm extends Form
|
||||
'label' => t('Bind DN'),
|
||||
'description' => t('The user dn to use for querying the ldap server')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'password',
|
||||
'bind_pw',
|
||||
array(
|
||||
@ -76,8 +77,9 @@ class LdapResourceForm extends Form
|
||||
'label' => t('Bind Password'),
|
||||
'description' => t('The password to use for querying the ldap server')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,8 +29,7 @@ class LivestatusResourceForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'socket',
|
||||
array(
|
||||
@ -39,8 +38,9 @@ class LivestatusResourceForm extends Form
|
||||
'description' => t('The path to your livestatus socket used for querying monitoring data'),
|
||||
'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/rw/livestatus')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,8 +26,7 @@ class StatusdatResourceForm extends Form
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
return array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'status_file',
|
||||
array(
|
||||
@ -37,8 +36,8 @@ class StatusdatResourceForm extends Form
|
||||
'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/status.dat'),
|
||||
'validators' => array(new ReadablePathValidator())
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'object_file',
|
||||
array(
|
||||
@ -48,7 +47,8 @@ class StatusdatResourceForm extends Form
|
||||
'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/objects.cache'),
|
||||
'validators' => array(new ReadablePathValidator())
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -224,8 +224,7 @@ class ResourceConfigForm extends ConfigForm
|
||||
$resourceTypes['db'] = t('SQL Database');
|
||||
}
|
||||
|
||||
$elements = array(
|
||||
$this->createElement(
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
@ -233,8 +232,8 @@ class ResourceConfigForm extends ConfigForm
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
),
|
||||
$this->createElement(
|
||||
);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'type',
|
||||
array(
|
||||
@ -245,14 +244,15 @@ class ResourceConfigForm extends ConfigForm
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user