Skip to content
Snippets Groups Projects

Issue #3350210: Enable the Manage Permissions tab

3 unresolved threads
2 files
+ 16
27
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -2,6 +2,7 @@
namespace Drupal\paragraphs_type_permissions;
use Drupal\Core\Entity\BundlePermissionHandlerTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\paragraphs\Entity\ParagraphsType;
@@ -10,6 +11,7 @@ use Drupal\paragraphs\Entity\ParagraphsType;
*/
class ParagraphsTypePermissions {
use BundlePermissionHandlerTrait;
use StringTranslationTrait;
/**
@@ -18,12 +20,12 @@ class ParagraphsTypePermissions {
* @return array
*/
public function globalPermissions() {
return array(
'bypass paragraphs type content access' => array(
return [
'bypass paragraphs type content access' => [
'title' => $this->t('Bypass Paragraphs type content access control'),
'description' => $this->t('Is able to administer content for all Paragraph types'),
),
);
],
];
}
/**
@@ -32,14 +34,10 @@ class ParagraphsTypePermissions {
* @return array
*/
public function paragraphTypePermissions() {
$perms = array();
// Generate paragraph permissions for all Paragraphs types.
foreach (ParagraphsType::loadMultiple() as $type) {
$perms += $this->buildPermissions($type);
}
return $perms;
return $this->generatePermissions(ParagraphsType::loadMultiple(), [
$this,
'buildPermissions',
]);
}
/**
@@ -53,37 +51,27 @@ class ParagraphsTypePermissions {
*/
protected function buildPermissions(ParagraphsType $type) {
$type_id = $type->id();
$type_params = array('%type_name' => $type->label());
$type_params = ['%type_name' => $type->label()];
$permissions = [
'view paragraph content ' .$type_id => [
"view paragraph content $type_id" => [
'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 => [
"create paragraph content $type_id" => [
'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 => [
"update paragraph content $type_id" => [
'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 => [
"delete paragraph content $type_id" => [
'title' => $this->t('%type_name: Delete content', $type_params),
'description' => $this->t('Is able to delete Paragraphs content of type %type_name', $type_params),
],
];
// Add permissions dependency.
$dependencies = [
'config' => [
"paragraphs.paragraphs_type.{$type_id}",
],
];
foreach ($permissions as &$permission) {
$permission['dependencies'] = $dependencies;
}
return $permissions;
}
Loading