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