A themer can use different templates for action links depending on the link route

Created on 17 September 2024, 3 months ago

Problem/Motivation

Used an action link in a non-admin theme, and it put it inside list item li tags without any surrounding ordered or unordered list.

Also i'd like to add a class.

πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mlncn
    • mlncn β†’ committed cd252ba6 on 8.x-1.x
      Issue #3475003 by mlncn: A themer can use different templates
      
    • mlncn β†’ committed 1edb5a36 on 8.x-1.x
      Issue #3475003 by mlncn: Make each part of route a suggestion
      
  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    For THEME HOOK: 'menu_local_action' for an action link to the Entity Print view, we now have two new suggestions:

     FILE NAME SUGGESTIONS:
       β–ͺ️ menu-local-action--entity-print--view.html.twig
       β–ͺ️ menu-local-action--entity-print.html.twig
       βœ… menu-local-action.html.twig
    
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    There is not a direct way to addClass to the link part of the action link template but you can if you are unhealthily committed to doing things only in templates, you can do the holy hell that is this:

    {#
    /**
     * @file
     * Theme override for a single local action link.
     *
     * Available variables:
     * - attributes: HTML attributes for the wrapper element.
     * - link: A rendered link element.
     *
     * @see template_preprocess_menu_local_action()
     */
    #}
    {% set link = link|merge({
      '#options': link['#options']|merge({
        'attributes': link['#options']['attributes']|merge({
          'class': link['#options']['attributes']['class']|merge(
            ['btn']
          )
        })
      })
    }) %}
    <p{{ attributes }}>{{ link }}</p>
    

    But i recommend doing like is done here, using the preprocess hook, instead: https://agaric.coop/blog/adding-bootstrap-button-stylings-drupal-8s-acti...

Production build 0.71.5 2024