class ViewsData

Same name in this branch
  1. 8.9.x core/modules/views/src/ViewsData.php \Drupal\views\ViewsData
Same name in other branches
  1. 9 core/modules/content_moderation/src/ViewsData.php \Drupal\content_moderation\ViewsData
  2. 9 core/modules/views/src/ViewsData.php \Drupal\views\ViewsData
  3. 10 core/modules/content_moderation/src/ViewsData.php \Drupal\content_moderation\ViewsData
  4. 10 core/modules/views/src/ViewsData.php \Drupal\views\ViewsData
  5. 11.x core/modules/content_moderation/src/ViewsData.php \Drupal\content_moderation\ViewsData
  6. 11.x core/modules/views/src/ViewsData.php \Drupal\views\ViewsData

Provides the content_moderation views integration.

@internal

Hierarchy

Expanded class hierarchy of ViewsData

1 file declares its use of ViewsData
content_moderation.views.inc in core/modules/content_moderation/content_moderation.views.inc
Provide views data for content_moderation.module.

File

core/modules/content_moderation/src/ViewsData.php, line 14

Namespace

Drupal\content_moderation
View source
class ViewsData {
    use StringTranslationTrait;
    
    /**
     * The entity type manager.
     *
     * @var \Drupal\Core\Entity\EntityTypeManagerInterface
     */
    protected $entityTypeManager;
    
    /**
     * The moderation information.
     *
     * @var \Drupal\content_moderation\ModerationInformationInterface
     */
    protected $moderationInformation;
    
    /**
     * Creates a new ViewsData instance.
     *
     * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
     *   The entity type manager.
     * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_information
     *   The moderation information.
     */
    public function __construct(EntityTypeManagerInterface $entity_type_manager, ModerationInformationInterface $moderation_information) {
        $this->entityTypeManager = $entity_type_manager;
        $this->moderationInformation = $moderation_information;
    }
    
    /**
     * Returns the views data.
     *
     * @return array
     *   The views data.
     */
    public function getViewsData() {
        $data = [];
        $entity_types_with_moderation = array_filter($this->entityTypeManager
            ->getDefinitions(), function (EntityTypeInterface $type) {
            return $this->moderationInformation
                ->isModeratedEntityType($type);
        });
        // Provides a relationship from moderated entity to its moderation state
        // entity.
        $content_moderation_state_entity_type = $this->entityTypeManager
            ->getDefinition('content_moderation_state');
        $content_moderation_state_entity_base_table = $content_moderation_state_entity_type->getDataTable() ?: $content_moderation_state_entity_type->getBaseTable();
        $content_moderation_state_entity_revision_base_table = $content_moderation_state_entity_type->getRevisionDataTable() ?: $content_moderation_state_entity_type->getRevisionTable();
        foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
            $table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
            $data[$table]['moderation_state'] = [
                'title' => t('Moderation state'),
                'relationship' => [
                    'id' => 'standard',
                    'title' => $this->t('Deprecated: @label moderation state', [
                        '@label' => $entity_type->getLabel(),
                    ]),
                    'help' => $this->t('Using a relationship to the Content Moderation State entity type has been deprecated and will be removed before 9.0.0. See <a target="_blank" href=":url">this change record</a> for alternatives.', [
                        ':url' => 'https://www.drupal.org/node/3061099',
                    ]),
                    'base' => $content_moderation_state_entity_base_table,
                    'base field' => 'content_entity_id',
                    'relationship field' => $entity_type->getKey('id'),
                    'extra' => [
                        [
                            'field' => 'content_entity_type_id',
                            'value' => $entity_type_id,
                        ],
                    ],
                    'deprecated' => 'Moderation state relationships are deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. See https://www.drupal.org/node/3061099',
                ],
                'field' => [
                    'id' => 'moderation_state_field',
                    'default_formatter' => 'content_moderation_state',
                    'field_name' => 'moderation_state',
                ],
                'filter' => [
                    'id' => 'moderation_state_filter',
                    'allow empty' => TRUE,
                ],
                'sort' => [
                    'id' => 'moderation_state_sort',
                ],
            ];
            $revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable();
            $data[$revision_table]['moderation_state'] = [
                'title' => t('Moderation state'),
                'relationship' => [
                    'id' => 'standard',
                    'title' => $this->t('Deprecated: @label moderation state', [
                        '@label' => $entity_type->getLabel(),
                    ]),
                    'help' => $this->t('Using a relationship to the Content Moderation State entity type has been deprecated and will be removed before 9.0.0. See <a target="_blank" href=":url">this change record</a> for alternatives.', [
                        ':url' => 'https://www.drupal.org/node/3061099',
                    ]),
                    'base' => $content_moderation_state_entity_revision_base_table,
                    'base field' => 'content_entity_revision_id',
                    'relationship field' => $entity_type->getKey('revision'),
                    'extra' => [
                        [
                            'field' => 'content_entity_type_id',
                            'value' => $entity_type_id,
                        ],
                    ],
                    'deprecated' => 'Moderation state relationships are deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. See https://www.drupal.org/node/3061099',
                ],
                'field' => [
                    'id' => 'moderation_state_field',
                    'default_formatter' => 'content_moderation_state',
                    'field_name' => 'moderation_state',
                ],
                'filter' => [
                    'id' => 'moderation_state_filter',
                    'allow empty' => TRUE,
                ],
                'sort' => [
                    'id' => 'moderation_state_sort',
                ],
            ];
        }
        return $data;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ViewsData::$entityTypeManager protected property The entity type manager.
ViewsData::$moderationInformation protected property The moderation information.
ViewsData::getViewsData public function Returns the views data.
ViewsData::__construct public function Creates a new ViewsData instance.

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