class NodePermissions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/NodePermissions.php \Drupal\node\NodePermissions
Provides dynamic permissions for nodes of different types.
Hierarchy
- class \Drupal\node\NodePermissions uses UrlGeneratorTrait, StringTranslationTrait
Expanded class hierarchy of NodePermissions
File
- core/
modules/ node/ src/ NodePermissions.php, line 17 - Contains \Drupal\node\NodePermissions.
Namespace
Drupal\nodeView source
class NodePermissions {
use StringTranslationTrait;
use UrlGeneratorTrait;
/**
* Returns an array of node type permissions.
*
* @return array
* The node type permissions.
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function nodeTypePermissions() {
$perms = array();
// Generate node permissions for all node types.
foreach (NodeType::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
/**
* Returns a list of node permissions for a given node type.
*
* @param \Drupal\node\Entity\NodeType $type
* The node type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(NodeType $type) {
$type_id = $type
->id();
$type_params = array(
'%type_name' => $type
->label(),
);
return array(
"create {$type_id} content" => array(
'title' => $this
->t('%type_name: Create new content', $type_params),
),
"edit own {$type_id} content" => array(
'title' => $this
->t('%type_name: Edit own content', $type_params),
),
"edit any {$type_id} content" => array(
'title' => $this
->t('%type_name: Edit any content', $type_params),
),
"delete own {$type_id} content" => array(
'title' => $this
->t('%type_name: Delete own content', $type_params),
),
"delete any {$type_id} content" => array(
'title' => $this
->t('%type_name: Delete any content', $type_params),
),
"view {$type_id} revisions" => array(
'title' => $this
->t('%type_name: View revisions', $type_params),
),
"revert {$type_id} revisions" => array(
'title' => $this
->t('%type_name: Revert revisions', $type_params),
'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for nodes in question, or <em>administer nodes</em>.'),
),
"delete {$type_id} revisions" => array(
'title' => $this
->t('%type_name: Delete revisions', $type_params),
'description' => $this
->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for nodes in question, or <em>administer nodes</em>.'),
),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NodePermissions:: |
protected | function | Returns a list of node permissions for a given node type. | |
NodePermissions:: |
public | function | Returns an array of node type permissions. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |