You are here

class Permissions in Block Region Permissions 8

Provides dynamic permissions for the block region permissions module.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 13

Namespace

Drupal\block_region_permissions
View source
class Permissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * Constructs a new Permissions instance.
   *
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   */
  public function __construct(ThemeHandlerInterface $theme_handler) {
    $this->themeHandler = $theme_handler;
  }

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

  /**
   * Get permissions.
   *
   * @return array
   *   Array of permissions.
   */
  public function get() {
    $permissions = [];

    // Get themes and generate permissions for each theme's regions.
    $themes = $this->themeHandler
      ->listInfo();
    foreach ($themes as $theme_key => $theme) {
      if ($theme->status == 1 && (!isset($theme->info['hidden']) || $theme->info['hidden'] != 1)) {
        $theme_name = $theme->info['name'];

        // Get regions for this theme.
        $regions = $theme->info['regions'];

        // Add permissions for each region.
        foreach ($regions as $region_key => $region_name) {
          $permissions["administer {$theme_key} {$region_key}"] = [
            'title' => $this
              ->t('Administer: <em>@theme</em> - <em>@region</em>', [
              '@theme' => $theme_name,
              '@region' => $region_name,
            ]),
          ];
        }
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$themeHandler protected property The entity manager.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::get public function Get permissions.
Permissions::__construct public function Constructs a new Permissions 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.