diff --git a/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php b/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php index 0d44883c88..091210d86a 100644 --- a/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php +++ b/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php @@ -72,61 +72,38 @@ public function getValueOptions() { /** * {@inheritdoc} */ - public function query() { - $this->ensureMyTable(); - // Filter the moderation states of the content via the - // ContentModerationState field revision table, joining either the entity - // field data or revision table. This allows filtering states against either - // the default or latest revision, depending on the relationship of the - // filter. - $left_entity_type = $this->entityTypeManager->getDefinition($this->getEntityType()); - $entity_type = $this->entityTypeManager->getDefinition('content_moderation_state'); - $configuration = [ - 'table' => $entity_type->getRevisionDataTable(), - 'field' => 'content_entity_revision_id', - 'left_table' => $this->tableAlias, - 'left_field' => $left_entity_type->getKey('revision'), - 'extra' => [ - [ - 'field' => 'content_entity_type_id', - 'value' => $left_entity_type->id(), + public function ensureMyTable() { + if (!isset($this->tableAlias)) { + // Filter the moderation states of the content via the + // ContentModerationState field revision table, joining either the entity + // field data or revision table. This allows filtering states against either + // the default or latest revision, depending on the relationship of the + // filter. + $left_entity_type = $this->entityTypeManager->getDefinition($this->getEntityType()); + $entity_type = $this->entityTypeManager->getDefinition('content_moderation_state'); + $configuration = [ + 'table' => $entity_type->getRevisionDataTable(), + 'field' => 'content_entity_revision_id', + 'left_table' => $this->tableAlias, + 'left_field' => $left_entity_type->getKey('revision'), + 'extra' => [ + [ + 'field' => 'content_entity_type_id', + 'value' => $left_entity_type->id(), + ], ], - ], - ]; - if ($left_entity_type->isTranslatable()) { - $configuration['extra'][] = [ - 'field' => $entity_type->getKey('langcode'), - 'left_field' => $left_entity_type->getKey('langcode'), ]; - } - $join = Views::pluginManager('join')->createInstance('standard', $configuration); - $this->query->addRelationship('content_moderation_state', $join, 'content_moderation_state_field_revision'); - parent::query(); - } - - /** - * {@inheritdoc} - */ - protected function opEmpty() { - if ($this->operator === 'empty') { - $operator = "IS NULL"; - } - else { - $operator = "IS NOT NULL"; - } - - $this->query->addWhere($this->options['group'], 'content_moderation_state.moderation_state', NULL, $operator); - } - - /** - * {@inheritdoc} - */ - protected function opSimple() { - if (empty($this->value)) { - return; + if ($left_entity_type->isTranslatable()) { + $configuration['extra'][] = [ + 'field' => $entity_type->getKey('langcode'), + 'left_field' => $left_entity_type->getKey('langcode'), + ]; + } + $join = Views::pluginManager('join')->createInstance('standard', $configuration); + $this->tableAlias = $this->query->addRelationship('content_moderation_state', $join, 'content_moderation_state_field_revision'); } - $this->query->addWhere($this->options['group'], 'content_moderation_state.moderation_state', $this->value, $this->operator); + return $this->tableAlias; } /**