DomainEntityPermissions.php in Domain Access Entity 8
File
src/DomainEntityPermissions.php
View source
<?php
namespace Drupal\domain_entity;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class DomainEntityPermissions {
use StringTranslationTrait;
public function permissions() {
$permissions = [];
$mapper = \Drupal::service('domain_entity.mapper');
$bundle_info = \Drupal::service('entity_type.bundle.info');
foreach ($mapper
->getEnabledEntityTypes() as $type_id => $entity_type) {
$bundles = $bundle_info
->getBundleInfo($type_id);
if (!empty($bundles)) {
foreach ($bundles as $bundle_id => $bundle) {
$permissions += $this
->bundlePermissions($bundle_id, $bundle['label'], $entity_type
->id(), $entity_type
->getBundleLabel());
}
}
}
return $permissions;
}
private function bundlePermissions($id, $label, $entityTypeId, $entityTypeLabel) {
$perms = [
"create {$id} {$entityTypeId} content on assigned domains" => [
'title' => $this
->t('%entity_type_name: %type_name: Create new content on assigned domains', [
'%type_name' => $label,
'%entity_type_name' => $entityTypeLabel,
]),
],
"update {$id} {$entityTypeId} content on assigned domains" => [
'title' => $this
->t('%entity_type_name: %type_name: Edit any content on assigned domains', [
'%type_name' => $label,
'%entity_type_name' => $entityTypeLabel,
]),
],
"delete {$id} {$entityTypeId} content on assigned domains" => [
'title' => $this
->t('%entity_type_name: %type_name: Delete any content on assigned domains', [
'%type_name' => $label,
'%entity_type_name' => $entityTypeLabel,
]),
],
];
return $perms;
}
}