diff --git a/core/modules/content_translation/config/schema/content_translation.views.schema.yml b/core/modules/content_translation/config/schema/content_translation.views.schema.yml index 03dfc1a7e4..284e7fd1d0 100644 --- a/core/modules/content_translation/config/schema/content_translation.views.schema.yml +++ b/core/modules/content_translation/config/schema/content_translation.views.schema.yml @@ -7,3 +7,11 @@ views.field.content_translation_link: text: type: label label: 'Text to display' + +views.filter.untranslated: + type: views.filter.boolean + label: 'Untranslated' + +views.filter_value.untranslated: + type: views.filter_value.boolean + label: 'Untranslated' diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 10f546dfd5..92d695fc4c 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -349,6 +349,18 @@ function content_translation_views_data_alter(array &$data) { ], ]; } + + $data_table = $entity_type->getDataTable(); + if (isset($data[$data_table]) && $manager->isEnabled($entity_type_id)) { + $data[$data_table]['untranslated'] = [ + 'title' => t('Untranslated'), + 'filter' => [ + 'title' => t('Untranslated'), + 'help' => t('Check if the content is not translated in one, at least, enabled language.'), + 'id' => 'untranslated', + ], + ]; + } } } diff --git a/core/modules/content_translation/src/Plugin/views/filter/UnTranslated.php b/core/modules/content_translation/src/Plugin/views/filter/UnTranslated.php new file mode 100644 index 0000000000..061cdaa371 --- /dev/null +++ b/core/modules/content_translation/src/Plugin/views/filter/UnTranslated.php @@ -0,0 +1,103 @@ +get('entity_type.manager'), + $container->get('language_manager') + ); + } + + /** + * Constructs a Untranslated views filter object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity_type.manager service. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language_manager service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->entityTypeManager = $entity_type_manager; + $this->languageManager = $language_manager; + } + + /** + * {@inheritdoc} + */ + protected function operators() { + return []; + } + + /** + * {@inheritdoc} + */ + public function query() { + $this->ensureMyTable(); + + if (empty($this->value)) { + $operator = '>='; + } + else { + $operator = '<'; + } + + $languages_number = count($this->languageManager->getLanguages()); + $table_alias = (string) $this->table . '_untranslated'; + + $id_key = $this->entityTypeManager + ->getStorage($this->getEntityType()) + ->getEntityType() + ->getKey('id'); + + $where = "(SELECT COUNT(langcode) FROM {$this->table} {$table_alias} WHERE {$table_alias}.{$id_key} = {$this->tableAlias}.{$id_key}) {$operator} {$languages_number}"; + + $this->query->addWhereExpression($this->options['group'], $where); + } + +}