Problem/Motivation

There is a relationship provided by taxonomy in TermViewsData, labeled as "Content with term - Relate all content tagged with a term." This relationship allows you to find related content by joining from the taxonomy_index table to the node table.

I believe however that it should be joining to the node_field_data table. As at the moment you cannot add fields, filters, etc. relating to the nodes joined to.

What are the steps required to reproduce the bug?

  • Install Drupal - Standard profile
  • Add some articles with the same tags
  • Create a view of content (nodes)
  • Add a views relationship to the tag term field
  • Add a views relationship to the "Content with term" using the previous relationship.
  • Try to add any fields on content - There is no option for selecting the relationship as the views base node is the only node available.

What behavior were you expecting?

I am expecting to be able to add fields,etc for the related content.

What happened instead?

There is no option for the related content.

Proposed resolution

Change the base table for the relationship

Remaining tasks

Change the base table for the relationship

Comments

yanniboi created an issue. See original summary.

yanniboi’s picture

Status: Active » Needs review
StatusFileSize
new645 bytes

Attached patch

yanniboi’s picture

StatusFileSize
new4.93 KB
yanniboi’s picture

StatusFileSize
new86.58 KB
yanniboi’s picture

Issue tags: +Novice
bn_code’s picture

Assigned: Unassigned » bn_code
bn_code’s picture

Assigned: bn_code » Unassigned
joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/src/TermViewsData.php
@@ -157,10 +157,10 @@ public function getViewsData() {
-        'base' => 'node',
+        'base' => 'node_field_data',

Instead of hardcoding, this should call getViewsTableForEntityType(), like in the code that sets up general reference field relationships:

        $views_field['relationship'] = [
          'base' => $this->getViewsTableForEntityType($entity_type),
          'base field' => $entity_type->getKey('id'),
          'label' => $entity_type->getLabel(),
          'title' => $entity_type->getLabel(),
          'id' => 'standard',
        ];

Max1muss’s picture

Hi there, I'm here at the contribution weekend and I'm going to make the suggested changes!

Max1muss’s picture

Adding tags

takyros’s picture

New patch with suggested changes. #ContributionWeekend2019 @mecmartini, @jlbellido

takyros’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Needs work » Needs review

Status: Needs review » Needs work
joachim’s picture

  1. +++ b/core/modules/taxonomy/src/TermViewsData.php
    @@ -152,15 +152,17 @@ public function getViewsData() {
    -        'skip base' => 'node',
    

    This item's been lost.

  2. +++ b/core/modules/taxonomy/src/TermViewsData.php
    @@ -152,15 +152,17 @@ public function getViewsData() {
    +        'title' => $entity_type->getLabel(),
    ...
    +        'base field' => $entity_type->getKey('id'),
    +        'label' => $entity_type->getLabel(),
    

    These are good changes, but they're technically scope creep!

    They're clean-up tasks, rather than bug fixing. I'm nitpicking, yes, but this is an important principle to keep a patch focussed on the issue.

StephanieLuz’s picture

Tested patch from #2. Worked as expected! (Drupal Contrib Weekend!)

jimafisk’s picture

Tested with @StephanieLuz, #2 works! Thanks!

mecmartini’s picture

Status: Needs work » Needs review
StatusFileSize
new837 bytes
new786 bytes

@joachim I understand your point, we were using as reference the code on CommentViewsData

$data['comment_field_data'][$type] = [
          'relationship' => [
            'title' => $entity_type->getLabel(),
            'help' => $this->t('The @entity_type to which the comment is a reply to.', ['@entity_type' => $entity_type->getLabel()]),
            'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(),
            'base field' => $entity_type->getKey('id'),
            'relationship field' => 'entity_id',
            'id' => 'standard',
            'label' => $entity_type->getLabel(),
            'extra' => [
              [
                'field' => 'entity_type',
                'value' => $type,
                'table' => 'comment_field_data',
              ],
            ],
          ],
        ];

Anyway here it's the updated patch with suggested changes.

#ContributionWeekend2019 @karma0321 @jlbellido @Max1muss

Status: Needs review » Needs work
mecmartini’s picture

We mistaked this line:

'base' => $this->getViewsTableForEntityType($entity_type),

with this:

'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(),

It should be the same. Anyway, if needed, we'll upload a new patch to fix it.

Also, since the tests didn't pass, I guess we need to update the failed tests adding the "node" entity type. We'll try to work on it next week.

mecmartini’s picture

mecmartini’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
joachim’s picture

+++ b/core/modules/taxonomy/src/TermViewsData.php
@@ -152,12 +152,15 @@ public function getViewsData() {
+        'title' => $this->t('node'),

The test failure might be because this title property is going to change the UI.

psf_’s picture

Status: Needs work » Needs review
mecmartini’s picture

@joachim I don't see any errors in the build, why the testing failed?

About the #23, the issue there is the title field or the fact that we used $this->t() as value?

joachim’s picture

> About the #23, the issue there is the title field or the fact that we used $this->t() as value?

Don't add the title field. That's changing the UI, and not a part of this issue.

mecmartini’s picture

Updated patch without the title field.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks everyone!

The last submitted patch, 2: 3011013-2.patch, failed testing. View results

Status: Reviewed & tested by the community » Needs work
krzysztof domański’s picture

Status: Needs work » Reviewed & tested by the community

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldTidTest needs fixing.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new655 bytes
new2.71 KB

Fixed the test

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: 3011013-34.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new537 bytes
new2.71 KB

Let's not use a deprecated property

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1019 bytes
new1.63 KB

So given that the base table is not dynamic I don't think we should be using the entity type manager for this. We don't, for example, in \Drupal\file\FileViewsData, book_views_data(), \Drupal\user\UserViewsData. The only time we use the entity type definition to get the base table name is when it is dynamic. That means we don't need to fix the tests which make this change less disruptive for contrib or custom testing.

Also whilst reviewing this I realise we've not update the 'skip base' setting and I think we should.

Also whilst checking the rest of the code base I've discovered that forum has the same problem. We should look to see if there is a similar issue - I've not fixed it here because views based on forum_index are more broken than just this.

Furthermore I think we should add some automated test coverage of this change - which is done in the attached patch.

The last submitted patch, 37: 3011013-2-37.test-only.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Gayathri J’s picture

#37 Tested patch works for me. Looks Good!

joachim’s picture

Status: Needs review » Reviewed & tested by the community

That sounds like an RTBC to me!

  • catch committed 90db46d on 9.0.x
    Issue #3011013 by alexpott, mecmartini, yanniboi, karma0321, joachim,...

  • catch committed 15c711e on 8.9.x
    Issue #3011013 by alexpott, mecmartini, yanniboi, karma0321, joachim,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.0.x and 8.9.x thanks!

Wondering if there's a theoretical chance that this could break hook_views_query_alter() implementations or similar, so not backporting to 8.8.x for now.

Status: Fixed » Closed (fixed)

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

m@ster’s picture