EntityViewBuilderInterface::view() should accept an EntityViewDisplay, not only a view mode ID

Created on 27 March 2014, over 11 years ago
Updated 24 June 2025, 18 days ago

Problem/Motivation

We're concerned here with the route comment.reply and the method \Drupal\comment\Controller\CommentController::getReplyForm().

Currently, comment module does some gymanstics to get a fully-rendered node and just a single comment on a page.

// The comment is in response to a entity.
elseif ($entity->access('view', $account)) {
  // We make sure the field value isn't set so we don't end up with a
  // redirect loop.
  $entity->{$field_name}->status = CommentItemInterface::HIDDEN;
  // Render array of the entity full view mode.
  $build['commented_entity'] = $this->entityManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, 'full');
  unset($build['commented_entity']['#cache']);
  $entity->{$field_name}->status = $status;
}

Note the hiding of the comment field, rendering the node, then reseting of the comment field status. This is not ideal, especially because we're actively unsetting the cache property, so this page becomes uncached.

Proposed resolution

What we might try instead is for the Comment module to provide a node view mode that is a combo of the fully-rendered entity and the comment form. Or, in the case of a reply to a comment, the comment being replied to and a comment form -- this last case might require a view mode for comment as well.

We could then cache the entity/comment reply pages given the unique view mode.

User interface changes

None.

API changes

None.

Original report by @jessebeach β†’

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡ΊπŸ‡ΈUnited States jessebeach

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024