[message:field_node_reference:entity:url] is not alias path

Created on 6 June 2020, about 4 years ago
Updated 30 January 2024, 5 months ago

Hi,

I am using [message:field_node_reference:entity:url] token in Partial 1 for body message.

I generate message with hook_node_insert.

Message shows /node/xxx but and It does not show alias.

What is It wrong?

Thanks in advance.

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain rafaticarte

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¬πŸ‡§United Kingdom philipnorton42 Cheshire

    I found this problem as well, but I found that it was connected to a different problem, with a few moving parts.

    By default the path auto system will return a non-aliased path if the language isn't defined (i.e. the language is "und"). This means that this code will return the path "/node/123".

    \Drupal::service('path_alias.manager')->getAliasByPath('/node/1', 'und');`
    

    To get the correct path the language needs to be stipulated. This code will return the correct aliased path of the node.

    \Drupal::service('path_alias.manager')->getAliasByPath('/node/1', 'end');`
    

    I'm running a non-multilingual site and I was using the output on the page /admin/content/messages to test the templates. They would always show as having the incorrect path of "/node/123" due to this issue. The problem is that the page at /admin/content/messages does not pass a language to the getText() method when rendering the message entity. When this happens the getText() method just uses the default of "und", which introduces this issue.

    When I created a view to print out the messages everything worked correctly.

    I can see two avenues to correct this, but I'm not sure which one is best as I'm not exactly familiar with the module.

    1) Alter MessageListBuilder::buildRow()

    When calling getText(), pass in the language of the message entity. Something like this:

    $text = $entity->getText($entity->get('langcode')->value);
    

    2) Alter Message::getText()

    During the running of getText() it looks to see if the language has been set, this could be changed to force the language to come from the message entity itself.

        if (!$langcode) {
          $langcode = $this->get('langcode')->value;
        }
    

    As I said, I'm not sure which is the best approach here. I'm thinking that altering getText() might have some far reaching consequences. If anyone has an opinion then let me know and I'll create a patch :)

  • πŸ‡ΊπŸ‡ΈUnited States eeyorr

    FWIW, I had this issue with a different entity token, but when I use [entity:url:relative], I get the aliased path.

  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024