<?php
namespace Drupal\paragraphs_type_permissions;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\paragraphs\Entity\ParagraphsType;
class ParagraphsTypePermissions {
use StringTranslationTrait;
public function globalPermissions() {
return array(
'bypass paragraphs type content access' => array(
'title' => $this
->t('Bypass Paragraphs type content access control'),
'description' => $this
->t('Is able to administer content for all Paragraph types'),
),
);
}
public function paragraphTypePermissions() {
$perms = array();
foreach (ParagraphsType::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
protected function buildPermissions(ParagraphsType $type) {
$type_id = $type
->id();
$type_params = array(
'%type_name' => $type
->label(),
);
return array(
'view paragraph content ' . $type_id => array(
'title' => $this
->t('%type_name: View content', $type_params),
'description' => $this
->t('Is able to view Paragraphs content of type %type_name', $type_params),
),
'create paragraph content ' . $type_id => array(
'title' => $this
->t('%type_name: Create content', $type_params),
'description' => $this
->t('Is able to create Paragraphs content of type %type_name', $type_params),
),
'update paragraph content ' . $type_id => array(
'title' => $this
->t('%type_name: Edit content', $type_params),
'description' => $this
->t('Is able to update Paragraphs content of type %type_name', $type_params),
),
'delete paragraph content ' . $type_id => array(
'title' => $this
->t('%type_name: Delete content', $type_params),
'description' => $this
->t('Is able to delete Paragraphs content of type %type_name', $type_params),
),
);
}
}