protected function TocBlockBase::getCurrentNode in TOC API 8
Load the node associated with the current request.
Return value
\Drupal\node\NodeInterface|null A node entity, or NULL if no node is not found.
1 call to TocBlockBase::getCurrentNode()
- TocBlockBase::getCacheTags in src/
Plugin/ Block/ TocBlockBase.php - The cache tags associated with this object.
File
- src/
Plugin/ Block/ TocBlockBase.php, line 103
Class
- TocBlockBase
- Provides a base TOC block which displays the current TOC module's TOC in a block.
Namespace
Drupal\toc_api\Plugin\BlockCode
protected function getCurrentNode() {
switch (\Drupal::routeMatch()
->getRouteName()) {
// Look at the request's node revision.
case 'node.revision_show':
return node_revision_load(\Drupal::routeMatch()
->getParameter('node_revision'));
// Look at the request's node preview.
case 'entity.node.preview':
return \Drupal::routeMatch()
->getParameter('node_preview');
// Look at the request's node.
case 'entity.node.canonical':
return \Drupal::routeMatch()
->getParameter('node');
}
return NULL;
}