You are here

class FieldPermissions in Voting API Reaction 8

Field permissions.

Hierarchy

Expanded class hierarchy of FieldPermissions

File

src/FieldPermissions.php, line 13

Namespace

Drupal\votingapi_reaction
View source
class FieldPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * Entity field manager service.
   *
   * @var \Drupal\Core\Entity\EntityFieldManager
   */
  protected $fieldManager;

  /**
   * Constructs a FieldPermissionsService instance.
   *
   * @param \Drupal\Core\Entity\EntityFieldManager $fieldManager
   *   Entity field manager service.
   */
  public function __construct(EntityFieldManager $fieldManager) {
    $this->fieldManager = $fieldManager;
  }

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

  /**
   * Get implemets permissions invoke in field_permissions.permissions.yml.
   *
   * @return array
   *   Add custom permissions.
   */
  public function permissions() {
    $map = $this->fieldManager
      ->getFieldMapByFieldType('votingapi_reaction');
    $permissions = [];
    foreach ($map as $entity_type => $info) {
      foreach ($info as $field_name => $field_info) {
        foreach ($field_info['bundles'] as $bundle) {
          $permissions['view reactions on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
            'title' => $this
              ->t('View reactions to field %field in bundle %bundle of entity type %type', [
              '%type' => $entity_type,
              '%bundle' => $bundle,
              '%field' => $field_name,
            ]),
          ];
          $permissions['create reaction on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
            'title' => $this
              ->t('React to field %field in bundle %bundle of entity type %type', [
              '%type' => $entity_type,
              '%bundle' => $bundle,
              '%field' => $field_name,
            ]),
          ];
          $permissions['modify reaction on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
            'title' => $this
              ->t('Modify reaction to field %field in bundle %bundle of entity type %type', [
              '%type' => $entity_type,
              '%bundle' => $bundle,
              '%field' => $field_name,
            ]),
          ];
          $permissions['control reaction status on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
            'title' => $this
              ->t('Conrol reactions status in field %field in bundle %bundle of entity type %type', [
              '%type' => $entity_type,
              '%bundle' => $bundle,
              '%field' => $field_name,
            ]),
          ];
        }
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldPermissions::$fieldManager protected property Entity field manager service.
FieldPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FieldPermissions::permissions public function Get implemets permissions invoke in field_permissions.permissions.yml.
FieldPermissions::__construct public function Constructs a FieldPermissionsService 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.