You are here

class FlippingBookPermissions in Flipping Book 8

Provides dynamic permissions of the flipping_book module.

Hierarchy

Expanded class hierarchy of FlippingBookPermissions

File

src/FlippingBookPermissions.php, line 14

Namespace

Drupal\flipping_book
View source
class FlippingBookPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

  /**
   * Constructs a new FlippingBookPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

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

  /**
   * Returns an array of private flipping books permissions.
   *
   * @return array
   */
  public function permissions() {
    $permissions = [];
    $storage = $this->entityManager
      ->getStorage('flipping_book_type');

    /** @var FlippingBookType[] $types */
    $types = $storage
      ->loadByProperties([
      'location' => FlippingBookInterface::FLIPPING_BOOK_PRIVATE,
    ]);
    uasort($types, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
    foreach ($types as $type) {
      if ($permission = $type
        ->getPermissionName()) {
        $permissions[$permission] = [
          'title' => $this
            ->t('Access "%label" Flipping Books', [
            '%label' => $type
              ->label(),
          ]),
          'description' => [
            '#prefix' => '<em>',
            '#markup' => $this
              ->t('Allow access to flipping books imported into the private folder.'),
            '#suffix' => '</em>',
          ],
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlippingBookPermissions::$entityManager protected property The entity manager.
FlippingBookPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FlippingBookPermissions::permissions public function Returns an array of private flipping books permissions.
FlippingBookPermissions::__construct public function Constructs a new FlippingBookPermissions 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.