UserGroupBackendPage: Ensure that all required fields exist

refs #9609
This commit is contained in:
Johannes Meyer 2015-07-30 15:49:04 +02:00
parent 9cd419d330
commit 5ca0e981c4
4 changed files with 71 additions and 35 deletions

View File

@ -26,6 +26,32 @@ class DbUserGroupBackendForm extends Form
*/
public function createElements(array $formData)
{
$this->addElement(
'text',
'name',
array(
'required' => true,
'label' => $this->translate('Backend Name'),
'description' => $this->translate(
'The name of this user group backend that is used to differentiate it from others'
),
'validators' => array(
array(
'Regex',
false,
array(
'pattern' => '/^[^\\[\\]:]+$/',
'messages' => array(
'regexNotMatch' => $this->translate(
'The name cannot contain \'[\', \']\' or \':\'.'
)
)
)
)
)
)
);
$resourceNames = $this->getDatabaseResourceNames();
$this->addElement(
'select',
@ -37,6 +63,15 @@ class DbUserGroupBackendForm extends Form
'multiOptions' => empty($resourceNames) ? array() : array_combine($resourceNames, $resourceNames)
)
);
$this->addElement(
'hidden',
'backend',
array(
'disabled' => true, // Prevents the element from being submitted, see #7717
'value' => 'db'
)
);
}
/**

View File

@ -31,6 +31,32 @@ class LdapUserGroupBackendForm extends Form
*/
public function createElements(array $formData)
{
$this->addElement(
'text',
'name',
array(
'required' => true,
'label' => $this->translate('Backend Name'),
'description' => $this->translate(
'The name of this user group backend that is used to differentiate it from others'
),
'validators' => array(
array(
'Regex',
false,
array(
'pattern' => '/^[^\\[\\]:]+$/',
'messages' => array(
'regexNotMatch' => $this->translate(
'The name cannot contain \'[\', \']\' or \':\'.'
)
)
)
)
)
)
);
$resourceNames = $this->getLdapResourceNames();
$this->addElement(
'select',
@ -89,6 +115,15 @@ class LdapUserGroupBackendForm extends Form
$this->createGroupConfigElements($defaults, $groupConfigDisabled);
$this->createUserConfigElements($defaults, $userConfigDisabled, $dnDisabled);
$this->addElement(
'hidden',
'backend',
array(
'disabled' => true, // Prevents the element from being submitted, see #7717
'value' => $formData['type']
)
);
}
/**

View File

@ -158,32 +158,6 @@ class UserGroupBackendForm extends ConfigForm
*/
public function createElements(array $formData)
{
$this->addElement(
'text',
'name',
array(
'required' => true,
'label' => $this->translate('Backend Name'),
'description' => $this->translate(
'The name of this user group backend that is used to differentiate it from others'
),
'validators' => array(
array(
'Regex',
false,
array(
'pattern' => '/^[^\\[\\]:]+$/',
'messages' => array(
'regexNotMatch' => $this->translate(
'The name cannot contain \'[\', \']\' or \':\'.'
)
)
)
)
)
)
);
// TODO(jom): We did not think about how to configure custom group backends yet!
$backendTypes = array(
'db' => $this->translate('Database'),
@ -196,15 +170,6 @@ class UserGroupBackendForm extends ConfigForm
$backendType = key($backendTypes);
}
$this->addElement(
'hidden',
'backend',
array(
'disabled' => true, // Prevents the element from being submitted, see #7717
'value' => $backendType
)
);
$this->addElement(
'select',
'type',

View File

@ -110,6 +110,7 @@ class UserGroupBackendPage extends Form
$backendForm->create($formData);
$userBackendOptions = $backendForm->getElement('user_backend')->getMultiOptions();
unset($userBackendOptions['none']);
$backendForm->getElement('name')->setValue('icingaweb2');
$backendForm->getElement('user_backend')->setMultiOptions($userBackendOptions);
$this->addSubForm($backendForm, 'backend_form');
}