Unable to use lazy builders for individual links in hook_node_links_alter(), hook_comment_links_alter()

Created on 11 October 2015, about 9 years ago
Updated 29 March 2024, 9 months ago

Over at Flag module, we need to add the flag links to node and comment links.

Because the link is different for each user, and changes if the flag status changes, it can't be cached with the node, or the node links, and instead needs to be built with a lazy builder.

We've got this working with the link that appears a pseudofield, because that gets its own render array. But hook_node_links_alter() gives us a $links array which is passed to theme_links(), so it doesn't seem that it's possible to do this at the moment.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated about 8 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

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 joachim

    I've got this working!

    You do:

    $placeholder = Crypt::hashBase64(something unique);
    
    $links['mythings'] = [
      '#theme' => 'links__node__mystuff',
      '#links' => [
        'mykey' => [
          'title' => $placeholder,
        ]
      ],
    ];
    
    $links['#attached']['placeholders'][$placeholder] = [
      '#lazy_builder' => [
        // The lazy builder callback and parameters.
        'lazybuildercallback',
        [
          // lazy builder params
        ],
      ],
    ];
    
Production build 0.71.5 2024