Problem/Motivation

I have two content types (Book and Page) and a taxonomy vocabulary (Notes). Notes vocabulary has an image field (field_image). Page content type has an entity reference field (field_note) that references terms in Notes vocabulary. Book content type has an entity reference field (field_page) that references nodes of type Page.

I created a view that displays content of type Book. I also added two relationships: field_pages that appears in Book and field_note that appears in Page. (field_note relationship uses field_pages relationship because notes are attached to pages).

I also turned on an option to display all messages with backtrace information in Logging and errors configuration panel.

Then I added the following content:

  1. A term "First note" to Notes vocabulary and attached an image to it
  2. A node of type Page and referenced a term "First note" to it
  3. Two nodes of type Page without term references.
  4. A node of type Book with three references to nodes of type Page.

When the view page is displayed, I get an error:

Notice: Undefined index: field_note in Drupal\views\Plugin\views\field\FieldPluginBase->getEntity() (line 395 of core/modules/views/src/Plugin/views/field/FieldPluginBase.php).
Drupal\views\Plugin\views\field\FieldPluginBase->getEntity(Object)
Drupal\field\Plugin\views\field\Field->getItems(Object)
...

Proposed resolution

getEntity() method in FieldPluginBase class does not check of relationship existence therefore if a node of type Book is displayed and if a referenced node of type Page does not have a reference to term in Notes vocabulary, NULL is returned and an undefined index error is thrown.

getEntity() method in FieldPluginBase class should check whether relationship exists and return NULL if it doesn't.

#2133471: Notice: Undefined index: uid in simple a user view is related to this issue in sense that variable existence check is not performed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maijs’s picture

A patch against 8.0.x branch (commit d21c9a4) is attached.

maijs’s picture

Status: Active » Needs review
jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

adci_contributor’s picture

Status: Needs work » Needs review
FileSize
663 bytes

Trying to reroll.
Docblock is '@inheritdoc' now, so I didn't touch it.

dawehner’s picture

@adci_contributor
Can you please login with your personal drupal.org account?

In general I think this patch should not be applied, because even it might fix the symptom I doubt that this fixes the underlying problem.
The question we have to ask is: why is the relationship value not set here?

adci_contributor’s picture

@dawehner actually I'm already logged on with my personal account. :)

jhedstrom’s picture

The question we have to ask is: why is the relationship value not set here?

As I understand the issue, this occurs when a relationship is optional.

jyotisankar’s picture

I am working on it

jyotisankar’s picture

Issue tags: +#SprintWeekend2015
FileSize
661 bytes
David Hernández’s picture

Hello!

Thank you for working on this issue!

We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.

David Hernández’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015
manningpete’s picture

Issue tags: -Needs reroll

Patch applies.

maijs’s picture

Issue tags: +drupaldevdays
FileSize
661 bytes

This issue still persists and is very annoying. The patch has been updated.

mikgreen’s picture

Status: Needs review » Reviewed & tested by the community

Works as advertised.
I've had to enable error logging to see notices.
They are gone after applying patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: undefined-index-2319005-13.patch, failed testing.

Status: Needs work » Needs review
maijs’s picture

QA testbot failure with applying the patch in #15 seems to be a mistake on testbot part. Having done manual testing and new "passed" status, setting back to RTBC.

maijs’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Looks like a we could write a test to cover this.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Closed (outdated)

Closing this out as it appears to have been already added to core.

smustgrave’s picture

Issue tags: +Bug Smash Initiative
xjm’s picture

Status: Closed (outdated) » Needs work

Per discussion with @smustgrave and @quietone, we're not sure that #32 is the case.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.