RelationshipPluginBase.php in Zircon Profile 8
File
core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
View source
<?php
namespace Drupal\views\Plugin\views\relationship;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\HandlerBase;
use Drupal\views\Join;
use Drupal\views\Views;
abstract class RelationshipPluginBase extends HandlerBase {
public $alias;
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
if (isset($this->definition['relationship table'])) {
$this->table = $this->definition['relationship table'];
}
if (isset($this->definition['relationship field'])) {
$this->realField = $this->field = $this->definition['relationship field'];
}
}
public function usesGroupBy() {
return FALSE;
}
protected function defineOptions() {
$options = parent::defineOptions();
if (!empty($this->definition['label'])) {
$label = (string) $this->definition['label'];
}
else {
$label = !empty($this->definition['field']) ? $this->definition['field'] : $this->definition['base field'];
}
$options['admin_label']['default'] = $label;
$options['required'] = array(
'default' => FALSE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
unset($form['admin_label']['#fieldset']);
$form['admin_label']['#weight'] = -1;
$form['required'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Require this relationship'),
'#description' => $this
->t('Enable to hide items that do not contain this relationship'),
'#default_value' => !empty($this->options['required']),
);
}
public function query() {
$table_data = Views::viewsData()
->get($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this
->ensureMyTable();
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->tableAlias;
$def['left_field'] = $this->realField;
$def['adjusted'] = TRUE;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
if (!empty($this->definition['extra'])) {
$def['extra'] = $this->definition['extra'];
}
if (!empty($def['join_id'])) {
$id = $def['join_id'];
}
else {
$id = 'standard';
}
$join = Views::pluginManager('join')
->createInstance($id, $def);
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query
->addRelationship($alias, $join, $this->definition['base'], $this->relationship);
if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
$access_tag = $table_data['table']['base']['access query tag'];
$this->query
->addTag($access_tag);
}
}
public function calculateDependencies() {
$table_data = $this
->getViewsData()
->get($this->definition['base']);
return [
'module' => [
$table_data['table']['provider'],
],
];
}
}
Classes
Name |
Description |
RelationshipPluginBase |
Simple relationship handler that allows a new version of the primary table
to be linked in. |