Add ConfigFormEventsHook to UserForm.php
Add ConfigFormEventsHook to UserGroupForm.php Add check in getValues for UserForm.php
This commit is contained in:
parent
9a29d8f3d4
commit
0520ed348d
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\User;
|
namespace Icinga\Forms\Config\User;
|
||||||
|
|
||||||
|
use Icinga\Application\Hook\ConfigFormEventsHook;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Forms\RepositoryForm;
|
use Icinga\Forms\RepositoryForm;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
class UserForm extends RepositoryForm
|
class UserForm extends RepositoryForm
|
||||||
{
|
{
|
||||||
|
@ -97,7 +99,10 @@ class UserForm extends RepositoryForm
|
||||||
public function getValues($suppressArrayNotation = false)
|
public function getValues($suppressArrayNotation = false)
|
||||||
{
|
{
|
||||||
$values = parent::getValues($suppressArrayNotation);
|
$values = parent::getValues($suppressArrayNotation);
|
||||||
if (! $values['password']) {
|
// before checking if password values is empty
|
||||||
|
// we have to check that the password field is set
|
||||||
|
// otherwise an error is thrown
|
||||||
|
if (isset($values['password']) && ! $values['password']) {
|
||||||
unset($values['password']);
|
unset($values['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,4 +178,33 @@ class UserForm extends RepositoryForm
|
||||||
return sprintf($this->translate('Failed to remove user "%s"'), $this->getIdentifier());
|
return sprintf($this->translate('Failed to remove user "%s"'), $this->getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isValid($formData)
|
||||||
|
{
|
||||||
|
$valid = parent::isValid($formData);
|
||||||
|
|
||||||
|
if ($valid && ConfigFormEventsHook::runIsValid($this) === false) {
|
||||||
|
foreach (ConfigFormEventsHook::getLastErrors() as $msg) {
|
||||||
|
$this->error($msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
if (parent::onSuccess() === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigFormEventsHook::runOnSuccess($this) === false) {
|
||||||
|
Notification::error($this->translate(
|
||||||
|
'Configuration successfully stored. Though, one or more module hooks failed to run.'
|
||||||
|
. ' See logs for details'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\UserGroup;
|
namespace Icinga\Forms\Config\UserGroup;
|
||||||
|
|
||||||
|
use Icinga\Application\Hook\ConfigFormEventsHook;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Forms\RepositoryForm;
|
use Icinga\Forms\RepositoryForm;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
class UserGroupForm extends RepositoryForm
|
class UserGroupForm extends RepositoryForm
|
||||||
{
|
{
|
||||||
|
@ -124,4 +126,33 @@ class UserGroupForm extends RepositoryForm
|
||||||
return sprintf($this->translate('Failed to remove group "%s"'), $this->getIdentifier());
|
return sprintf($this->translate('Failed to remove group "%s"'), $this->getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isValid($formData)
|
||||||
|
{
|
||||||
|
$valid = parent::isValid($formData);
|
||||||
|
|
||||||
|
if ($valid && ConfigFormEventsHook::runIsValid($this) === false) {
|
||||||
|
foreach (ConfigFormEventsHook::getLastErrors() as $msg) {
|
||||||
|
$this->error($msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
if (parent::onSuccess() === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigFormEventsHook::runOnSuccess($this) === false) {
|
||||||
|
Notification::error($this->translate(
|
||||||
|
'Configuration successfully stored. Though, one or more module hooks failed to run.'
|
||||||
|
. ' See logs for details'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue