3 namespace Drupal\paragraphs_type_permissions;
5 use Drupal\Core\Routing\UrlGeneratorTrait;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7 use Drupal\paragraphs\Entity\ParagraphsType;
10 * Defines a class containing permission callbacks.
12 class ParagraphsTypePermissions {
14 use StringTranslationTrait;
15 use UrlGeneratorTrait;
18 * Returns an array of content permissions.
22 public function globalPermissions() {
24 'bypass paragraphs type content access' => array(
25 'title' => $this->t('Bypass paragraphs type content access control'),
26 'description' => $this->t('Is able to administer content for all paragraph types'),
32 * Returns an array of paragraphs type permissions.
36 public function paragraphTypePermissions() {
39 // Generate paragraph permissions for all paragraphs types.
40 foreach (ParagraphsType::loadMultiple() as $type) {
41 $perms += $this->buildPermissions($type);
48 * Builds a standard list of node permissions for a given type.
50 * @param \Drupal\paragraphs\Entity\ParagraphsType $type
51 * The machine name of the node type.
54 * An array of permission names and descriptions.
56 protected function buildPermissions(ParagraphsType $type) {
57 $type_id = $type->id();
58 $type_params = array('%type_name' => $type->label());
61 'view paragraph content ' .$type_id => array(
62 'title' => $this->t('%type_name: View content', $type_params),
63 'description' => $this->t('Is able to view paragraphs content of type %type_name', $type_params),
65 'create paragraph content ' . $type_id => array(
66 'title' => $this->t('%type_name: Create content', $type_params),
67 'description' => $this->t('Is able to create paragraphs content of type %type_name', $type_params),
69 'update paragraph content ' . $type_id => array(
70 'title' => $this->t('%type_name: Edit content', $type_params),
71 'description' => $this->t('Is able to update paragraphs content of type %type_name', $type_params),
73 'delete paragraph content ' . $type_id => array(
74 'title' => $this->t('%type_name: Delete content', $type_params),
75 'description' => $this->t('Is able to delete paragraphs content of type %type_name', $type_params),