class NavigationTestHooks
Hooks implementations for navigation_test module.
Hierarchy
- class \Drupal\navigation_test\Hook\NavigationTestHooks
Expanded class hierarchy of NavigationTestHooks
File
-
core/
modules/ navigation/ tests/ navigation_test/ src/ Hook/ NavigationTestHooks.php, line 14
Namespace
Drupal\navigation_test\HookView source
class NavigationTestHooks {
/**
* NavigationTestHooks constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public function __construct(StateInterface $state) {
}
/**
* Implements hook_block_alter().
*/
public function blockAlter(&$definitions) : void {
if ($this->state
->get('navigation_safe_alter')) {
$definitions['navigation_link']['allow_in_navigation'] = TRUE;
$definitions['navigation_shortcuts']['allow_in_navigation'] = FALSE;
}
}
/**
* Implements hook_navigation_content_top().
*/
public function navigationContentTop() : array {
if (\Drupal::keyValue('navigation_test')->get('content_top')) {
$items = [
'navigation_foo' => [
'#markup' => 'foo',
],
'navigation_bar' => [
'#markup' => 'bar',
],
'navigation_baz' => [
'#markup' => 'baz',
],
];
}
else {
$items = [
'navigation_foo' => [],
'navigation_bar' => [],
'navigation_baz' => [],
];
}
// Add cache tags to our items to express a made up dependency to test
// cacheability. Note that as we're always returning the same items,
// sometimes only with cacheability metadata. By doing this we're testing
// conditional rendering of content_top items.
foreach ($items as &$element) {
CacheableMetadata::createFromRenderArray($element)->addCacheTags([
'navigation_test',
])
->applyTo($element);
}
return $items;
}
/**
* Implements hook_navigation_content_top_alter().
*/
public function navigationContentTopAlter(&$content_top) : void {
if (\Drupal::keyValue('navigation_test')->get('content_top_alter')) {
unset($content_top['navigation_foo']);
$content_top['navigation_bar']['#markup'] = 'new bar';
$content_top['navigation_baz']['#weight'] = '-100';
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
NavigationTestHooks::blockAlter | public | function | Implements hook_block_alter(). |
NavigationTestHooks::navigationContentTop | public | function | Implements hook_navigation_content_top(). |
NavigationTestHooks::navigationContentTopAlter | public | function | Implements hook_navigation_content_top_alter(). |
NavigationTestHooks::__construct | public | function | NavigationTestHooks constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.