Example #1
0
 /**
  * Update a role
  *
  * @TODO(el): Rename to updateAction()
  */
 public function editAction()
 {
     $this->assertPermission('config/authentication/roles/edit');
     $name = $this->params->getRequired('role');
     $role = new RoleForm();
     $role->setSubmitLabel($this->translate('Update Role'));
     try {
         $role->setIniConfig(Config::app('roles', true))->load($name);
     } catch (NotFoundError $e) {
         $this->httpNotFound($e->getMessage());
     }
     $role->setOnSuccess(function (RoleForm $role) use($name) {
         $oldName = $name;
         $name = $role->getElement('name')->getValue();
         $values = $role->getValues();
         try {
             $role->update($name, $values, $oldName);
         } catch (NotFoundError $e) {
             $role->addError($e->getMessage());
             return false;
         }
         if ($role->save()) {
             Notification::success(t('Role updated'));
             return true;
         }
         return false;
     })->setRedirectUrl('role/list')->handleRequest();
     $this->renderForm($role, $this->translate('Update Role'));
 }
Example #2
0
 /**
  * Update a role
  *
  * @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist
  */
 public function editAction()
 {
     $this->assertPermission('config/authentication/roles/edit');
     $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();
     $role->setTitle(sprintf($this->translate('Update Role %s'), $name));
     $role->setSubmitLabel($this->translate('Update Role'));
     try {
         $role->setIniConfig(Config::app('roles', true))->load($name);
     } catch (InvalidArgumentException $e) {
         throw new Zend_Controller_Action_Exception($e->getMessage(), 400);
     }
     $role->setOnSuccess(function (RoleForm $role) use($name) {
         $oldName = $name;
         $name = $role->getElement('name')->getValue();
         $values = $role->getValues();
         try {
             $role->update($name, $values, $oldName);
         } catch (InvalidArgumentException $e) {
             $role->addError($e->getMessage());
             return false;
         }
         if ($role->save()) {
             Notification::success(t('Role updated'));
             return true;
         }
         return false;
     })->setRedirectUrl('role/list')->handleRequest();
     $this->view->form = $role;
     $this->render('form');
 }