class ViewsData in Drupal 9
Same name in this branch
- 9 core/modules/views/src/ViewsData.php \Drupal\views\ViewsData
- 9 core/modules/content_moderation/src/ViewsData.php \Drupal\content_moderation\ViewsData
Same name and namespace in other branches
- 8 core/modules/content_moderation/src/ViewsData.php \Drupal\content_moderation\ViewsData
Provides the content_moderation views integration.
@internal
Hierarchy
- class \Drupal\content_moderation\ViewsData uses StringTranslationTrait
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_moderationView 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);
});
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'),
'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'),
'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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ViewsData:: |
protected | property | The entity type manager. | |
ViewsData:: |
protected | property | The moderation information. | |
ViewsData:: |
public | function | Returns the views data. | |
ViewsData:: |
public | function | Creates a new ViewsData instance. |