class MenuChildrenNodeJoin in Views Menu Node Children Filter 8.2
Same name and namespace in other branches
- 8 src/Plugin/views/join/MenuChildrenNodeJoin.php \Drupal\views_menu_children_filter\Plugin\views\join\MenuChildrenNodeJoin
- 3.0.x src/Plugin/views/join/MenuChildrenNodeJoin.php \Drupal\views_menu_children_filter\Plugin\views\join\MenuChildrenNodeJoin
Views Join plugin to join the Node table to the menu_tree table.
@package Drupal\views_menu_children_filter
Plugin annotation
@ViewsJoin("menu_children_node_join");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\views\Plugin\views\join\JoinPluginBase implements JoinPluginInterface
- class \Drupal\views_menu_children_filter\Plugin\views\join\MenuChildrenNodeJoin
- class \Drupal\views\Plugin\views\join\JoinPluginBase implements JoinPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MenuChildrenNodeJoin
2 files declare their use of MenuChildrenNodeJoin
- MenuChildren.php in src/
Plugin/ views/ sort/ MenuChildren.php - MenuChildren.php in src/
Plugin/ views/ argument/ MenuChildren.php
1 string reference to 'MenuChildrenNodeJoin'
1 service uses MenuChildrenNodeJoin
File
- src/
Plugin/ views/ join/ MenuChildrenNodeJoin.php, line 18
Namespace
Drupal\views_menu_children_filter\Plugin\views\joinView source
class MenuChildrenNodeJoin extends JoinPluginBase {
/**
* The values to concat with node.nid in to join on the menu_tree's route_param_key column.
*
* @var array Defaults to: [ 'entity:node/' ].
*/
public $prefixes = array(
'entity:node/',
);
/**
* MenuChildrenNodeJoin constructor.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler Required to setup hook_TYPE_alter hooks so module's can alter this join.
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
*/
public function __construct(ModuleHandlerInterface $module_handler, array $configuration, $plugin_id, $plugin_definition) {
// Define a hook_TYPE_alter hook for other modules to change the "prefixes" used in the SQL join.
$module_handler
->alter('menu_children_filter_join_prefix', $this->prefixes);
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* Creates an instance of the plugin.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container to pull out services used in the plugin.
* @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.
*
* @return static
* Returns an instance of this plugin.
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// Setup some defaults.
$configuration = array_merge(array(
'type' => 'INNER',
'table' => 'menu_link_content_data',
'field' => false,
// Formula value handled in the "buildJoin" function.
'left_table' => false,
'left_field' => false,
'operator' => '=',
), $configuration);
// TODO: Remove this after dev work completed.
// $test = $container->get('views_menu_children_filter.join_handler');
$plugin_id = empty($plugin_id) ? "menu_children_node_join" : $plugin_id;
return new static($container
->get('module_handler'), $configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
function buildJoin($select_query, $table, $view_query) {
$values = array();
$node_table_alias = $select_query
->getTables()['node_field_data']['alias'];
$condition_parts = [];
foreach ($this->prefixes as $prefix) {
// Concatenate prefix with node.nid and provide as a parametrized value.
$placeholder = ':views_join_condition_' . $select_query
->nextPlaceholder();
$values[$placeholder] = $prefix;
$condition_parts[] = "( CONCAT({$placeholder}, {$node_table_alias}.nid) = {$this->table}.link__uri)";
}
$condition = sprintf('(%s.enabled = 1) AND (%s)', $this->table, implode(' OR ', $condition_parts));
$select_query
->addJoin($this->type, $this->table, $table['alias'], $condition, $values);
}
/**
* @param Sql $query The query that the join will be added to.
* @param bool $allow_duplicate_join If "false", prevents this join from joining more than once if this function is called repeatedly.
*/
public function joinToNodeTable(Sql $query, $allow_duplicate_join = false) {
// Because this can be called from the argument and sort handlers,
// first check to see if the join as already been applied.
if (!$allow_duplicate_join && isset($query->tables['node_field_data']['menu_link_content_data'])) {
return;
}
$query
->queueTable("menu_link_content_data", "node_field_data", $this);
}
/**
* Filter the query by either a: parent node, page page via its link_path, or null and limit to root nodes.
*
* @param \Drupal\views\Plugin\views\query\Sql $query The $query The query we're going to alter.
* @param \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $link The by parent link.
*/
public static function filterByPage(Sql $query, $link) {
$parent = $link
->getPluginId();
$query
->addWhereExpression(0, 'menu_link_content_data.parent = :parent_lid', array(
':parent_lid' => $parent,
));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
JoinPluginBase:: |
public | property | Defines whether a join has been adjusted. | |
JoinPluginBase:: |
public | property |
The configuration array passed by initJoin. Overrides PluginBase:: |
|
JoinPluginBase:: |
public | property | An array of extra conditions on the join. | |
JoinPluginBase:: |
public | property | How all the extras will be combined. Either AND or OR. | |
JoinPluginBase:: |
public | property | The field to join on (right field). | |
JoinPluginBase:: |
public | property | The field we join to. | |
JoinPluginBase:: |
public | property | A formula to be used instead of the left field. | |
JoinPluginBase:: |
public | property | The table we join to. | |
JoinPluginBase:: |
public | property | The table to join (right table). | |
JoinPluginBase:: |
public | property | The join type, so for example LEFT (default) or INNER. | |
JoinPluginBase:: |
protected | function | Builds a single extra condition. | |
JoinPluginBase:: |
protected | function | Adds the extras to the join condition. | 1 |
MenuChildrenNodeJoin:: |
public | property | The values to concat with node.nid in to join on the menu_tree's route_param_key column. | |
MenuChildrenNodeJoin:: |
function |
Builds the SQL for the join this object represents. Overrides JoinPluginBase:: |
||
MenuChildrenNodeJoin:: |
public static | function | Creates an instance of the plugin. | |
MenuChildrenNodeJoin:: |
public static | function | Filter the query by either a: parent node, page page via its link_path, or null and limit to root nodes. | |
MenuChildrenNodeJoin:: |
public | function | ||
MenuChildrenNodeJoin:: |
public | function |
MenuChildrenNodeJoin constructor. Overrides JoinPluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |