Provide suggestions for AuthBackendPage as element defaults

refs #2990
This commit is contained in:
Alexander A. Klimov 2017-10-06 11:12:11 +02:00
parent a0ffdb0f7c
commit de53925c7c
2 changed files with 43 additions and 5 deletions

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
*/
@ -112,6 +119,13 @@ class AuthBackendPage extends Form
));
}
foreach ($this->suggestions as $key => $suggestion) {
$element = $backendForm->getElement($key);
if ($element !== null) {
$element->setValue($suggestion);
}
}
$backendForm->getElement('name')->setValue('icingaweb2');
$this->addSubForm($backendForm, 'backend_form');
}
@ -231,4 +245,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') && ! $request->isPost()) {
$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) {