Skip to content

Commit

Permalink
Do not populate using createElements() and fix documentation blocks
Browse files Browse the repository at this point in the history
refs #5525
  • Loading branch information
Johannes Meyer committed Aug 22, 2014
1 parent bc05d2e commit 2b879b3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 38 deletions.
Expand Up @@ -6,13 +6,19 @@

use Zend_Validate_Callback;

/**
* Form class for adding/modifying autologin authentication backends
*/
class AutologinBackendForm extends BaseBackendForm
{
public function isValidAuthenticationBackend()
{
return true;
}

/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
return array(
Expand All @@ -24,7 +30,6 @@ public function createElements(array $formData)
'allowEmpty' => false,
'label' => t('Backend Name'),
'helptext' => t('The name of this authentication backend'),
'value' => '',
'validators' => array(
array(
'Regex',
Expand Down
35 changes: 11 additions & 24 deletions application/forms/Config/GeneralForm.php
Expand Up @@ -31,9 +31,9 @@ public function init()
public function createElements(array $formData)
{
$elements = array(
$this->getLanguageSelection($formData),
$this->getTimezoneSelection($formData),
$this->getModulePathInput($formData)
$this->getLanguageSelection(),
$this->getTimezoneSelection(),
$this->getModulePathInput()
);

return array_merge(
Expand Down Expand Up @@ -102,11 +102,9 @@ public function getConfiguration()
*
* Possible values are determined by Translator::getAvailableLocaleCodes.
*
* @param array $formData The data to populate the elements with
*
* @return Zend_Form_Element
*/
protected function getLanguageSelection(array $formData)
protected function getLanguageSelection()
{
$languages = array();
foreach (Translator::getAvailableLocaleCodes() as $language) {
Expand All @@ -122,8 +120,7 @@ protected function getLanguageSelection(array $formData)
'multiOptions' => $languages,
'helptext' => t(
'Select the language to use by default. Can be overwritten by a user in his preferences.'
),
'value' => isset($formData['language']) ? $formData['language'] : Translator::DEFAULT_LOCALE
)
)
);
}
Expand All @@ -133,11 +130,9 @@ protected function getLanguageSelection(array $formData)
*
* Possible values are determined by DateTimeZone::listIdentifiers.
*
* @param array $formData The data to populate the elements with
*
* @return Zend_Form_Element
*/
protected function getTimezoneSelection(array $formData)
protected function getTimezoneSelection()
{
$tzList = array();
foreach (DateTimeZone::listIdentifiers() as $tz) {
Expand All @@ -155,17 +150,15 @@ protected function getTimezoneSelection(array $formData)
'Select the timezone to be used as the default. User\'s can set their own timezone if'
. ' they like to, but this is the timezone to be used as the default setting .'
),
'value' => isset($formData['timezone']) ? $formData['timezone'] : date_default_timezone_get()
'value' => date_default_timezone_get()
)
);
}

/**
* Return a input field for setting the module path
*
* @param array $formData The data to populate the elements with
*/
protected function getModulePathInput(array $formData)
protected function getModulePathInput()
{
$this->addElement(
'text',
Expand All @@ -178,17 +171,15 @@ protected function getModulePathInput(array $formData)
. 'colons. Modules that don\'t exist in these directories can still be symlinked in '
. 'the module folder, but won\'t show up in the list of disabled modules.'
),
'value' => isset($formData['modulePath'])
? $formData['modulePath']
: realpath(ICINGAWEB_APPDIR . '/../modules')
'value' => realpath(ICINGAWEB_APPDIR . '/../modules')
)
);
}

/**
* Return form elements for setting the user preference storage backend
*
* @param array $formData The data to populate the elements with
* @param array $formData The data sent by the user
*/
protected function getPreferencesElements(array $formData)
{
Expand All @@ -200,7 +191,6 @@ protected function getPreferencesElements(array $formData)
'required' => true,
'class' => 'autosubmit',
'label' => t('User Preference Storage Type'),
'value' => isset($formData['preferences_type']) ? $formData['preferences_type'] : 'ini',
'multiOptions' => array(
'ini' => t('File System (INI Files)'),
'db' => t('Database'),
Expand All @@ -224,10 +214,7 @@ protected function getPreferencesElements(array $formData)
array(
'required' => true,
'multiOptions' => $backends,
'label' => t('Database Connection'),
'value' => isset($formData['preferences_resource'])
? $formData['preferences_resource']
: null
'label' => t('Database Connection')
)
);
}
Expand Down
15 changes: 5 additions & 10 deletions application/forms/Preference/GeneralForm.php
Expand Up @@ -28,7 +28,7 @@ public function init()
* Possible values are determined by Translator::getAvailableLocaleCodes.
* Also, a 'use browser language' checkbox is added in order to allow a user to discard his setting
*
* @param array $formData The data to populate the elements with
* @param array $formData The data sent by the user
*/
protected function getLanguageElements(array $formData)
{
Expand All @@ -43,9 +43,7 @@ protected function getLanguageElements(array $formData)
'required' => false === $useBrowserLanguage,
'multiOptions' => $languages,
'helptext' => t('Use the following language to display texts and messages'),
'value' => isset($formData['language'])
? $formData['language']
: substr(setlocale(LC_ALL, 0), 0, 5)
'value' => substr(setlocale(LC_ALL, 0), 0, 5)
);
if ($useBrowserLanguage) {
$selectOptions['disabled'] = 'disabled';
Expand All @@ -72,7 +70,7 @@ protected function getLanguageElements(array $formData)
* Possible values are determined by DateTimeZone::listIdentifiers.
* Also, a 'use local timezone' checkbox is added in order to allow a user to discard his overwritten setting
*
* @param array $formData The data to populate the elements with
* @param array $formData The data sent by the user
*/
protected function getTimezoneElements(array $formData)
{
Expand All @@ -87,9 +85,7 @@ protected function getTimezoneElements(array $formData)
'required' => false === $useLocalTimezone,
'multiOptions' => $tzList,
'helptext' => t('Use the following timezone for dates and times'),
'value' => isset($formData['timezone'])
? $formData['timezone']
: date_default_timezone_get()
'value' => date_default_timezone_get()
);
if ($useLocalTimezone) {
$selectOptions['disabled'] = 'disabled';
Expand Down Expand Up @@ -120,8 +116,7 @@ public function createElements(array $formData)
'checkbox',
'show_benchmark',
array(
'label' => t('Use benchmark'),
'value' => isset($formData['show_benchmark']) ? $formData['show_benchmark'] : 0
'label' => t('Use benchmark')
)
);

Expand Down
4 changes: 2 additions & 2 deletions library/Icinga/Web/Form.php
Expand Up @@ -123,7 +123,7 @@ public function getTokenElementName()
/**
* Create this form
*
* @param array $formData The data to populate the form with
* @param array $formData The data sent by the user
*
* @return self
*/
Expand All @@ -150,7 +150,7 @@ public function create(array $formData = array())
*
* Intended to be implemented by concrete form classes.
*
* @param array $formData The data to populate the elements with
* @param array $formData The data sent by the user
*
* @return array
*/
Expand Down
4 changes: 3 additions & 1 deletion modules/monitoring/application/forms/Config/SecurityForm.php
Expand Up @@ -7,6 +7,9 @@
use Zend_Config;
use Icinga\Web\Form;

/**
* Form for modifying security relevant settings
*/
class SecurityForm extends Form
{
/**
Expand All @@ -26,7 +29,6 @@ public function createElements(array $formData)
array(
'label' => 'Protected Custom Variables',
'required' => true,
'value' => $this->config->protected_customvars,
'helptext' => 'Comma separated case insensitive list of protected custom variables.'
. ' Use * as a placeholder for zero or more wildcard characters.'
. ' Existance of those custom variables will be shown, but their values will be masked.'
Expand Down

0 comments on commit 2b879b3

Please sign in to comment.