protected function processField($field) { switch ($name = $field->getName()) { case 'password': if (0 < strlen(trim($this->form->getValue('password')))) { $this->resource->setPassword($this->form->getValue('password')); } break; case 'confirmPassword': // Don't do anything for confirmPassword break; case 'groups': $newGroupIds = $formGroupIds = array(); if (null != ($groups = $this->form->getValue('groups'))) { foreach ($groups as $item) { $newGroupIds[$item] = $formGroupIds[$item] = $item; } } else { $newGroupIds = $formGroupIds = array(); } // Don't re-add existing groups + delete exiting groups that are no longer // in groups list foreach ($this->resource->aclUserGroups as $item) { if (in_array($item->groupId, $formGroupIds)) { unset($newGroupIds[$item->groupId]); } else { $item->delete(); } } foreach ($newGroupIds as $item) { $userGroup = new QubitAclUserGroup(); $userGroup->groupId = $item; $this->resource->aclUserGroups[] = $userGroup; } break; case 'translate': $languages = $this->form->getValue('translate'); $criteria = new Criteria(); $criteria->add(QubitAclPermission::USER_ID, $this->resource->id); $criteria->addAnd(QubitAclPermission::USER_ID, null, Criteria::ISNOTNULL); $criteria->add(QubitAclPermission::ACTION, 'translate'); if (null === ($permission = QubitAclPermission::getOne($criteria))) { $permission = new QubitAclPermission(); $permission->userId = $this->resource->id; $permission->action = 'translate'; $permission->grantDeny = 1; $permission->conditional = 'in_array(%p[language], %k[languages])'; } else { if (!is_array($languages)) { // If $languages is not an array, then remove the translate permission $permission->delete(); } } if (is_array($languages)) { $permission->setConstants(array('languages' => $languages)); $permission->save(); } break; default: $this->resource[$name] = $this->form->getValue($name); } }