Do not populate using createElements() and fix documentation blocks

refs #5525
This commit is contained in:
Johannes Meyer 2014-08-22 12:04:14 +02:00
parent bc05d2ee64
commit 2b879b344f
5 changed files with 27 additions and 38 deletions

View File

@ -6,6 +6,9 @@ namespace Icinga\Form\Config\Authentication;
use Zend_Validate_Callback; use Zend_Validate_Callback;
/**
* Form class for adding/modifying autologin authentication backends
*/
class AutologinBackendForm extends BaseBackendForm class AutologinBackendForm extends BaseBackendForm
{ {
public function isValidAuthenticationBackend() public function isValidAuthenticationBackend()
@ -13,6 +16,9 @@ class AutologinBackendForm extends BaseBackendForm
return true; return true;
} }
/**
* @see Form::createElements()
*/
public function createElements(array $formData) public function createElements(array $formData)
{ {
return array( return array(
@ -24,7 +30,6 @@ class AutologinBackendForm extends BaseBackendForm
'allowEmpty' => false, 'allowEmpty' => false,
'label' => t('Backend Name'), 'label' => t('Backend Name'),
'helptext' => t('The name of this authentication backend'), 'helptext' => t('The name of this authentication backend'),
'value' => '',
'validators' => array( 'validators' => array(
array( array(
'Regex', 'Regex',

View File

@ -31,9 +31,9 @@ class GeneralForm extends Form
public function createElements(array $formData) public function createElements(array $formData)
{ {
$elements = array( $elements = array(
$this->getLanguageSelection($formData), $this->getLanguageSelection(),
$this->getTimezoneSelection($formData), $this->getTimezoneSelection(),
$this->getModulePathInput($formData) $this->getModulePathInput()
); );
return array_merge( return array_merge(
@ -102,11 +102,9 @@ class GeneralForm extends Form
* *
* Possible values are determined by Translator::getAvailableLocaleCodes. * Possible values are determined by Translator::getAvailableLocaleCodes.
* *
* @param array $formData The data to populate the elements with
*
* @return Zend_Form_Element * @return Zend_Form_Element
*/ */
protected function getLanguageSelection(array $formData) protected function getLanguageSelection()
{ {
$languages = array(); $languages = array();
foreach (Translator::getAvailableLocaleCodes() as $language) { foreach (Translator::getAvailableLocaleCodes() as $language) {
@ -122,8 +120,7 @@ class GeneralForm extends Form
'multiOptions' => $languages, 'multiOptions' => $languages,
'helptext' => t( 'helptext' => t(
'Select the language to use by default. Can be overwritten by a user in his preferences.' '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
) )
); );
} }
@ -133,11 +130,9 @@ class GeneralForm extends Form
* *
* Possible values are determined by DateTimeZone::listIdentifiers. * Possible values are determined by DateTimeZone::listIdentifiers.
* *
* @param array $formData The data to populate the elements with
*
* @return Zend_Form_Element * @return Zend_Form_Element
*/ */
protected function getTimezoneSelection(array $formData) protected function getTimezoneSelection()
{ {
$tzList = array(); $tzList = array();
foreach (DateTimeZone::listIdentifiers() as $tz) { foreach (DateTimeZone::listIdentifiers() as $tz) {
@ -155,17 +150,15 @@ class GeneralForm extends Form
'Select the timezone to be used as the default. User\'s can set their own timezone if' '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 .' . ' 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 * 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( $this->addElement(
'text', 'text',
@ -178,9 +171,7 @@ class GeneralForm extends Form
. 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . '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.' . 'the module folder, but won\'t show up in the list of disabled modules.'
), ),
'value' => isset($formData['modulePath']) 'value' => realpath(ICINGAWEB_APPDIR . '/../modules')
? $formData['modulePath']
: realpath(ICINGAWEB_APPDIR . '/../modules')
) )
); );
} }
@ -188,7 +179,7 @@ class GeneralForm extends Form
/** /**
* Return form elements for setting the user preference storage backend * 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) protected function getPreferencesElements(array $formData)
{ {
@ -200,7 +191,6 @@ class GeneralForm extends Form
'required' => true, 'required' => true,
'class' => 'autosubmit', 'class' => 'autosubmit',
'label' => t('User Preference Storage Type'), 'label' => t('User Preference Storage Type'),
'value' => isset($formData['preferences_type']) ? $formData['preferences_type'] : 'ini',
'multiOptions' => array( 'multiOptions' => array(
'ini' => t('File System (INI Files)'), 'ini' => t('File System (INI Files)'),
'db' => t('Database'), 'db' => t('Database'),
@ -224,10 +214,7 @@ class GeneralForm extends Form
array( array(
'required' => true, 'required' => true,
'multiOptions' => $backends, 'multiOptions' => $backends,
'label' => t('Database Connection'), 'label' => t('Database Connection')
'value' => isset($formData['preferences_resource'])
? $formData['preferences_resource']
: null
) )
); );
} }

View File

@ -28,7 +28,7 @@ class GeneralForm extends Form
* Possible values are determined by Translator::getAvailableLocaleCodes. * 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 * 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) protected function getLanguageElements(array $formData)
{ {
@ -43,9 +43,7 @@ class GeneralForm extends Form
'required' => false === $useBrowserLanguage, 'required' => false === $useBrowserLanguage,
'multiOptions' => $languages, 'multiOptions' => $languages,
'helptext' => t('Use the following language to display texts and messages'), 'helptext' => t('Use the following language to display texts and messages'),
'value' => isset($formData['language']) 'value' => substr(setlocale(LC_ALL, 0), 0, 5)
? $formData['language']
: substr(setlocale(LC_ALL, 0), 0, 5)
); );
if ($useBrowserLanguage) { if ($useBrowserLanguage) {
$selectOptions['disabled'] = 'disabled'; $selectOptions['disabled'] = 'disabled';
@ -72,7 +70,7 @@ class GeneralForm extends Form
* Possible values are determined by DateTimeZone::listIdentifiers. * 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 * 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) protected function getTimezoneElements(array $formData)
{ {
@ -87,9 +85,7 @@ class GeneralForm extends Form
'required' => false === $useLocalTimezone, 'required' => false === $useLocalTimezone,
'multiOptions' => $tzList, 'multiOptions' => $tzList,
'helptext' => t('Use the following timezone for dates and times'), 'helptext' => t('Use the following timezone for dates and times'),
'value' => isset($formData['timezone']) 'value' => date_default_timezone_get()
? $formData['timezone']
: date_default_timezone_get()
); );
if ($useLocalTimezone) { if ($useLocalTimezone) {
$selectOptions['disabled'] = 'disabled'; $selectOptions['disabled'] = 'disabled';
@ -120,8 +116,7 @@ class GeneralForm extends Form
'checkbox', 'checkbox',
'show_benchmark', 'show_benchmark',
array( array(
'label' => t('Use benchmark'), 'label' => t('Use benchmark')
'value' => isset($formData['show_benchmark']) ? $formData['show_benchmark'] : 0
) )
); );

View File

@ -123,7 +123,7 @@ class Form extends Zend_Form
/** /**
* Create this form * Create this form
* *
* @param array $formData The data to populate the form with * @param array $formData The data sent by the user
* *
* @return self * @return self
*/ */
@ -150,7 +150,7 @@ class Form extends Zend_Form
* *
* Intended to be implemented by concrete form classes. * 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 * @return array
*/ */

View File

@ -7,6 +7,9 @@ namespace Icinga\Module\Monitoring\Form\Config;
use Zend_Config; use Zend_Config;
use Icinga\Web\Form; use Icinga\Web\Form;
/**
* Form for modifying security relevant settings
*/
class SecurityForm extends Form class SecurityForm extends Form
{ {
/** /**
@ -26,7 +29,6 @@ class SecurityForm extends Form
array( array(
'label' => 'Protected Custom Variables', 'label' => 'Protected Custom Variables',
'required' => true, 'required' => true,
'value' => $this->config->protected_customvars,
'helptext' => 'Comma separated case insensitive list of protected custom variables.' 'helptext' => 'Comma separated case insensitive list of protected custom variables.'
. ' Use * as a placeholder for zero or more wildcard characters.' . ' Use * as a placeholder for zero or more wildcard characters.'
. ' Existance of those custom variables will be shown, but their values will be masked.' . ' Existance of those custom variables will be shown, but their values will be masked.'