Problem/Motivation

AJAX comments are configured in a view mode's comment field. Currently, however, this works only in the 'full' view mode. Configuring any other view mode to support AJAX comments leads to the bug that the form submits but no update is returned.

This bug is deeply embedded in the code base. There are six places where the 'full' node view mode is hard-coded.

Proposed resolution

Currently the implementation is attached to field configuration in node view modes, which introduces problems because it is in various comment contexts that we need to determine whether/how the behaviour should apply.

An alternative that might address this issue (albeit with significant refactoring) is to make AJAX comments instead a property of comment view modes.

  • An admin configuring a comment view mode has a checkbox to make the view mode use AJAX comments.
  • To apply AJAX comments to a given content type per view mode, configure the node's comments to use a view mode for which AJAX comments are enabled.
  • Via config/install, provide an 'ajax' comment view mode and enable AJAX comments on it.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Erik Frèrejean created an issue. See original summary.

Rop’s picture

If you enable the field in the 'Default' viewmode it works.

ziomizar’s picture

Attached patch solve the problem for me.

I did a check on the parameter before passing it to Drupal\ajax_comments\FieldSettingsHelper::isEnabled()

vierlex’s picture

I would be very interested in a solution which lets you configure the commented entities display mode, which is hardcoded as 'full' (in in the function itself defaults to 'default') as already mentioned..

I cant seem to figure out a way to get the currently rendered view_mode of the parent entity at those 4 points in the code the current patch is editing to get rid of an error.

proweb.ua’s picture

in Drupal 8.4.3 + ajax_comments 8.x-1.0-beta1
when the comment field isn't in the "full" view mode, i see error

TypeError: Argument 1 passed to Drupal\ajax_comments\FieldSettingsHelper::isEnabled() must implement interface Drupal\Core\Field\FormatterInterface, boolean given, called in /var/www/html/modules/contrib/ajax_comments/ajax_comments.module on line 44 in Drupal\ajax_comments\FieldSettingsHelper->isEnabled() (line 160 of /var/www/html/modules/contrib/ajax_comments/src/FieldSettingsHelper.php) #0 /var/www/html/modules/contrib/ajax_comments/ajax_comments.module(44): Drupal\ajax_comments\FieldSettingsHelper->isEnabled(false) 
#1 /var/www/html/core/lib/Drupal/Core/Extension/ModuleHandler.php(501): ajax_comments_comment_links_alter(Array, Object(Drupal\comment\Entity\Comment), Array) 
#2 /var/www/html/core/modules/comment/src/CommentLazyBuilders.php(148): Drupal\Core\Extension\ModuleHandler->alter('comment_links', Array, Object(Drupal\comment\Entity\Comment), Array) 
#3 [internal function]: Drupal\comment\CommentLazyBuilders->renderLinks('5', 'token', 'uk', false) 
#4 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(358): call_user_func_array(Array, Array) 
#5 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) 
#6 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render(Array, true) 
#7 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(576): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() 
#8 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#9 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain(Array) 
#10 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(661): Drupal\Core\Render\Renderer->renderPlaceholder('<drupal-render-...', Array) 
#11 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(546): Drupal\Core\Render\Renderer->replacePlaceholders(Array) 
#12 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) 
#13 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true) 
#14 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(576): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() 
#15 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#16 /var/www/html/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(258): Drupal\Core\Render\Renderer->renderRoot(Array) 
#17 /var/www/html/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse)) 
#18 /var/www/html/modules/contrib/http2_server_push/src/Render/HtmlResponseAttachmentsProcessor.php(48): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse)) 
#19 /var/www/html/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\http2_server_push\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse)) 
#20 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(108): Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) 
#21 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(193): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent)) 
#22 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(175): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1) 
#23 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#24 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#25 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#26 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#27 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#28 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#29 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#30 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#31 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(657): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#32 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#33 {main}.

patch #3 does not fix the bug

SocialNicheGuru’s picture

Status: Needs review » Needs work

Same as number 5

nedjo’s picture

Issue summary: View changes

Currently the implementation is attached to field configuration in node view modes, which introduces problems because it is in various comment contexts that we need to determine whether/how the behaviour should apply. An alternative that might address this issue (albeit with significant refactoring) is to make AJAX comments instead a property of comment view modes.

Updating the issue summary accordingly.

darvanen’s picture

The hard-coding of view_mode definitely needs to go, and I don't see an easy way to do that without a new architecture because comments can be viewed on their own without the commented entity being called (and therefore no way to specific a view mode).

I agree with @nedjo.

dqd’s picture

An alternative that might address this issue (albeit with significant refactoring) is to make AJAX comments instead a property of comment view modes.

1+ !

qzmenko’s picture

Status: Needs work » Closed (duplicate)

At the moment, an attempt is being made to solve the problem in another issue #2896916: Ajax not working when using non-default view mode.