final class ThemeEvent in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/core_event_dispatcher/src/Event/Theme/ThemeEvent.php \Drupal\core_event_dispatcher\Event\Theme\ThemeEvent
Class ThemeEvent.
Hierarchy
- class \Drupal\core_event_dispatcher\Event\Theme\ThemeEvent extends \Symfony\Component\EventDispatcher\Event implements EventInterface
Expanded class hierarchy of ThemeEvent
2 files declare their use of ThemeEvent
- core_event_dispatcher.module in modules/
core_event_dispatcher/ core_event_dispatcher.module - Core event dispatcher submodule.
- ThemeEventTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Theme/ ThemeEventTest.php
File
- modules/
core_event_dispatcher/ src/ Event/ Theme/ ThemeEvent.php, line 13
Namespace
Drupal\core_event_dispatcher\Event\ThemeView 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() : string {
return HookEventDispatcherInterface::THEME;
}
/**
* Get the existing implementations.
*
* @return array
* The existing implementations.
*/
public function getExisting() : array {
return $this->existing;
}
/**
* Get the new themes.
*
* @return array
* The new theme information.
*/
public function getNewThemes() : array {
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeEvent:: |
private | property | Existing implementations. | |
ThemeEvent:: |
private | property | Added themes. | |
ThemeEvent:: |
public | function | Add new theme. | |
ThemeEvent:: |
public | function | Add new themes. | |
ThemeEvent:: |
public | function |
Get the dispatcher type. Overrides EventInterface:: |
|
ThemeEvent:: |
public | function | Get the existing implementations. | |
ThemeEvent:: |
public | function | Get the new themes. | |
ThemeEvent:: |
public | function | ThemeEvent constructor. |