You are here

TaxonomyViewsIntegratorPermissions.php in Taxonomy Views Integrator 8

Namespace

Drupal\tvi

File

src/TaxonomyViewsIntegratorPermissions.php
View source
<?php

namespace Drupal\tvi;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Permissions generator for TVI.
 */
class TaxonomyViewsIntegratorPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a TaxonomyViewsIntegratorPermissions 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'));
  }

  /**
   * Get permissions for Taxonomy Views Integrator.
   *
   * @return array
   *   Permissions array.
   */
  public function permissions() {
    $permissions = [];
    foreach ($this->entityTypeManager
      ->getStorage('taxonomy_vocabulary')
      ->loadMultiple() as $vocabulary) {
      $permissions += [
        'define view for vocabulary ' . $vocabulary
          ->id() => [
          'title' => $this
            ->t('Define the view override for the vocabulary %vocabulary', [
            '%vocabulary' => $vocabulary
              ->label(),
          ]),
        ],
      ];
      $permissions += [
        'define view for terms in ' . $vocabulary
          ->id() => [
          'title' => $this
            ->t('Define the view override for terms in %vocabulary', [
            '%vocabulary' => $vocabulary
              ->label(),
          ]),
        ],
      ];
    }
    return $permissions;
  }

}

Classes

Namesort descending Description
TaxonomyViewsIntegratorPermissions Permissions generator for TVI.