abstract class Permission in Organic groups 8
Base class for OG permissions.
Hierarchy
- class \Drupal\og\Permission implements PermissionInterface
Expanded class hierarchy of Permission
1 string reference to 'Permission'
- og.schema.yml in config/
schema/ og.schema.yml - config/schema/og.schema.yml
File
- src/
Permission.php, line 10
Namespace
Drupal\ogView source
abstract class Permission implements PermissionInterface {
/**
* The name of the permission.
*
* @var string
*/
protected $name;
/**
* The human readable permission title.
*
* @var string
*/
protected $title;
/**
* A short description of the permission.
*
* @var string
*/
protected $description = '';
/**
* The default roles to which this permission applies.
*
* @var array
*/
protected $defaultRoles = [];
/**
* If the permission is security sensitive and should be limited to admins.
*
* @var bool
*/
protected $restrictAccess = FALSE;
/**
* Constructs a Permission object.
*
* @param array $values
* An associative array of values, keyed by property.
*/
public function __construct(array $values = []) {
foreach ($values as $property => $value) {
$this
->set($property, $value);
}
}
/**
* {@inheritdoc}
*/
public function get($property) {
$property = $this
->lowerCamelize($property);
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException("Invalid property {$property}.");
}
return $this->{$property};
}
/**
* {@inheritdoc}
*/
public function set($property, $value) {
$property = $this
->lowerCamelize($property);
$this
->validate($property, $value);
$this->{$property} = $value;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this
->get('name');
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this
->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this
->get('title');
}
/**
* {@inheritdoc}
*/
public function setTitle($title) {
$this
->set('title', $title);
return $this;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->get('description');
}
/**
* {@inheritdoc}
*/
public function setDescription($description) {
$this
->set('description', $description);
return $this;
}
/**
* {@inheritdoc}
*/
public function getDefaultRoles() {
return $this
->get('default roles');
}
/**
* {@inheritdoc}
*/
public function setDefaultRoles(array $default_roles) {
$this
->set('default roles', $default_roles);
return $this;
}
/**
* {@inheritdoc}
*/
public function getRestrictAccess() {
return $this
->get('restrict access');
}
/**
* {@inheritdoc}
*/
public function setRestrictAccess($access) {
$this
->set('restrict access', $access);
return $this;
}
/**
* Validates the given property and value.
*
* @param string $property
* The property to validate.
* @param mixed $value
* The value to validate.
*/
protected function validate($property, $value) {
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException("Invalid property {$property}.");
}
if ($property === 'restrictAccess' && !is_bool($value)) {
throw new \InvalidArgumentException('The value for the "restrict access" property should be a boolean.');
}
}
/**
* Converts the given string in a lowerCamelCase version.
*
* @param string $string
* The string to convert.
*
* @return string
* The converted string.
*/
protected static function lowerCamelize($string) {
return lcfirst(str_replace(' ', '', ucwords($string)));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Permission:: |
protected | property | The default roles to which this permission applies. | |
Permission:: |
protected | property | A short description of the permission. | |
Permission:: |
protected | property | The name of the permission. | |
Permission:: |
protected | property | If the permission is security sensitive and should be limited to admins. | |
Permission:: |
protected | property | The human readable permission title. | |
Permission:: |
public | function |
Returns the value for the given property. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Returns the default roles. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Returns the description. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Returns the machine name of the permission. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Returns whether or not access is restricted. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Returns the human readable permission title. Overrides PermissionInterface:: |
|
Permission:: |
protected static | function | Converts the given string in a lowerCamelCase version. | |
Permission:: |
public | function |
Sets the value for the given property. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Sets the default roles. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Sets the description. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Sets the machine name of the permission. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Sets the access restriction. Overrides PermissionInterface:: |
|
Permission:: |
public | function |
Sets the human readable permission title. Overrides PermissionInterface:: |
|
Permission:: |
protected | function | Validates the given property and value. | 1 |
Permission:: |
public | function | Constructs a Permission object. |