You are here

final class ThemeEvent in Hook Event Dispatcher 8

Class ThemeEvent.

Hierarchy

  • class \Drupal\hook_event_dispatcher\Event\Theme\ThemeEvent extends \Symfony\Component\EventDispatcher\Event implements EventInterface

Expanded class hierarchy of ThemeEvent

2 files declare their use of ThemeEvent
hook_event_dispatcher.module in ./hook_event_dispatcher.module
Hook event dispatcher module.
ThemeEventTest.php in tests/src/Unit/Theme/ThemeEventTest.php

File

src/Event/Theme/ThemeEvent.php, line 13

Namespace

Drupal\hook_event_dispatcher\Event\Theme
View source
final class ThemeEvent extends Event implements EventInterface {

  /**
   * Existing implementations.
   *
   * @var array
   */
  private $existing;

  /**
   * Added themes.
   *
   * @var array
   */
  private $newThemes = [];

  /**
   * ThemeEvent constructor.
   *
   * @param array $existing
   *   An array of existing implementations that may be used for override
   *   purposes. This is primarily useful for themes that may wish to examine
   *   existing implementations to extract data (such as arguments) so that
   *   it may properly register its own, higher priority implementations.
   *
   * @see \hook_theme()
   */
  public function __construct(array $existing) {
    $this->existing = $existing;
  }

  /**
   * Get the dispatcher type.
   *
   * @return string
   *   The dispatcher type.
   */
  public function getDispatcherType() {
    return HookEventDispatcherInterface::THEME;
  }

  /**
   * Get the existing implementations.
   *
   * @return array
   *   The existing implementations.
   */
  public function getExisting() {
    return $this->existing;
  }

  /**
   * Get the new themes.
   *
   * @return array
   *   The new theme information.
   */
  public function getNewThemes() {
    return $this->newThemes;
  }

  /**
   * Add new theme.
   *
   * @param string $theme
   *   Theme hook.
   * @param array $information
   *   Information array.
   *
   * @see \hook_theme()
   * Have a look at the return statement.
   *
   * @throws \RuntimeException
   */
  public function addNewTheme($theme, array $information) {
    if (empty($information['path'])) {
      throw new RuntimeException('Missing path in the information array. ThemeEvent needs the path to be set manually, to have a proper default theme implementation. See \\hook_theme() for more information.');
    }
    $this->newThemes[$theme] = $information;
  }

  /**
   * Add new themes.
   *
   * @param array $themes
   *   The new theme information.
   *
   * @see \hook_theme()
   * Have a look at the return statement.
   *
   * @throws \RuntimeException
   */
  public function addNewThemes(array $themes) {
    foreach ($themes as $theme => $information) {
      $this
        ->addNewTheme($theme, $information);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeEvent::$existing private property Existing implementations.
ThemeEvent::$newThemes private property Added themes.
ThemeEvent::addNewTheme public function Add new theme.
ThemeEvent::addNewThemes public function Add new themes.
ThemeEvent::getDispatcherType public function Get the dispatcher type. Overrides EventInterface::getDispatcherType
ThemeEvent::getExisting public function Get the existing implementations.
ThemeEvent::getNewThemes public function Get the new themes.
ThemeEvent::__construct public function ThemeEvent constructor.