[regression] getEntity() doesn't always return entity, which results in add comment field not working in Views

Created on 28 April 2016, over 8 years ago
Updated 6 February 2023, almost 2 years ago

Drupal\views\Plugin\views\field\FieldPluginBase\GetEntity is documented as returning an entity.
However if only returns an entity if one of two conditions are true.

    if ($relationship_id == 'none') {
      return $values->_entity;
    }
    elseif (isset($values->_relationship_entities[$relationship_id])) {
      return $values->_relationship_entities[$relationship_id];
    }

otherwise it returns nothing;
Mine is crashing I think when a non-required relationship is not present.

This is problematic in Drupal\views\Plugin\views\field\Field::getItems() because createEntityForGroupBy expects an entity. I think this problem was introduced in 8.1
$this->createEntityForGroupBy($this->getEntity($values), $values);

This also results in the add comment link not being a link in Views. Steps to reproduce from #2671494: Add Comment Field Not Appearing in Views β†’ :

  1. Create a new view 'Blog' as a page, Unformatted List, Fields, paged 10, URL /blog
  2. Add field for 'Content: Add comment link'
  3. View the page at /blog
  4. The field is empty
πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
ViewsΒ  β†’

Last updated about 5 hours ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024