Hi there!

I have been using paragraphs quite successfully but there is an issue with comments + paragraphs. Right now I have a content type called consultation which has paragraphs of type idea which is just a bunch of text fields + comments fields. Everything works I am able to successfully get comments attached to paragraphs through migrate. I have highlighted an example below showing this all working. Additionally all of my fields are properly instantiated.

The problem is while I can edit existing comments, I can't reply or add new comments without getting the following error:

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\Entity->toUrl() (line 214 of core/lib/Drupal/Core/Entity/Entity.php).

I recall seeing that this is perhaps an issue with core as paragraphs doesn't implement an $entity->uri. However this would currently mean comments just don't work with paragraphs. I was hoping for some direction as to how to solve this, as I really would prefer to not jump back to inline_entity_form for this edge case.

Thanks for the great module and any assistance you could provide :)

Comments

sylus created an issue. See original summary.

sylus’s picture

Issue summary: View changes
sylus’s picture

Issue summary: View changes
sylus’s picture

I think based on other issues that I would have to look inside the comment module to correct this behavior? But even then wouldn't some logic need to be added to instead check from the host entity? I don't think comment should have to handle that kind of logic?

That leads me to think that this should be solved in paragraphs itself. I know paragraphs has a few issues with how core dictates functionality but adding a comment field with paragraphs should be a fairly common use case.

Happy to help however I can, but just need to be pointed in the right direction. Thanks again!

thenchev’s picture

Status: Active » Needs review
StatusFileSize
new804 bytes

@sylus
Can you try this patch and let me know if it solves your problem?

We discovered something similar i think. When you add a field (plain not formatted) in a paragraphs type and in Managed display check Link to the Paragraph then you get similar error massage about canonical link template missing.

Not sure if this is the right approach but it solves our problem...
With this you can access a paragraph on paragraphs/{some_id} witch might not be desired behavior.

sylus’s picture

Hi @Denchev ^_^,

Greatly appreciated!

That did immediately resolve all of my issues with commenting. Can now edit / reply / delete without issue. :)

I'm tempted to mark this RTBC but also not sure whether the maintainers would accept this. It does seem that more then a few issues in the queue could benefit from this being added.

Either way I really appreciate the patch :)

thenchev’s picture

I just noticed the other related issue. Yea I guess this needs to be fixed in core, this probably wont be committed but here it is if someone needs it to avoid the nasty error.

berdir’s picture

This came up before, but I'm not conviced about just adding a default link. that will display that paragraph on /paragraph/1 but that makes no sense.

The only thing that might make sense is redirecting that to the node the paragraph is shown, but not sure about the.

The image issue also already has a duplicate somewhere.

I still think that code should not hardcode the assumption that there is a canonical link template although core now documents that somehow now.

sylus’s picture

Thanks @berdir for your feedback, I don't suppose you could highlight how we would redirect to the parent entity?

I'm just interested in having comment functionality working with paragraphs, or a clear statement saying they are incompatible :)

sylus’s picture

So for this would the correct approach be extending the "DefaultHtmlRouteProvider" class and then overriding the getCanonicalRoute method?

Edit: Unfortunately it seems we don't get enough information in that context to get the parent entity type.

miro_dietiker’s picture

@Berdir if implementing such a "workaround" would be the right approach, then core should be cristal clear and require all entities to provide such a route. If not, we are doing the right thing to not provide it.

There is a related issue where the core quick edit requires each entity to provide a form and only providing those routes solves half of the integration.

What we do with Entity Reference Revision, is defining new integrity constrains and extend the concepts of the entity subsystem. We try to be transparent, but as core is not aware if composite relationship concept, we have limitations. Combined with other dimensions where core has limitations (multilingual, revisions, recently workflows / workspaces) the integration complexity is gaining crazy complexity.

Whatever silently assumes wrongly there is always such an URI is technically "incompatible" with Peargraphs. ;-)

To workaround the problem for the impatient people, adding a extra project / module that defines the routes could be the best approach. The workaround with a redirect route has other faux impacts, including code that determine an entity "canonical" by using "==" comparing the route with the entity uri.

Alternatively, we could try to return an uri to the host entity with an anchor address to the DOM id. Not sure if drupal likes these kind of canonicals.

arnaud-brugnon’s picture

Patch #6 works for me.

But i agree that redirect to "/paragraph/{ID}" is quite annoying.

Like i need something now, i made this small code.

use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Url;
function module_comment_insert(Drupal\Core\Entity\EntityInterface $comment) {
  $content_comment = $comment->getCommentedEntity();
  $content_comment_type = $content_comment->getType();
  
  // If comment is set on my custom paragraph
  if($content_comment_type == 'prestation') {
    // I redirect to parent entity
    $url = Url::fromRoute('entity.node.canonical', ['node' => $content_comment->getParentEntity()->id()])->toString();
    $response = new RedirectResponse($url);
    $response->send();
  }
}
siddhant.bhosale’s picture

StatusFileSize
new804 bytes

I have re-rolled the #06 patch with the latest version.

Status: Needs review » Needs work

The last submitted patch, 14: comments_entity_uri-2878615-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rokzabukovec’s picture

I created a patch for the Drupal core that should solve this issue. It looks at the parent entity of the paragraph if the URI callback is not valid.
Paragraphs with comment field results in UndefinedLinkTemplateException.

Please review.

j1mb0b’s picture

StatusFileSize
new852 bytes

Patch re-rolled.

berdir’s picture

Category: Bug report » Support request
Status: Needs work » Fixed

Well, that is closed, and so should this issue. It's a duplicate of the core issue that you commented on as well, because paragraphs module isn't going to accommodate comment.module by adding this. As others commented, having the paragraph then on its own page is weird.

What you could do as a workaround in a project is add a canonical link template that redirects back to the host node of the paragraph.

dpi’s picture

One potential solution is using Entity Bundle Classes, add your own bundle class Comment entity, and override getCommentedEntity() or whichever method, rewriting to the paragraph parent.

dravenk’s picture

Status: Fixed » Needs work

When a page displays a fatal error, it is really hard to believe is a Fixed issue. It's should fix on the Paragraph module or the Comment module. If the user is not allowed to use Paragraph and Comment together, it should be disabled before the user adds the Comment field to the Paragraph.
The website encountered an unexpected error. Please try again later.