-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added plugin for contextual filter for selecting 2 second level in bo…
…ok, used DI in Book Title block
- Loading branch information
1 parent
e754b87
commit 46e06a2
Showing
2 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
modules/quanthub_book/src/Plugin/views/argument_default/BookSecondLevelActive.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Drupal\quanthub_book\Plugin\views\argument_default; | ||
|
||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Drupal\node\NodeStorageInterface; | ||
use Drupal\node\Plugin\views\argument_default\Node; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Default argument plugin to get the current node's second level active page. | ||
* | ||
* @ViewsArgumentDefault( | ||
* id = "book_second_level_active", | ||
* title = @Translation("Book Second level active") | ||
* ) | ||
*/ | ||
class BookSecondLevelActive extends Node { | ||
|
||
/** | ||
* The node storage controller. | ||
* | ||
* @var \Drupal\node\NodeStorageInterface | ||
*/ | ||
protected $nodeStorage; | ||
|
||
/** | ||
* Constructs a BookSecondLevelActive object. | ||
* | ||
* @param array $configuration | ||
* A configuration array containing information about the plugin instance. | ||
* @param string $plugin_id | ||
* The plugin_id for the plugin instance. | ||
* @param array $plugin_definition | ||
* The plugin implementation definition. | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The route match. | ||
* @param \Drupal\node\NodeStorageInterface $node_storage | ||
* The node storage controller. | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteMatchInterface $route_match, NodeStorageInterface $node_storage) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match); | ||
$this->nodeStorage = $node_storage; | ||
} | ||
|
||
/** | ||
* {@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'), | ||
$container->get('entity_type.manager')->getStorage('node') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getArgument() { | ||
// Use the argument_default_node plugin to get the nid argument. | ||
$nid = parent::getArgument(); | ||
if (!empty($nid)) { | ||
$node = $this->nodeStorage->load($nid); | ||
// Get second level active book page. | ||
if (isset($node->book['p2']) && $node->book['p2'] > 0) { | ||
return $node->book['p2']; | ||
} | ||
} | ||
} | ||
|
||
} |