Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/Admin/src/Form/CreateAdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Submit;
use Laminas\Form\Element\Text;
use Laminas\Form\Exception\ExceptionInterface;
use Laminas\Session\Container;

/**
Expand All @@ -24,6 +25,7 @@ class CreateAdminForm extends AbstractForm
{
/**
* @param array<non-empty-string, mixed> $options
* @throws ExceptionInterface
*/
public function __construct(?string $name = null, array $options = [])
{
Expand All @@ -41,16 +43,20 @@ public function __construct(?string $name = null, array $options = [])

/**
* @phpstan-param SelectDataType[] $roles
* @throws ExceptionInterface
*/
public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
return $this->add(
(new MultiCheckbox('roles'))
->setLabel('Select at least one role')
->setValueOptions($roles)
);
$checkbox = new MultiCheckbox('roles');
$checkbox->setLabel('Select at least one role');
$checkbox->setValueOptions($roles);
$this->add($checkbox);
return $this;
}

/**
* @throws ExceptionInterface
*/
public function init(): void
{
$this->add(
Expand All @@ -76,12 +82,13 @@ public function init(): void
(new Text('lastName'))
->setLabel('Lastname')
);
$this->add(
(new Select('status'))
->setLabel('Account status')
->setValueOptions(AdminStatusEnum::toArray())
->setAttribute('required', true)
);

$select = new Select('status');
$select->setLabel('Account status');
$select->setValueOptions(AdminStatusEnum::toArray());
$select->setAttribute('required', true);
$this->add($select);

$this->add(
(new Csrf('adminCreateCsrf'))
->setOptions([
Expand Down
31 changes: 19 additions & 12 deletions src/Admin/src/Form/EditAdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Submit;
use Laminas\Form\Element\Text;
use Laminas\Form\Exception\ExceptionInterface;
use Laminas\Session\Container;

/**
Expand All @@ -24,6 +25,7 @@ class EditAdminForm extends AbstractForm
{
/**
* @param array<non-empty-string, mixed> $options
* @throws ExceptionInterface
*/
public function __construct(?string $name = null, array $options = [])
{
Expand All @@ -41,16 +43,20 @@ public function __construct(?string $name = null, array $options = [])

/**
* @phpstan-param SelectDataType[] $roles
* @throws ExceptionInterface
*/
public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
return $this->add(
(new MultiCheckbox('roles'))
->setLabel('Select at least one role')
->setValueOptions($roles)
);
$checkbox = new MultiCheckbox('roles');
$checkbox->setLabel('Select at least one role');
$checkbox->setValueOptions($roles);
$this->add($checkbox);
return $this;
}

/**
* @throws ExceptionInterface
*/
public function init(): void
{
$this->add(
Expand All @@ -69,12 +75,13 @@ public function init(): void
(new Text('lastName'))
->setLabel('Lastname')
);
$this->add(
(new Select('status'))
->setLabel('Account status')
->setValueOptions(AdminStatusEnum::toArray())
->setAttribute('required', true)
);

$select = new Select('status');
$select->setLabel('Account status');
$select->setValueOptions(AdminStatusEnum::toArray());
$select->setAttribute('required', true);
$this->add($select);

$this->add(
(new Csrf('adminEditCsrf'))
->setOptions([
Expand Down
17 changes: 10 additions & 7 deletions src/Admin/src/Handler/Admin/GetEditAdminFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Form\Exception\ExceptionInterface;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -46,6 +47,9 @@ public function __construct(
) {
}

/**
* @throws ExceptionInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
try {
Expand All @@ -59,7 +63,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
/** @var AdminRole[] $adminRoles */
$adminRoles = $this->adminRoleService->getAdminRoleRepository()->findAll();
$adminRoles = array_map(
/** @return SelectDataType */
/** @return SelectDataType */
fn (AdminRole $adminRole): array => [
'label' => $adminRole->getName()->value,
'value' => $adminRole->getUuid()->toString(),
Expand All @@ -68,12 +72,11 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$adminRoles
);

$this->editAdminForm
->setAttribute(
'action',
$this->router->generateUri('admin::edit-admin', ['uuid' => $admin->getUuid()->toString()])
)
->bind($admin)
$this->editAdminForm->setAttribute(
'action',
$this->router->generateUri('admin::edit-admin', ['uuid' => $admin->getUuid()->toString()])
);
$this->editAdminForm->bind($admin)
->setRoles($adminRoles);

return new HtmlResponse(
Expand Down
17 changes: 10 additions & 7 deletions src/Admin/src/Handler/Admin/PostEditAdminHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Form\Exception\ExceptionInterface;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -55,6 +56,9 @@ public function __construct(
) {
}

/**
* @throws ExceptionInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
try {
Expand All @@ -68,7 +72,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
/** @var AdminRole[] $adminRoles */
$adminRoles = $this->adminRoleService->getAdminRoleRepository()->findAll();
$adminRoles = array_map(
/** @return SelectDataType */
/** @return SelectDataType */
fn (AdminRole $adminRole): array => [
'label' => $adminRole->getName()->value,
'value' => $adminRole->getUuid()->toString(),
Expand All @@ -77,12 +81,11 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$adminRoles
);

$this->editAdminForm
->setAttribute(
'action',
$this->router->generateUri('admin::edit-admin', ['uuid' => $admin->getUuid()->toString()])
)
->setRoles($adminRoles);
$this->editAdminForm->setAttribute(
'action',
$this->router->generateUri('admin::edit-admin', ['uuid' => $admin->getUuid()->toString()])
);
$this->editAdminForm->setRoles($adminRoles);

try {
/** @var iterable<array<string, string|string[]>> $data */
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function saveAdmin(array $data, ?Admin $admin = null): Admin
if (array_key_exists('identity', $data) && $data['identity'] !== null && ! $admin->hasIdentity()) {
$admin->setIdentity($data['identity']);
}
if (array_key_exists('password', $data) && $data['password'] !== null) {
if (array_key_exists('password', $data) && $data['password'] !== null && $data['password'] !== '') {
$admin->usePassword($data['password']);
}
if (array_key_exists('firstName', $data) && $data['firstName'] !== null) {
Expand Down
29 changes: 18 additions & 11 deletions src/User/src/Form/CreateUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Submit;
use Laminas\Form\Element\Text;
use Laminas\Form\Exception\ExceptionInterface;
use Laminas\Form\Fieldset;
use Laminas\Session\Container;

Expand All @@ -26,6 +27,7 @@ class CreateUserForm extends AbstractForm
{
/**
* @param array<non-empty-string, mixed> $options
* @throws ExceptionInterface
*/
public function __construct(?string $name = null, array $options = [])
{
Expand All @@ -43,16 +45,20 @@ public function __construct(?string $name = null, array $options = [])

/**
* @phpstan-param SelectDataType[] $roles
* @throws ExceptionInterface
*/
public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
return $this->add(
(new MultiCheckbox('roles'))
->setLabel('Select at least one role')
->setValueOptions($roles)
);
$checkbox = new MultiCheckbox('roles');
$checkbox->setLabel('Select at least one role');
$checkbox->setValueOptions($roles);
$this->add($checkbox);
return $this;
}

/**
* @throws ExceptionInterface
*/
public function init(): void
{
$this
Expand All @@ -68,11 +74,6 @@ public function init(): void
(new Password('passwordConfirm'))
->setLabel('Password confirm')
->setAttribute('required', true)
)->add(
(new Select('status'))
->setLabel('Account status')
->setValueOptions(UserStatusEnum::toArray())
->setAttribute('required', true)
)->add(
(new Csrf('userCreateCsrf'))
->setOptions([
Expand Down Expand Up @@ -100,5 +101,11 @@ public function init(): void
->setAttribute('required', true)
)
);

$select = new Select('status');
$select->setLabel('Account status');
$select->setValueOptions(UserStatusEnum::toArray());
$select->setAttribute('required', true);
$this->add($select);
}
}
29 changes: 18 additions & 11 deletions src/User/src/Form/EditUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Submit;
use Laminas\Form\Element\Text;
use Laminas\Form\Exception\ExceptionInterface;
use Laminas\Form\Fieldset;
use Laminas\Session\Container;

Expand All @@ -26,6 +27,7 @@ class EditUserForm extends AbstractForm
{
/**
* @param array<non-empty-string, mixed> $options
* @throws ExceptionInterface
*/
public function __construct(?string $name = null, array $options = [])
{
Expand All @@ -43,16 +45,20 @@ public function __construct(?string $name = null, array $options = [])

/**
* @phpstan-param SelectDataType[] $roles
* @throws ExceptionInterface
*/
public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
return $this->add(
(new MultiCheckbox('roles'))
->setLabel('Select at least one role')
->setValueOptions($roles)
);
$checkbox = new MultiCheckbox('roles');
$checkbox->setLabel('Select at least one role');
$checkbox->setValueOptions($roles);
$this->add($checkbox);
return $this;
}

/**
* @throws ExceptionInterface
*/
public function init(): void
{
$this
Expand All @@ -62,11 +68,6 @@ public function init(): void
)->add(
(new Password('passwordConfirm'))
->setLabel('Password confirm')
)->add(
(new Select('status'))
->setLabel('Account status')
->setValueOptions(UserStatusEnum::toArray())
->setAttribute('required', true)
)->add(
(new Csrf('userEditCsrf'))
->setOptions([
Expand All @@ -93,5 +94,11 @@ public function init(): void
->setLabel('Email')
)
);

$select = new Select('status');
$select->setLabel('Account status');
$select->setValueOptions(UserStatusEnum::toArray());
$select->setAttribute('required', true);
$this->add($select);
}
}
10 changes: 7 additions & 3 deletions src/User/src/Handler/GetEditUserFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Form\Exception\ExceptionInterface;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -51,6 +52,9 @@ public function __construct(
) {
}

/**
* @throws ExceptionInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
try {
Expand All @@ -64,7 +68,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
/** @var UserRole[] $userRoles */
$userRoles = $this->userRoleService->getUserRoleRepository()->findAll();
$userRoles = array_map(
/** @return SelectDataType */
/** @return SelectDataType */
fn (UserRole $userRole): array => [
'label' => $userRole->getName()->value,
'value' => $userRole->getUuid()->toString(),
Expand All @@ -84,8 +88,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
->setAttribute(
'action',
$this->router->generateUri('user::edit-user', ['uuid' => $user->getUuid()->toString()])
)
->bind($user)
);
$this->editUserForm->bind($user)
->setRoles($userRoles);

return new HtmlResponse(
Expand Down
Loading