trait ModerationStateJoinViewsHandlerTrait

Same name in other branches
  1. 8.9.x core/modules/content_moderation/src/Plugin/views/ModerationStateJoinViewsHandlerTrait.php \Drupal\content_moderation\Plugin\views\ModerationStateJoinViewsHandlerTrait
  2. 10 core/modules/content_moderation/src/Plugin/views/ModerationStateJoinViewsHandlerTrait.php \Drupal\content_moderation\Plugin\views\ModerationStateJoinViewsHandlerTrait
  3. 11.x core/modules/content_moderation/src/Plugin/views/ModerationStateJoinViewsHandlerTrait.php \Drupal\content_moderation\Plugin\views\ModerationStateJoinViewsHandlerTrait

Assist views handler plugins to join to the content_moderation_state entity.

@internal

Hierarchy

3 files declare their use of ModerationStateJoinViewsHandlerTrait
ModerationStateField.php in core/modules/content_moderation/src/Plugin/views/field/ModerationStateField.php
ModerationStateFilter.php in core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php
ModerationStateSort.php in core/modules/content_moderation/src/Plugin/views/sort/ModerationStateSort.php

File

core/modules/content_moderation/src/Plugin/views/ModerationStateJoinViewsHandlerTrait.php, line 12

Namespace

Drupal\content_moderation\Plugin\views
View source
trait ModerationStateJoinViewsHandlerTrait {
    
    /**
     * {@inheritdoc}
     */
    public function ensureMyTable() {
        if (!isset($this->tableAlias)) {
            $table_alias = $this->query
                ->ensureTable($this->table, $this->relationship);
            // Join 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(),
                    ],
                    [
                        'field' => 'content_entity_id',
                        'left_field' => $left_entity_type->getKey('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->tableAlias = $this->query
                ->addRelationship('content_moderation_state', $join, 'content_moderation_state_field_revision');
        }
        return $this->tableAlias;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ModerationStateJoinViewsHandlerTrait::ensureMyTable public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.