You are here

class PdfUsingMpdfNodeTypePermissions in PDF using mPDF 8.2

Generate permissions dynamically for various content types

@package Drupal\pdf_using_mpdf

Hierarchy

Expanded class hierarchy of PdfUsingMpdfNodeTypePermissions

File

src/PdfUsingMpdfNodeTypePermissions.php, line 15

Namespace

Drupal\pdf_using_mpdf
View source
class PdfUsingMpdfNodeTypePermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * @var EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructor for GeneratePermissions class
   *
   * @param EntityTypeManagerInterface $entityTypeManager
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
    $this->entityTypeManager = $entityTypeManager;
  }
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * Return permissions
   *
   * @return array|array[]
   */
  public function accessPermissions() {
    $types = $this->entityTypeManager
      ->getStorage('node_type')
      ->loadMultiple();
    $types = array_map(function ($type) {
      return [
        'id' => $type
          ->id(),
        'label' => $type
          ->label(),
      ];
    }, $types);
    return $this
      ->createPerm($types);
  }

  /**
   * Create node type permissions
   *
   * @param array $types
   * @return array[]
   */
  public function createPerm($types) {
    $permissions = [];
    foreach ($types as $type) {
      $perm = [
        'generate ' . $type['id'] . ' pdf' => [
          'title' => $this
            ->t('%type_name: Generate PDF using mPDF', [
            '%type_name' => $type['label'],
          ]),
        ],
      ];
      $permissions += $perm;
    }

    //    echo '<pre>';print_r($permissions);die;
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PdfUsingMpdfNodeTypePermissions::$entityTypeManager protected property
PdfUsingMpdfNodeTypePermissions::accessPermissions public function Return permissions
PdfUsingMpdfNodeTypePermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
PdfUsingMpdfNodeTypePermissions::createPerm public function Create node type permissions
PdfUsingMpdfNodeTypePermissions::__construct public function Constructor for GeneratePermissions class
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.