Chris@5: entityTypeManager = $entity_type_manager; Chris@5: $this->bundleInfo = $bundle_info; Chris@5: } Chris@5: Chris@5: /** Chris@5: * {@inheritdoc} Chris@5: */ Chris@5: public static function create(ContainerInterface $container) { Chris@5: return new static( Chris@5: $container->get('entity_type.manager'), Chris@5: $container->get('entity_type.bundle.info') Chris@5: ); Chris@5: } Chris@5: Chris@5: /** Chris@5: * Returns an array of permissions. Chris@5: * Chris@5: * @return string[][] Chris@5: * An array whose keys are permission names and whose corresponding values Chris@5: * are defined in \Drupal\user\PermissionHandlerInterface::getPermissions(). Chris@5: */ Chris@5: public function permissions() { Chris@5: $permissions = []; Chris@5: Chris@5: /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $entity_displays */ Chris@5: $entity_displays = $this->entityTypeManager->getStorage('entity_view_display')->loadByProperties(['third_party_settings.layout_builder.allow_custom' => TRUE]); Chris@5: foreach ($entity_displays as $entity_display) { Chris@5: $entity_type_id = $entity_display->getTargetEntityTypeId(); Chris@5: $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); Chris@5: $bundle = $entity_display->getTargetBundle(); Chris@5: $args = [ Chris@5: '%entity_type' => $entity_type->getCollectionLabel(), Chris@5: '@entity_type_singular' => $entity_type->getSingularLabel(), Chris@5: '@entity_type_plural' => $entity_type->getPluralLabel(), Chris@5: '%bundle' => $this->bundleInfo->getBundleInfo($entity_type_id)[$bundle]['label'], Chris@5: ]; Chris@5: if ($entity_type->hasKey('bundle')) { Chris@5: $permissions["configure all $bundle $entity_type_id layout overrides"] = [ Chris@5: 'title' => $this->t('%entity_type - %bundle: Configure all layout overrides', $args), Chris@5: 'warning' => $this->t('Warning: Allows configuring the layout even if the user cannot edit the @entity_type_singular itself.', $args), Chris@5: ]; Chris@5: $permissions["configure editable $bundle $entity_type_id layout overrides"] = [ Chris@5: 'title' => $this->t('%entity_type - %bundle: Configure layout overrides for @entity_type_plural that the user can edit', $args), Chris@5: ]; Chris@5: } Chris@5: else { Chris@5: $permissions["configure all $bundle $entity_type_id layout overrides"] = [ Chris@5: 'title' => $this->t('%entity_type: Configure all layout overrides', $args), Chris@5: 'warning' => $this->t('Warning: Allows configuring the layout even if the user cannot edit the @entity_type_singular itself.', $args), Chris@5: ]; Chris@5: $permissions["configure editable $bundle $entity_type_id layout overrides"] = [ Chris@5: 'title' => $this->t('%entity_type: Configure layout overrides for @entity_type_plural that the user can edit', $args), Chris@5: ]; Chris@5: } Chris@5: } Chris@5: return $permissions; Chris@5: } Chris@5: Chris@5: }