Add attributes on the formatter level

Created on 12 November 2024, 4 days ago

Problem/Motivation

Link Attributes adds attributes on the field widget level, so each link in an entity can have additional attributes, classes, etc. That's super helpful!

But additionally, there's also often the need to set attributes (starting with simple classes) on the formatter level! So they will be same for the link field display and won't change per entity. These attributes can not be changed in entities, as they are set when rendering the field.

Link attributes already has a lot of related functionality and core is missing this feature, so that currently you have to override the link in theme or twig, which is okay, but not what you want from Drupal in many cases.

So we'd like to help implementing this (maybe in a submodule)? link_attributes_formatter?

https://www.drupal.org/project/link_class β†’ does similar things, but seems not very well maintainted and might conflict with link_attributes. Would be much nicer to have all this in link_attributes with known UX. And even by name it fits into "Link Attributes" :)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @larowlan if you're fine with the proposal, we'll start implementing this as submodule via MR.

  • Yes, please make this feature happen. Adding attributes to link fields is horrible on frontend.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Element class formatter does this too I think

    I'm happy with a sub-module, but we'd have to be mindful about how we merge values from the formatter with user supplied values.

    Perhaps we need options 'overrride user options' or 'user options override defaults'

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks for the feedback @larowlan that's wonderful news!

    Yes I think one of the key benefits is to have that control in one module. For the beginning, I'd say we should simply merge and unify them, not overriding anything. For the future we should then see, if there are cases where overriding into one or the other direction makes sense as an option? (YAGNI)

    It's planned to start here soon! :)

  • Pipeline finished with Success
    2 days ago
    Total: 175s
    #338316
Production build 0.71.5 2024