We've basically decided that all entity views should behave similarly on #2313159: [meta] Make multilingual views work

Which means:
- A views row is an entity ID plus language (a translation)
- Filterable on the language of translation
- Also filterable on original language of the entity or revision

Taxonomy has the first two, but lacks the filter on the original language of the term. For parity with other entity views, it should have this added.

See how Node does this for an example.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

jhodgdon’s picture

Status: Postponed » Active

Other issue is taken care of.

jhodgdon’s picture

Status: Active » Postponed
Related issues: +#1740492: Implement a default entity views data handler

The proposed patch on #1740492: Implement a default entity views data handler would take care of this... so we may want to postpone until that is done and then hopefully close this issue as a duplicate. But if that issue isn't moving forward, we can do this here.

jhodgdon’s picture

Status: Postponed » Active

#1740492: Implement a default entity views data handler has been committed, so it's time to get back to this issue.

What needs to be done for Taxonomy is something similar to what that issue's patch did for Node: convert Taxonomy's views data handler to derive from the new default Views data handler. Which will automatically add the necessary filter on the original language.

jhodgdon’s picture

Status: Active » Needs review
FileSize
6.11 KB

Here's a first pass, at least, at converting Taxonomy to use the new base class for views data. I think it works; needs patch to #2320521: Follow-up: Node language views filters need label adjustments to make the Views UI labels for the langcode fields make sense though. Let's see if it breaks any tests, then go from there.

I think there is a problem with the Description field here though. It seems that it's added to the views data in the default class in a way that's different from how the Taxonomy-specific class was doing it. Needs further investigation.

Status: Needs review » Needs work

The last submitted patch, 5: 2320743-convert-taxonomy.patch, failed testing.

dawehner’s picture

I think there is a problem with the Description field here though. It seems that it's added to the views data in the default class in a way that's different from how the Taxonomy-specific class was doing it. Needs further investigation.

I am pretty sure it is exposed as $data['taxonomy_term_field_data']['description.value']

+++ b/core/modules/taxonomy/src/TermViewsData.php
@@ -96,42 +68,21 @@ public function getViewsData() {
     $data['taxonomy_term_field_data']['name'] = array(
-      'title' => t('Name'),
       'help' => t('The taxonomy term name.'),
       'field' => array(
         'id' => 'taxonomy',
       ),
-      'sort' => array(
-        'id' => 'standard',
-      ),
       'filter' => array(
-        'id' => 'string',
         'help' => t('Taxonomy term name.'),
       ),
       'argument' => array(
-        'id' => 'string',
         'help' => t('Taxonomy term name.'),
         'many to one' => TRUE,
         'empty field name' => t('Uncategorized'),
       ),
-    );
+    ) + $data['taxonomy_term_field_data']['name'];
...
-    $data['taxonomy_term_field_data']['weight'] = array(
-      'title' => t('Weight'),
-      'help' => t('The term weight field'),
-      'field' => array(
-        'id' => 'numeric',
-      ),
-      'sort' => array(
-        'id' => 'standard',
-      ),
-      'filter' => array(
-        'id' => 'numeric',
-      ),
-      'argument' => array(
-        'id' => 'numeric',
-      ),
-    );
+    $data['taxonomy_term_field_data']['weight']['help'] = t('The term weight field');

Ha, I thought we don't want to do that :)

jhodgdon’s picture

Assigned: Unassigned » jhodgdon

Yeah, I'm working on a new patch... definitely needs some cleanup. And the existing views data exposes the description as description__data and description__format, not with a . separator -- looking into this too... trying to be systematic this time. The first patch was just a quick one...

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
14.36 KB
10.96 KB

So... The database table fields here are description__value and description__format, so the Views base class needed an update for this. There may be a cleaner way to do this, not sure.

Anyway, with that change, here's a generally more careful go at the Taxonomy views data class. I made things into a more logical order and fixed an indentation problem... so the patch is a bit bigger but the result is I think better.

There still seems to be some problem with the tid_representative relationship when I run a test locally; I'm not sure why since this did not change in TermViewsData? Anyway, let's see what the bot and dawehner say, maybe that is an artifact of some sort on my local machine.

Status: Needs review » Needs work

The last submitted patch, 9: 2320743-convert-taxonomy-9.patch, failed testing.

jhodgdon’s picture

That didn't work very well. :( Will have to work on this some more.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
20.04 KB
9.33 KB

OK, this should work better.

Note for @dawehner/reviewers: The interdiff only contains changes for EntityViewsData, but it's confusing and is nearly as big as the actual patch for that file... so I suggest just looking at the patch file and ignoring the interdiff, but I've attached it anyway just in case.

Status: Needs review » Needs work

The last submitted patch, 12: 2320743-convert-taxonomy-12.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
20.2 KB
1.74 KB

Hm. Not sure what the test failure is caused by, but I had already gone through the Node output to compare before and after this patch, and I think that is fine. This pass, I went through the Term output and found a problem with the Description field, which I think I've fixed. Let's see if that fixes this test failure, although it doesn't really look like it's probably related. Not sure.

Status: Needs review » Needs work

The last submitted patch, 14: 2320743-convert-taxonomy-14.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
22.12 KB
2.15 KB

OK, I fixed the test failure, at least locally.

In debugging this problem, I also came across (and fixed) a problem in the GroupwiseMax plugin where I couldn't look at its settings in Views UI because it was trying to access a protected property on the View object, so I fixed that too. Hope that is OK.

dawehner’s picture

  1. +++ b/core/modules/views/src/Entity/View.php
    @@ -143,6 +143,13 @@ public function label() {
     
       /**
    +   * Returns the base table name.
    +   */
    +  public function getBaseTable() {
    +    return $this->base_table;
    +  }
    +
    
    +++ b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php
    @@ -127,7 +127,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    -      if ($view->base_table == $this->definition['base'] && !empty($view->display['default']['display_options']['fields'])) {
    +      if ($view->getBaseTable() == $this->definition['base'] && !empty($view->display['default']['display_options']['fields'])) {
    

    Not sure whether we really need all those getters or just using $view->get('base_table') would be enough.

  2. +++ b/core/modules/views/src/Entity/View.php
    index 2477885..1439bd2 100644
    --- a/core/modules/views/src/EntityViewsData.php
    
    --- a/core/modules/views/src/EntityViewsData.php
    +++ b/core/modules/views/src/EntityViewsData.php
    

    Can we please expand the test coverage now that we change something in this file?

  3. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -250,113 +240,119 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf
    -    $process_method = 'processViewsDataFor' . Container::camelize($data_type);
    +    // Do post-processing for a few field types.
    +
    +    $process_method = 'processViewsDataFor' . Container::camelize($field_type);
         if (method_exists($this, $process_method)) {
    

    These extra lines looks kind of wrong.

jhodgdon’s picture

FileSize
20.67 KB

Thanks for the review!

Regarding point 1 in #17, I'll take this out of the patch and file a separate issue. It's not actually related to this issue. And .. not sure if point 2 is related to this... the comment is a bit garbled... I think so?

So I filed: #2341483: Views UI on settings for GroupwiseMax relationships has fatal error

And here is a new patch without those changes.

Regarding point 3, previously the argument passed into mapFieldDefinition was called $data_type and it was either the field type or the column type, depending on whether it was the first item on the field or not. This was confusing and not working for long text fields, so in this patch, I changed it so both are explicitly always passed separately, as $field_type and $column_type. The special post processing happens on field types.

Oh, maybe on point 2 you are saying we need some additional test coverage for EntityViewsData. I think that is true -- it needs coverage for a text_long field, which wasn't working without this patch. I believe that this is the only output change from this patch (obviously everything else is passing the tests); most of the patch in EntityViewsData is refactoring the code so that I could get text_long to work in a sane way, but (as you can tell because the existing EntityViewsData tests pass) the output is the same (I also manually checked the before/after output from Node to make sure it hadn't changed).

Anyway. First here is a patch without the changes to
core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php
core/modules/views/src/Entity/View.php
Otherwise the same as previous patch. I'll see what I can do about a test next.

jhodgdon’s picture

FileSize
32.6 KB
11.94 KB

Here's a patch with added unit tests for an entity with a Long Text field.

dawehner’s picture

Great work!

  1. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -226,22 +226,12 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf
    +    $multiple = (count($field_column_mapping) > 1);
         $first = TRUE;
    ...
    -      $schema = $field_schema['columns'][$field_column_name];
    -      // We want to both have an entry in the views data for the actual field,
    -      // but also each additional schema field, for example the file
    -      // description.
    -      // @todo Introduce a concept of the "main" schema field for a field item.
    -      //   This would be the FID for a file reference for example.
    -      // @see https://www.drupal.org/node/2337517
    ...
    +      $views_field_name = ($multiple) ? $field_name . '__' . $field_column_name : $field_name;
    +      $table_data[$views_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $field_definition_type, $field_column_name, $field_schema['columns'][$field_column_name]['type'], $first, $field_definition);
    +      $first = FALSE;
    
    @@ -250,113 +240,119 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf
         if ($first) {
           $views_field['title'] = $field_definition->getLabel();
         }
         else {
    -      $views_field['title'] = $field_definition->getLabel() . " ($schema_field_name)";
    +      $views_field['title'] = $field_definition->getLabel() . " ($column_name)";
         }
    

    Can we try to not drop the todo and still keep some documentation? There is a still a big difference between the first one and the other one on the level of the sitebuilder.

  2. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -250,113 +240,119 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf
    +    switch ($field_type) {
    +
    +      // Special case a few field types.
    +
    +      case 'timestamp':
    

    Do we really use that much of new empty lines?

  3. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -250,113 +240,119 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf
         if (method_exists($this, $process_method)) {
    -      $this->{$process_method}($table, $field_definition, $views_field);
    +      $this->{$process_method}($table, $field_definition, $views_field, $column_name);
         }
    
    @@ -395,6 +391,13 @@ protected function processViewsDataForLanguage($table, FieldDefinitionInterface
       protected function processViewsDataForEntityReference($table, FieldDefinitionInterface $field_definition, array &$views_field) {
    

    Shouldn't we update the existing methods to also accept the $column_name ?

  4. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -426,6 +429,26 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt
    +   * Processes the views data for a text field with formatting.
    ...
    +   * @param string $table
    +   *   The table the language field is added to.
    

    Note: this is not about the language but actually about text fields.

jhodgdon’s picture

FileSize
34.19 KB
3.59 KB

Thanks for the review! All great ideas, I agree with everything.

This patch: Fixed whitespace and comments, and added the new parameter to the processViewsDataFor* methods.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, I think this is ready to fly now! More work ins coming.

jhodgdon’s picture

After this is committed, I plan to work on #2320277: Views comment language field/filter is for original language code, no translation language field/filter and #2323939: Views user language field/filter is for original language code, no translation language field/filter, where the proposed fix is basically to use the Views entity data base class on comment/user entities, if you were referring to "using the base views data class elsewhere coming soon" in comment #22. Did you have different issues also filed?

jhodgdon’s picture

Assigned: jhodgdon » Unassigned

Unassigning to avoid "jhodgdon is committing this" confusion in the RTBC queue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 61de3bd and pushed to 8.0.x. Thanks!

  • alexpott committed 61de3bd on 8.0.x
    Issue #2320743 by jhodgdon: Taxonomy views needs filter/field on...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.