View source
<?php
namespace Drupal\block_access;
use Drupal\block_content\BlockContentTypeInterface;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class Permissions {
use StringTranslationTrait;
public function get() {
$permissions = [];
foreach (BlockContentType::loadMultiple() as $type) {
$permissions += $this
->buildPermissions($type);
}
return $permissions;
}
protected function buildPermissions(BlockContentTypeInterface $type) {
$type_id = $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"create {$type_id} block_content" => [
'title' => $this
->t('%type_name: Create new block content', $type_params),
],
"update own {$type_id} block_content" => [
'title' => $this
->t('%type_name: Edit own block content', $type_params),
],
"update any {$type_id} block_content" => [
'title' => $this
->t('%type_name: Edit any block content', $type_params),
],
"delete own {$type_id} block_content" => [
'title' => $this
->t('%type_name: Delete own block content', $type_params),
],
"delete any {$type_id} block_content" => [
'title' => $this
->t('%type_name: Delete any block content', $type_params),
],
];
}
}