You are here

class ThemePerm in Theme permission 8

Theme Permission.

@package Drupal\theme_permission

Hierarchy

Expanded class hierarchy of ThemePerm

File

src/ThemePerm.php, line 17

Namespace

Drupal\theme_permission
View source
class ThemePerm implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandler
   */
  protected $themeHandler;

  /**
   * ThemePerm constructor.
   *
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler service.
   */
  public function __construct(ThemeHandlerInterface $theme_handler) {
    $this->themeHandler = $theme_handler;
  }

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

  /**
   * Returns an array of permissions.
   *
   * @return array
   *   The permissions.
   */
  public function dynamicPermissions() {
    $perms = [];
    $themes = $this->themeHandler
      ->listInfo();
    foreach ($themes as $theme => $value) {
      $type_params = [
        '%themename' => $theme,
      ];
      $perms += [
        "administer themes {$theme}" => [
          'title' => $this
            ->t('administer themes %themename', $type_params),
        ],
        "uninstall themes {$theme}" => [
          'title' => $this
            ->t('uninstall themes %themename', $type_params),
        ],
        "Edit Administration theme" => [
          'title' => $this
            ->t('Edit Administration theme'),
        ],
      ];
    }
    return $perms;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ThemePerm::$themeHandler protected property The theme handler.
ThemePerm::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ThemePerm::dynamicPermissions public function Returns an array of permissions.
ThemePerm::__construct public function ThemePerm constructor.