class FieldUiPermissions in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field_ui/src/FieldUiPermissions.php \Drupal\field_ui\FieldUiPermissions
 
Provides dynamic permissions of the field_ui module.
Hierarchy
- class \Drupal\field_ui\FieldUiPermissions implements ContainerInjectionInterface uses StringTranslationTrait
 
Expanded class hierarchy of FieldUiPermissions
File
- core/
modules/ field_ui/ src/ FieldUiPermissions.php, line 13  
Namespace
Drupal\field_uiView source
class FieldUiPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;
  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;
  /**
   * Constructs a new FieldUiPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'));
  }
  /**
   * Returns an array of field UI permissions.
   *
   * @return array
   */
  public function fieldPermissions() {
    $permissions = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      if ($entity_type
        ->get('field_ui_base_route')) {
        // The permissions depend on the module that provides the entity.
        $dependencies = [
          'module' => [
            $entity_type
              ->getProvider(),
          ],
        ];
        // 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,
          'dependencies' => $dependencies,
        ];
        $permissions['administer ' . $entity_type_id . ' form display'] = [
          'title' => $this
            ->t('%entity_label: Administer form display', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
          'dependencies' => $dependencies,
        ];
        $permissions['administer ' . $entity_type_id . ' display'] = [
          'title' => $this
            ->t('%entity_label: Administer display', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
          'dependencies' => $dependencies,
        ];
      }
    }
    return $permissions;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            FieldUiPermissions:: | 
                  protected | property | The entity type manager. | |
| 
            FieldUiPermissions:: | 
                  public static | function | 
            Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: | 
                  |
| 
            FieldUiPermissions:: | 
                  public | function | Returns an array of field UI permissions. | |
| 
            FieldUiPermissions:: | 
                  public | function | Constructs a new FieldUiPermissions instance. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 4 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |