You are here

class ExtrasPermissions in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 modules/ds_extras/src/ExtrasPermissions.php \Drupal\ds_extras\ExtrasPermissions
  2. 8.3 modules/ds_extras/src/ExtrasPermissions.php \Drupal\ds_extras\ExtrasPermissions

Provides dynamic permissions of the ds extras module.

Hierarchy

Expanded class hierarchy of ExtrasPermissions

File

modules/ds_extras/src/ExtrasPermissions.php, line 14

Namespace

Drupal\ds_extras
View source
class ExtrasPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity 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 ds extras permissions.
   */
  public function extrasPermissions() {
    $permissions = [];
    if (\Drupal::config('ds_extras.settings')
      ->get('field_permissions')) {
      $entities = $this->entityTypeManager
        ->getDefinitions();
      foreach ($entities as $entity_type => $info) {

        // @todo do this on all fields ?
        // @todo hide switch field if enabled
        $fields = Ds::getFields($entity_type);
        foreach ($fields as $key => $finfo) {
          $permissions['view ' . $key . ' on ' . $entity_type] = [
            'title' => $this
              ->t('View @field on @entity_type', [
              '@field' => $finfo['title'],
              '@entity_type' => $info
                ->getLabel(),
            ]),
          ];
        }
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExtrasPermissions::$entityTypeManager protected property The entity manager.
ExtrasPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ExtrasPermissions::extrasPermissions public function Returns an array of ds extras permissions.
ExtrasPermissions::__construct public function Constructs a new FieldUiPermissions instance.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.