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 bf90923..204a315 100644 --- a/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php +++ b/core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php @@ -6,7 +6,6 @@ use Drupal\views\Plugin\views\filter\InOperator; use Drupal\views\Views; use Drupal\workflows\Entity\Workflow; -use Drupal\workflows\StateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -62,7 +61,7 @@ public function getValueOptions() { $states += $workflow_type->getStates(); } } - $this->valueOptions = array_map(function (StateInterface $state) { + $this->valueOptions = array_map(function($state) { return $state->label(); }, $states); @@ -72,51 +71,43 @@ public function getValueOptions() { /** * {@inheritdoc} */ - public function ensureMyTable() { - if (!isset($this->tableAlias)) { - $table_alias = $this->query->ensureTable($this->table, $this->relationship); - - // 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' => $table_alias, - 'left_field' => $left_entity_type->getKey('revision'), - 'extra' => [ - [ - 'field' => 'content_entity_type_id', - 'value' => $left_entity_type->id(), - ], + 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(), ], + ], + ]; + if ($left_entity_type->isTranslatable()) { + $configuration['extra'][] = [ + 'field' => $entity_type->getKey('langcode'), + 'left_field' => $left_entity_type->getKey('langcode'), ]; - 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'); } - - return $this->tableAlias; + $join = Views::pluginManager('join')->createInstance('standard', $configuration); + $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); } /** * {@inheritdoc} */ public function calculateDependencies() { - // Do not depend on the workflows which provide states that are utilised - // in the filter. States cannot be depended on directly and can also be - // common across multiple workflows. States and workflows with existing - // content cannot be deleted, so the impact of not depending on them here is - // mitigated. + // @todo calculate dependencies in https://www.drupal.org/node/2901690. return parent::calculateDependencies(); }