View source
<?php
namespace Drupal\views\Plugin\views\filter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\views\Plugin\ViewsHandlerManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LatestTranslationAffectedRevision extends FilterPluginBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
protected $joinHandler;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ViewsHandlerManager $join_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->joinHandler = $join_handler;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('plugin.manager.views.join'));
}
public function adminSummary() {
}
protected function operatorForm(&$form, FormStateInterface $form_state) {
}
public function canExpose() {
return FALSE;
}
public function query() {
$query = $this->query;
$query_base_table = $this->relationship ?: $this->view->storage
->get('base_table');
$entity_type = $this->entityTypeManager
->getDefinition($this
->getEntityType());
$keys = $entity_type
->getKeys();
$definition = [
'table' => $query_base_table,
'type' => 'LEFT',
'field' => $keys['id'],
'left_table' => $query_base_table,
'left_field' => $keys['id'],
'extra' => [
[
'left_field' => $keys['revision'],
'field' => $keys['revision'],
'operator' => '>',
],
[
'left_field' => 'langcode',
'field' => 'langcode',
'operator' => '=',
],
[
'field' => 'revision_translation_affected',
'value' => '1',
'operator' => '=',
],
],
];
$join = $this->joinHandler
->createInstance('standard', $definition);
$join_table_alias = $query
->addTable($query_base_table, $this->relationship, $join);
$query
->addWhere($this->options['group'], "{$join_table_alias}.{$keys['id']}", NULL, 'IS NULL');
$query
->addWhere($this->options['group'], "{$query_base_table}.revision_translation_affected", '1', '=');
}
}