You are here

class MaestroEnginePermissions in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/MaestroEnginePermissions.php \Drupal\maestro\MaestroEnginePermissions

Provides dynamic permissions of the maestro module.

Hierarchy

Expanded class hierarchy of MaestroEnginePermissions

File

src/MaestroEnginePermissions.php, line 13

Namespace

Drupal\maestro
View source
class MaestroEnginePermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

  /**
   * Constructs a new MaestroEnginePermissions 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 maestro template permissions.
   *
   * @return array
   *   An array of Maestro template permissions.
   */
  public function permissions() {
    $permissions = [];
    $templates = $this->entityManager
      ->getStorage('maestro_template')
      ->loadMultiple();
    uasort($templates, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
    foreach ($templates as $template) {
      if ($permission = $template->id) {
        $permissions['start template ' . $permission] = [
          'title' => $this
            ->t('Put the @label template into production.', [
            '@label' => $template
              ->label(),
          ]),
          'description' => [
            '#prefix' => '<em>',
            '#markup' => $this
              ->t('Only validated templates can be put into production.'),
            '#suffix' => '</em>',
          ],
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MaestroEnginePermissions::$entityManager protected property The entity manager.
MaestroEnginePermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
MaestroEnginePermissions::permissions public function Returns an array of maestro template permissions.
MaestroEnginePermissions::__construct public function Constructs a new MaestroEnginePermissions instance.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.