Merge branch 'bugfix/form-createelements-in-wizard-2990'

fixes #2990
This commit is contained in:
Alexander A. Klimov 2017-10-06 14:53:26 +02:00
commit 9bc64d931e
3 changed files with 92 additions and 14 deletions

View File

@ -22,6 +22,13 @@ class LdapBackendForm extends Form
*/
protected $resources;
/**
* Default values for the form elements
*
* @var string[]
*/
protected $suggestions = array();
/**
* Initialize this form
*/
@ -60,7 +67,8 @@ class LdapBackendForm extends Form
'label' => $this->translate('Backend Name'),
'description' => $this->translate(
'The name of this authentication provider that is used to differentiate it from others.'
)
),
'value' => $this->getSuggestion('name')
)
);
$this->addElement(
@ -74,11 +82,11 @@ class LdapBackendForm extends Form
),
'multiOptions' => !empty($this->resources)
? array_combine($this->resources, $this->resources)
: array()
: array(),
'value' => $this->getSuggestion('resource')
)
);
$baseDn = null;
$hasAdOid = false;
if (! $isAd && !empty($this->resources)) {
$this->addElement(
@ -141,7 +149,7 @@ class LdapBackendForm extends Form
'disabled' => $isAd ?: null,
'label' => $this->translate('LDAP User Object Class'),
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
'value' => $userClass
'value' => $this->getSuggestion('user_class', $userClass)
)
);
$this->addElement(
@ -150,7 +158,7 @@ class LdapBackendForm extends Form
array(
'preserveDefault' => true,
'allowEmpty' => true,
'value' => $filter,
'value' => $this->getSuggestion('filter', $filter),
'label' => $this->translate('LDAP Filter'),
'description' => $this->translate(
'An additional filter to use when looking up users using the specified connection. '
@ -193,7 +201,7 @@ class LdapBackendForm extends Form
'description' => $this->translate(
'The attribute name used for storing the user name on the LDAP server.'
),
'value' => $userNameAttribute
'value' => $this->getSuggestion('user_name_attribute', $userNameAttribute)
)
);
$this->addElement(
@ -201,7 +209,7 @@ class LdapBackendForm extends Form
'backend',
array(
'disabled' => true,
'value' => $isAd ? 'msldap' : 'ldap'
'value' => $this->getSuggestion('backend', $isAd ? 'msldap' : 'ldap')
)
);
$this->addElement(
@ -215,7 +223,7 @@ class LdapBackendForm extends Form
'The path where users can be found on the LDAP server. Leave ' .
'empty to select all users available using the specified connection.'
),
'value' => $baseDn
'value' => isset($baseDn) ? $baseDn : $this->getSuggestion('base_dn')
)
);
@ -233,7 +241,8 @@ class LdapBackendForm extends Form
. ' If your LDAP backend holds usernames with a domain part or if it is not necessary in your setup'
. ' to authenticate users based on their domains, leave this field empty.'
),
'preserveDefault' => true
'preserveDefault' => true,
'value' => $this->getSuggestion('domain')
)
);
@ -318,4 +327,41 @@ class LdapBackendForm extends Form
}
}
}
/**
* Get the default values for the form elements
*
* @return string[]
*/
public function getSuggestions()
{
return $this->suggestions;
}
/**
* Get the default value for the given form element or the given default
*
* @param string $element
* @param string $default
*
* @return string
*/
public function getSuggestion($element, $default = null)
{
return isset($this->suggestions[$element]) ? $this->suggestions[$element] : $default;
}
/**
* Set the default values for the form elements
*
* @param string[] $suggestions
*
* @return $this
*/
public function setSuggestions(array $suggestions)
{
$this->suggestions = $suggestions;
return $this;
}
}

View File

@ -23,6 +23,13 @@ class AuthBackendPage extends Form
*/
protected $config;
/**
* Default values for the subform's elements suggested by a previous step
*
* @var string[]
*/
protected $suggestions = array();
/**
* Initialize this page
*/
@ -78,6 +85,7 @@ class AuthBackendPage extends Form
}
$backendForm = new LdapBackendForm();
$backendForm->setSuggestions($this->suggestions);
$backendForm->setResources(array($this->config['name']));
$backendForm->create($formData);
$backendForm->getElement('resource')->setIgnore(true);
@ -231,4 +239,28 @@ class AuthBackendPage extends Form
)
);
}
/**
* Get default values for the subform's elements suggested by a previous step
*
* @return string[]
*/
public function getSuggestions()
{
return $this->suggestions;
}
/**
* Set default values for the subform's elements suggested by a previous step
*
* @param string[] $suggestions
*
* @return $this
*/
public function setSuggestions(array $suggestions)
{
$this->suggestions = $suggestions;
return $this;
}
}

View File

@ -132,17 +132,17 @@ class WebWizard extends Wizard implements SetupWizard
if ($page->getName() === 'setup_requirements') {
$page->setWizard($this);
} elseif ($page->getName() === 'setup_authentication_backend') {
/** @var AuthBackendPage $page */
$authData = $this->getPageData('setup_authentication_type');
if ($authData['type'] === 'db') {
$page->setResourceConfig($this->getPageData('setup_auth_db_resource'));
} elseif ($authData['type'] === 'ldap') {
$page->setResourceConfig($this->getPageData('setup_ldap_resource'));
if (! $this->hasPageData('setup_authentication_backend')) {
$suggestions = $this->getPageData('setup_ldap_discovery');
if (isset($suggestions['backend'])) {
$page->populate($suggestions['backend']);
}
$suggestions = $this->getPageData('setup_ldap_discovery');
if (isset($suggestions['backend'])) {
$page->setSuggestions($suggestions['backend']);
}
if ($this->getDirection() === static::FORWARD) {