Merge branch 'bugfix/rebuild-form-builder-5525' into bugfix/commands-6593

This commit is contained in:
Eric Lippmann 2014-09-03 23:23:02 +02:00
commit a4da3b61b3
15 changed files with 337 additions and 337 deletions

View File

@ -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;
}
}

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
}

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
/**