The 'Page entity label' Views field conveniently checks the type of the entity containing the link and if it's a paragraph, displays the label of the paragraph's parent, and also links to it if there is a canonical link.

Unfortunately this doesn't handle nested paragraphs - e.g. a paragraph within a paragraphs field (e.g. some kind of container/layout paragraph). Patch attached continues getting paragraph parents while they're available, until the root parent is obtained (which will usually be of a type with a canonical link).

Comments

bgilhome created an issue. See original summary.

devkinetic’s picture

I second this patch, and implemented similar logic over on #3294846: Expose the url to the entity for Views

kle’s picture

PLEASE PLEASE
add this small change to LinkcheckerLinkPageEntityLabel.php

even in the Drupal-10 Version
########################

vistree’s picture

I agree. The problem still exists in current version. The patch seems to be clear and small. Why not commit to stable version of the module?

gwvoigt’s picture

+1 for commiting

eiriksm’s picture

Status: Needs review » Needs work
Issue tags: +Needs merge request, +Needs tests

This needs to be in a merge request, and it needs tests before being committed

Thanks everyone for working on it and testing ✌️🤓

vistree’s picture

I recognised today that the language of the parent node is not always the correct one. I have a site with DE + EN - where DE is the default language.
If the parent entity is also a paragraph, I will always get a link to the DE version of the top level node - even the link is on the EN version.

Could we use something like:

while ($linked_entity->getEntityTypeId() === 'paragraph' && $linked_entity->getParentEntity() !== NULL) {
      $parent = $linked_entity->getParentEntity();
      if ($parent instanceof TranslatableInterface && $linked_entity instanceof TranslatableInterface) {
        $parent = \Drupal::getContainer()->get('entity.repository')->getTranslationFromContext($parent, $linked_entity->language()->getId());
      }
      $linked_entity = $parent;
    }

    if ($linked_entity instanceof TranslatableInterface) {
      $langcode = $linkchecker_link->get('entity_langcode')->value;
      $linked_entity = \Drupal::getContainer()->get('entity.repository')->getTranslationFromContext($linked_entity, $langcode);
    }

    if (!empty($this->options['link_to_entity'])) {
      try {
        $url_options = [];
        if ($linked_entity instanceof TranslatableInterface) {
          $url_options['language'] = $linked_entity->language();
        }
        $this->options['alter']['url'] = $linked_entity->toUrl('canonical', $url_options);
        $this->options['alter']['make_link'] = TRUE;
      }
      catch (UndefinedLinkTemplateException $e) {
        $this->options['alter']['make_link'] = FALSE;
vistree’s picture

Please ignore my last comment. I figured out that not the translation is the problem - instead orphaned paragraphs are processed by linkchecker. I will try to find a fix for this!

claudiu.cristea’s picture

I would use the same code from LinkcheckerLinkPageEntityLink

    while ($linked_entity instanceof ParagraphInterface && $linked_entity->getParentEntity() !== NULL) {
      $linked_entity = $linked_entity->getParentEntity();
    }