drupalorg-1.0.x-dev/src/ExtraPermissions.php

src/ExtraPermissions.php
<?php

namespace Drupal\drupalorg;

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

/**
 * Provides dynamic permissions of the drupalorg module.
 */
class ExtraPermissions implements ContainerInjectionInterface {

  use StringTranslationTrait;

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

  /**
   * Constructs a new FilterPermissions 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 filter permissions.
   *
   * @return array
   *   New set of permissions.
   */
  public function permissions() {
    $permissions = [];
    $node_types = NodeType::loadMultiple();
    foreach ($node_types as $node_type_id => $node_type) {
      $permissions["view any unpublished $node_type_id content"] = [
        'title' => $this->t('%type_name: View any unpublished content', ['%type_name' => $node_type->label()]),
      ];
    }

    return $permissions;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc