X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FEntityPermissionProviderBase.php;fp=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FEntityPermissionProviderBase.php;h=0000000000000000000000000000000000000000;hb=059867c3f96750652c80f39e44c442a58c2549ee;hp=53d83f8ac97252879c64b2a44fc45533bb09e5d7;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2;p=yaffs-website diff --git a/web/modules/contrib/entity/src/EntityPermissionProviderBase.php b/web/modules/contrib/entity/src/EntityPermissionProviderBase.php deleted file mode 100644 index 53d83f8ac..000000000 --- a/web/modules/contrib/entity/src/EntityPermissionProviderBase.php +++ /dev/null @@ -1,231 +0,0 @@ -entityTypeBundleInfo = $entity_type_bundle_info; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $container->get('entity_type.bundle.info') - ); - } - - /** - * {@inheritdoc} - */ - public function buildPermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - $permissions["administer {$entity_type_id}"] = [ - 'title' => $this->t('Administer @type', ['@type' => $plural_label]), - 'restrict access' => TRUE, - ]; - $permissions["access {$entity_type_id} overview"] = [ - 'title' => $this->t('Access the @type overview page', ['@type' => $plural_label]), - ]; - if ($has_owner && $entity_type->entityClassImplements(EntityPublishedInterface::class)) { - $permissions["view own unpublished {$entity_type_id}"] = [ - 'title' => $this->t('View own unpublished @type', [ - '@type' => $plural_label, - ]), - ]; - } - - // Generate the other permissions based on granularity. - if ($entity_type->getPermissionGranularity() === 'entity_type') { - $permissions += $this->buildEntityTypePermissions($entity_type); - } - else { - $permissions += $this->buildBundlePermissions($entity_type); - } - - return $this->processPermissions($permissions, $entity_type); - } - - /** - * Adds the provider and converts the titles to strings to allow sorting. - * - * @param array $permissions - * The array of permissions - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * An array of processed permissions. - */ - protected function processPermissions(array $permissions, EntityTypeInterface $entity_type) { - foreach ($permissions as $name => $permission) { - // Permissions are grouped by provider on admin/people/permissions. - $permissions[$name]['provider'] = $entity_type->getProvider(); - // TranslatableMarkup objects don't sort properly. - $permissions[$name]['title'] = (string) $permission['title']; - } - return $permissions; - } - - /** - * Builds permissions for the entity_type granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildEntityTypePermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $singular_label = $entity_type->getSingularLabel(); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - $permissions["create {$entity_type_id}"] = [ - 'title' => $this->t('Create @type', [ - '@type' => $plural_label, - ]), - ]; - if ($has_owner) { - $permissions["update any {$entity_type_id}"] = [ - 'title' => $this->t('Update any @type', [ - '@type' => $singular_label, - ]), - ]; - $permissions["update own {$entity_type_id}"] = [ - 'title' => $this->t('Update own @type', [ - '@type' => $plural_label, - ]), - ]; - $permissions["delete any {$entity_type_id}"] = [ - 'title' => $this->t('Delete any @type', [ - '@type' => $singular_label, - ]), - ]; - $permissions["delete own {$entity_type_id}"] = [ - 'title' => $this->t('Delete own @type', [ - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["update {$entity_type_id}"] = [ - 'title' => $this->t('Update @type', [ - '@type' => $plural_label, - ]), - ]; - $permissions["delete {$entity_type_id}"] = [ - 'title' => $this->t('Delete @type', [ - '@type' => $plural_label, - ]), - ]; - } - - return $permissions; - } - - /** - * Builds permissions for the bundle granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildBundlePermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $singular_label = $entity_type->getSingularLabel(); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - foreach ($bundles as $bundle_name => $bundle_info) { - $permissions["create {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Create @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - - if ($has_owner) { - $permissions["update any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $singular_label, - ]), - ]; - $permissions["update own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - $permissions["delete any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $singular_label, - ]), - ]; - $permissions["delete own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["update {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - $permissions["delete {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - } - - return $permissions; - } - -}