Skip to content
Snippets Groups Projects
Commit e5b58a2b authored by Chris Burgess's avatar Chris Burgess Committed by Vladimir Roudakov
Browse files

Issue #3254404 by tatianag, xurizaemon, RoSk0: TOC block isn't displayed in the Latest version

parent b41a688b
No related branches found
No related tags found
No related merge requests found
......@@ -4,13 +4,52 @@ namespace Drupal\toc_api\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a base TOC block which displays the current TOC module's TOC in a
* block.
*/
abstract class TocBlockBase extends BlockBase {
abstract class TocBlockBase extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Creates a LocalActionsBlock instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_route_match')
);
}
/**
* {@inheritdoc}
......@@ -86,19 +125,19 @@ abstract class TocBlockBase extends BlockBase {
* A node entity, or NULL if no node is not found.
*/
protected function getCurrentNode() {
switch (\Drupal::routeMatch()->getRouteName()) {
switch ($this->routeMatch->getRouteName()) {
// Look at the request's node revision.
case 'node.revision_show':
return node_revision_load(\Drupal::routeMatch()
return node_revision_load($this->routeMatch
->getParameter('node_revision'));
// Look at the request's node preview.
case 'entity.node.preview':
return \Drupal::routeMatch()->getParameter('node_preview');
return $this->routeMatch->getParameter('node_preview');
// Look at the request's node.
case 'entity.node.canonical':
return \Drupal::routeMatch()->getParameter('node');
return $this->routeMatch->getParameter('node');
}
return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment