You are here

class FieldUiPermissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/FieldUiPermissions.php \Drupal\field_ui\FieldUiPermissions

Provides dynamic permissions of the field_ui module.

Hierarchy

Expanded class hierarchy of FieldUiPermissions

File

core/modules/field_ui/src/FieldUiPermissions.php, line 18
Contains \Drupal\field_ui\FieldUiPermissions.

Namespace

Drupal\field_ui
View source
class FieldUiPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a new FieldUiPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity.manager'));
  }

  /**
   * Returns an array of field UI permissions.
   *
   * @return array
   */
  public function fieldPermissions() {
    $permissions = [];
    foreach ($this->entityManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      if ($entity_type
        ->get('field_ui_base_route')) {

        // Create a permission for each fieldable entity to manage
        // the fields and the display.
        $permissions['administer ' . $entity_type_id . ' fields'] = [
          'title' => $this
            ->t('%entity_label: Administer fields', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
          'restrict access' => TRUE,
        ];
        $permissions['administer ' . $entity_type_id . ' form display'] = [
          'title' => $this
            ->t('%entity_label: Administer form display', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
        ];
        $permissions['administer ' . $entity_type_id . ' display'] = [
          'title' => $this
            ->t('%entity_label: Administer display', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldUiPermissions::$entityManager protected property The entity manager.
FieldUiPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FieldUiPermissions::fieldPermissions public function Returns an array of field UI permissions.
FieldUiPermissions::__construct public function Constructs a new FieldUiPermissions instance.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.