Ajax not working when using non-default view mode.

Created on 24 July 2017, almost 7 years ago
Updated 18 March 2024, 3 months ago

If parent entity is rendered using non-default (not "full") view mode, ajax comment form is never updated.

On ajax_comments_entity_display_build_alter cache is set like that:

Utility::setEntityRenderArray($build, $context['entity'], $context['display']->getMode());

where $context['display']->getMode() is a current view mode, which can be anything, if you render node, for example, like

$build = $view_builder->view($node, "my_custom_view_mode");

On getWrapperIdFromEntity we're getting cache like that:

$render_array = static::getEntityRenderArray($commented_entity, 'full');

And inside of getEntityRenderArray we have this for view modes:

$modes = [
  $view_mode,
  '_custom',
  'default',
];

Where $view_mode argument is always "full". That means that if you use non-full view mode for parent entity, cache key will be different on cache set and get, since cache key is based on view mode. Because of that hidden 'wrapper_html_id' form field gets different "#id" property from actual <section> id and comment block is never updated on ajax response.

Not sure about what approach should be used here, will try to provide some patch later.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇮🇪Ireland ArchieV

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.69.0 2024