Problem/Motivation

We've been successfully using the SDC Display module for a while and it worked great; however, we've recently faced an issue where we haven't been able to implement the link to the node rendered with SDC Display.

In a traditional templates-based approach, a few extra variables like the entity object, URL, etc are available; however, this is not the case for SDC Display.

Steps to reproduce

1. Create the SDC with an entity URL field.
2. Enable SDC Display for the node display.
3. Try to map the node URL to the display.
Expected: able to pass in the entity URL in the component.
Actual: it's not possible.

Proposed resolution

Two possible approaches:
1. Implement mapping some basic variables like entity ID, revision ID, entity type, entity object (as slot?), URL, title, display mode... you name it.
2. Go with tokens instead.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

abramm created an issue. See original summary.

pcambra’s picture

e0ipso’s picture

I think the tokens road is the my preferred, but I could go both ways.

attiks made their first commit to this issue’s fork.

attiks’s picture

Status: Active » Needs review

Ran into the same problem, needed the URL of the entity when using the display.

pcambra’s picture

Version: 1.x-dev » 2.x-dev
grumpydev74’s picture

As a workaround, you could still add a field to host those values on the node (hide them in the node form) and use hook_node_view to alter the fields values and set the required values (the hook has access to the node entity).

But I’m agree, it would be great to have those values available out of the box. As well, it would be a good idea to allow pseudo fields to be used in the SDC display mapping.

pcambra’s picture

Taking a look a this, we can easily fall into entities that do not have canonical URLs

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 211 of core/lib/Drupal/Core/Entity/EntityBase.php). 

I think it is ok to pass id, entity_type and bundle, but we should remove URL and leave that for #3377609: Implement Token Replacements

pcambra’s picture

  • pcambra committed 5c73ea0e on 2.x authored by attiks
    Issue #3462243 by pcambra, attiks: Passing the entity object/ID/URL into...
pcambra’s picture

Status: Needs review » Fixed

Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.