diff --git a/src/Controllers/PermissionsController.php b/src/Controllers/PermissionsController.php index 53c04a7f..864fefe3 100644 --- a/src/Controllers/PermissionsController.php +++ b/src/Controllers/PermissionsController.php @@ -1,5 +1,4 @@ view->setTemplateBefore('private'); + //default select option value + $selectedOption = 0; if ($this->request->isPost()) { - $profile = Profiles::findFirstById($this->request->getPost('profileId')); + $selectedOption = $this->request->getPost('profileId'); + $profile = Profiles::findFirstById($selectedOption); if ($profile) { if ($this->request->hasPost('permissions') && $this->request->hasPost('submit')) { // Deletes the current permissions - $profile->getPermissions()->delete(); + $profile->getPermissions() + ->delete() + ; // Save the new permissions foreach ($this->request->getPost('permissions') as $permission) { @@ -69,30 +75,23 @@ public function indexAction(): void ], ]); - $escaper = new Escaper(); - $helper = new Select($escaper); - $options = [ 'id' => 'profileId', 'name' => 'profileId', 'class' => 'form-control mr-sm-2' ]; - - $profilesSelect = $helper(' ', PHP_EOL, $options); - $profilesSelect - ->addPlaceholder( - '...', - "0", - [], - true, - ) - ->selected(strval($profile->id)) + + $select = $this + ->tag + ->inputSelect(' ', PHP_EOL, $options) + ->addPlaceholder('...', '', [], true) + ->selected((string) $selectedOption) ; foreach ($profiles as $profile) { - $profilesSelect->add($profile->name, strval($profile->id)); + $select->add($profile->name, (string) $profile->id); } - $this->view->setVar('profilesSelect', $profilesSelect); + $this->view->setVar('profilesSelect', $select); } }