/** * Remove a role */ public function removeAction() { $this->assertPermission('config/authentication/roles/remove'); $name = $this->params->getRequired('role'); $role = new RoleForm(); try { $role->setIniConfig(Config::app('roles', true))->load($name); } catch (NotFoundError $e) { $this->httpNotFound($e->getMessage()); } $confirmation = new ConfirmRemovalForm(array('onSuccess' => function (ConfirmRemovalForm $confirmation) use($name, $role) { try { $role->remove($name); } catch (NotFoundError $e) { Notification::error($e->getMessage()); return false; } if ($role->save()) { Notification::success(t('Role removed')); return true; } return false; })); $confirmation->setSubmitLabel($this->translate('Remove Role'))->setRedirectUrl('role/list')->handleRequest(); $this->renderForm($confirmation, $this->translate('Remove Role')); }
/** * Remove a role * * @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist */ public function removeAction() { $this->assertPermission('config/authentication/roles/remove'); $name = $this->_request->getParam('role'); if (empty($name)) { throw new Zend_Controller_Action_Exception(sprintf($this->translate('Required parameter \'%s\' missing'), 'role'), 400); } $role = new RoleForm(); try { $role->setIniConfig(Config::app('roles', true))->load($name); } catch (InvalidArgumentException $e) { throw new Zend_Controller_Action_Exception($e->getMessage(), 400); } $confirmation = new ConfirmRemovalForm(array('onSuccess' => function (ConfirmRemovalForm $confirmation) use($name, $role) { try { $role->remove($name); } catch (InvalidArgumentException $e) { Notification::error($e->getMessage()); return false; } if ($role->save()) { Notification::success(t('Role removed')); return true; } return false; })); $confirmation->setTitle(sprintf($this->translate('Remove Role %s'), $name))->setSubmitLabel($this->translate('Remove Role'))->setRedirectUrl('role/list')->handleRequest(); $this->view->form = $confirmation; $this->render('form'); }