Permissions: Allow to set restrictions too

This commit is contained in:
Eric Lippmann 2014-11-20 15:54:00 +01:00
parent 55d6a96fdc
commit e67d937642
1 changed files with 18 additions and 8 deletions

View File

@ -42,7 +42,7 @@ class RoleForm extends ConfigForm
} }
foreach ($module->getProvidedRestrictions() as $restriction) { foreach ($module->getProvidedRestrictions() as $restriction) {
/** @var object $restriction */ /** @var object $restriction */
$this->providedRestrictions[$restriction->name] = $restriction->name . ': ' . $restriction->description; $this->providedRestrictions[$restriction->name] = $restriction->description;
} }
} }
} }
@ -60,7 +60,8 @@ class RoleForm extends ConfigForm
array( array(
'required' => true, 'required' => true,
'label' => t('Role Name'), 'label' => t('Role Name'),
'description' => t('The name of the role') 'description' => t('The name of the role'),
'ignore' => true
), ),
), ),
array( array(
@ -89,6 +90,16 @@ class RoleForm extends ConfigForm
) )
) )
)); ));
foreach ($this->providedRestrictions as $name => $description) {
$this->addElement(
'text',
$name,
array(
'label' => $name,
'description' => $description
)
);
}
return $this; return $this;
} }
@ -215,11 +226,10 @@ class RoleForm extends ConfigForm
*/ */
public function getValues($suppressArrayNotation = false) public function getValues($suppressArrayNotation = false)
{ {
$permissions = $this->getElement('permissions')->getValue(); $values = array_filter(parent::getValues($suppressArrayNotation));
return array( if (isset($values['permissions'])) {
'users' => $this->getElement('users')->getValue(), $values['permissions'] = implode(', ', $values['permissions']);
'groups' => $this->getElement('groups')->getValue(), }
'permissions' => ! empty($permissions) ? implode(', ', $permissions) : null return $values;
);
} }
} }