public function transformContent() { // get the current role id $roleId = $this->getRequest()->getParameter('roleid'); // initialize the form $form = $this->getForm('RoleEdit'); $hidden = $form->getFormElementByName('roleid'); $hidden->setAttribute('value', $roleId); $displayName = $form->getFormElementByName('DisplayName'); $description = $form->getFormElementByName('Description'); $uM = $this->getManager(); // load selected roles to be able to highlight them within the select field $role = $uM->loadRoleByID($roleId); if ($form->isSent()) { if ($form->isValid()) { $displayName = $form->getFormElementByName('DisplayName'); $role = new UmgtRole(); $role->setObjectId($roleId); $role->setDisplayName($displayName->getValue()); $role->setDescription($description->getValue()); $uM->saveRole($role); $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } else { $form->transformOnPlace(); } } else { // pre-fill form $displayName->setValue($role->getDisplayName()); $description->setValue($role->getDescription()); $form->transformOnPlace(); } }
public function transformContent() { $form = $this->getForm('RoleAdd'); /* @var $permissionControl MultiSelectBoxTag */ $permissionControl = $form->getFormElementByName('Permission'); $uM = $this->getManager(); $roles = $uM->getRoleList(); $count = count($roles); // fill multi-select field for ($i = 0; $i < $count; $i++) { $permissionControl->addOption($roles[$i]->getDisplayName(), $roles[$i]->getObjectId()); } if ($form->isSent() && $form->isValid()) { $uM = $this->getManager(); $role = new UmgtRole(); $displayName = $form->getFormElementByName('DisplayName'); $role->setDisplayName($displayName->getValue()); $description = $form->getFormElementByName('Description'); $role->setDescription($description->getValue()); $options = $permissionControl->getSelectedOptions(); for ($i = 0; $i < count($options); $i++) { $newPermission = new UmgtPermission(); $newPermission->setObjectId($options[$i]->getAttribute('value')); $role->addRelatedObject('Role2Permission', $newPermission); unset($newPermission); } $uM->saveRole($role); $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } $form->transformOnPlace(); }