function LayoutBuilderOverridesPermissions::permissions

Same name in other branches
  1. 9 core/modules/layout_builder/src/LayoutBuilderOverridesPermissions.php \Drupal\layout_builder\LayoutBuilderOverridesPermissions::permissions()
  2. 8.9.x core/modules/layout_builder/src/LayoutBuilderOverridesPermissions.php \Drupal\layout_builder\LayoutBuilderOverridesPermissions::permissions()
  3. 10 core/modules/layout_builder/src/LayoutBuilderOverridesPermissions.php \Drupal\layout_builder\LayoutBuilderOverridesPermissions::permissions()

Returns an array of permissions.

Return value

string[][] An array whose keys are permission names and whose corresponding values are defined in \Drupal\user\PermissionHandlerInterface::getPermissions().

1 string reference to 'LayoutBuilderOverridesPermissions::permissions'
layout_builder.permissions.yml in core/modules/layout_builder/layout_builder.permissions.yml
core/modules/layout_builder/layout_builder.permissions.yml

File

core/modules/layout_builder/src/LayoutBuilderOverridesPermissions.php, line 67

Class

LayoutBuilderOverridesPermissions
Provides dynamic permissions for Layout Builder overrides.

Namespace

Drupal\layout_builder

Code

public function permissions() {
    $permissions = [];
    
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $entity_displays */
    $entity_displays = $this->entityTypeManager
        ->getStorage('entity_view_display')
        ->loadByProperties([
        'third_party_settings.layout_builder.allow_custom' => TRUE,
    ]);
    foreach ($entity_displays as $entity_display) {
        $entity_type_id = $entity_display->getTargetEntityTypeId();
        $entity_type = $this->entityTypeManager
            ->getDefinition($entity_type_id);
        $bundle = $entity_display->getTargetBundle();
        $args = [
            '%entity_type' => $entity_type->getCollectionLabel(),
            '@entity_type_singular' => $entity_type->getSingularLabel(),
            '@entity_type_plural' => $entity_type->getPluralLabel(),
            '%bundle' => $this->bundleInfo
                ->getBundleInfo($entity_type_id)[$bundle]['label'],
        ];
        // These permissions are generated on behalf of $entity_display entity
        // display, therefore add this entity display as a config dependency.
        $dependencies = [
            $entity_display->getConfigDependencyKey() => [
                $entity_display->getConfigDependencyName(),
            ],
        ];
        if ($entity_type->hasKey('bundle')) {
            $permissions["configure all {$bundle} {$entity_type_id} layout overrides"] = [
                'title' => $this->t('%entity_type - %bundle: Configure all layout overrides', $args),
                'warning' => $this->t('Warning: Allows configuring the layout even if the user cannot edit the @entity_type_singular itself.', $args),
                'dependencies' => $dependencies,
            ];
            $permissions["configure editable {$bundle} {$entity_type_id} layout overrides"] = [
                'title' => $this->t('%entity_type - %bundle: Configure layout overrides for @entity_type_plural that the user can edit', $args),
                'dependencies' => $dependencies,
            ];
        }
        else {
            $permissions["configure all {$bundle} {$entity_type_id} layout overrides"] = [
                'title' => $this->t('%entity_type: Configure all layout overrides', $args),
                'warning' => $this->t('Warning: Allows configuring the layout even if the user cannot edit the @entity_type_singular itself.', $args),
                'dependencies' => $dependencies,
            ];
            $permissions["configure editable {$bundle} {$entity_type_id} layout overrides"] = [
                'title' => $this->t('%entity_type: Configure layout overrides for @entity_type_plural that the user can edit', $args),
                'dependencies' => $dependencies,
            ];
        }
    }
    return $permissions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.