class PageEventVariables in Hook Event Dispatcher 8
Class PageEventVariables.
Hierarchy
- class \Drupal\hook_event_dispatcher\Event\Preprocess\Variables\AbstractEventVariables
- class \Drupal\hook_event_dispatcher\Event\Preprocess\Variables\PageEventVariables
Expanded class hierarchy of PageEventVariables
3 files declare their use of PageEventVariables
- OtherEventVariablesTest.php in tests/
src/ Unit/ Preprocess/ OtherEventVariablesTest.php - PagePreprocessEventFactory.php in src/
Event/ Preprocess/ Factory/ PagePreprocessEventFactory.php - PageTest.php in tests/
src/ Unit/ Preprocess/ PageTest.php
File
- src/
Event/ Preprocess/ Variables/ PageEventVariables.php, line 10
Namespace
Drupal\hook_event_dispatcher\Event\Preprocess\VariablesView source
class PageEventVariables extends AbstractEventVariables {
/**
* Is the current page a rendering a node?.
*
* @return bool
* Is it?
*/
public function isNodePage() {
return isset($this->variables['node']) && $this->variables['node'] instanceof NodeInterface;
}
/**
* Get the node of the page.
*
* @return \Drupal\node\NodeInterface|null
* Drupal node.
*/
public function getNode() {
if (!$this
->isNodePage()) {
return NULL;
}
return $this->variables['node'];
}
/**
* Get the template var.
*
* @param string $name
* Name.
* @param mixed $default
* Default.
*
* @return mixed
* Value
*/
public function get($name, $default = NULL) {
if (!isset($this->variables['page'][$name])) {
return $default;
}
return $this->variables['page'][$name];
}
/**
* Set a given page variable.
*
* @param string $name
* Name.
* @param mixed $value
* Value.
*
* @return $this
* PageEventVariables
*/
public function set($name, $value = NULL) {
$this->variables['page'][$name] = $value;
return $this;
}
/**
* Remove a given page variable.
*
* @param string $name
* Name.
*
* @return $this
* Page
*/
public function remove($name) {
unset($this->variables['page'][$name]);
return $this;
}
/**
* Get a variable with a given name by reference.
*
* @param string $name
* Variable name.
*
* @return mixed
* Reference for the variable.
*/
public function &getByReference($name) {
return $this->variables['page'][$name];
}
/**
* Get the complete $variables of the page template.
*
* @return mixed
* Reference to all variables of the page template.
*/
public function &getRootVariablesByReference() {
return $this->variables;
}
/**
* Add a cache context to the page template.
*
* @param string $context
* A cache context such as 'url.path'.
*
* @return $this
* PageEventVariables
*/
public function addCacheContext($context) {
$this->variables['#cache']['contexts'][] = $context;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractEventVariables:: |
protected | property | Variables. | |
AbstractEventVariables:: |
public | function | Event Variables constructor. | |
PageEventVariables:: |
public | function | Add a cache context to the page template. | |
PageEventVariables:: |
public | function |
Get the template var. Overrides AbstractEventVariables:: |
|
PageEventVariables:: |
public | function |
Get a variable with a given name by reference. Overrides AbstractEventVariables:: |
|
PageEventVariables:: |
public | function | Get the node of the page. | |
PageEventVariables:: |
public | function | Get the complete $variables of the page template. | |
PageEventVariables:: |
public | function | Is the current page a rendering a node?. | |
PageEventVariables:: |
public | function |
Remove a given page variable. Overrides AbstractEventVariables:: |
|
PageEventVariables:: |
public | function |
Set a given page variable. Overrides AbstractEventVariables:: |