Problem/Motivation

Hi,

I think it would be nice that in ui_patterns/src/Plugin/UiPatterns/Source/AttributesWidget.php a token could be used, for example to create a button with a title attribute with [node:title].

Example:
tokens in Attributes

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

grimreaper created an issue. See original summary.

rajab natshah’s picture

This would be so nice. Thanks a lot, Florent, for filing the issue.

I faced an issue with Read more link or Learn more link in a call to action button
My current status is

The optimal target to work with

aria-label="[node:field_link:title] about [node:title]" target="_parent"

A common accessibility challenge arises when multiple identical links (e.g., "Read Article") appear on a page. Without additional context, screen reader users may struggle to distinguish between links. ARIA attributes, such as aria-label, allow developers to add meaningful descriptions to links, ensuring clarity and context.

Helpful resource: What the Heck is ARIA A Beginner's Guide to ARIA for Accessibility - Kat Shaw (A11yTalks - Aug 2024)

Thanks to A11yTalks and Kat Shaw for this!

Enhancing "Read Article" Links for Accessibility
Replace generic "Read Article" links with meaningful ARIA labels:

<a aria-label="Read the full article of {{ title }}">Read Article</a>

If the link text changes to "Learn more", "Read more", or "Click", the {{ title }} token will still help maintain context for screen reader users.

rajab natshah’s picture

Title: Attributs prop type source replaces token » Add Support for Attributes Prop Type Source Replacing Token Values

rajab natshah’s picture

Status: Active » Needs review

First Draft MR - Integration with the Token module

rajab natshah’s picture

Tested with

aria-label="[node:field_link:title] about [node:title]" target="_parent"
rajab natshah’s picture

Attached a static ui_patterns--2025-05-16--3496209--mr-378.patch file to this point in MR378
To be used with Composer Patches

pdureau’s picture

Status: Needs review » Needs work

Hi Rajab,

Thanks for the MR, it is very exciting.

2 feedbacks:

  • Do we really need dependency to the contrib token module? Core Token API is not enough?
  • Can you add an automatic test with aria-label="[node:field_link:title] about [node:title]" target="_parent"?
pdureau’s picture

Title: Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.4] Add Support for Attributes Prop Type Source Replacing Token Values
rajab natshah’s picture

Thanks, Pierre, for the quick review.

1- I will test that - you are right. ( testing, then to change if needed)
2- For sure, we need

  • Automated unit testing coverage
  • Automated functional testing coverage

( WIP )

3- UI Patterns 2.0 Docs -- the doc in code is so nice by the way!!

  • Documentation

4- We may need to do a small UX/UI designer responsibilities - to hint site builders so that they can use tokens.

rajab natshah’s picture

Assigned: Unassigned » rajab natshah
Status: Needs work » Active
pdureau’s picture

Great plan!

pdureau’s picture

Title: [2.0.4] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.5] Add Support for Attributes Prop Type Source Replacing Token Values
pdureau’s picture

Title: [2.0.5] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.6] Add Support for Attributes Prop Type Source Replacing Token Values
pdureau’s picture

Title: [2.0.6] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.7] Add Support for Attributes Prop Type Source Replacing Token Values
pdureau’s picture

Title: [2.0.7] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.8] Add Support for Attributes Prop Type Source Replacing Token Values
just_like_good_vibes’s picture

hello,
thank you for your work, indeed this is a nice usecase :)
Today we have some code in Token source, if we plan to generalize it in other sources like Attributes, it would be good to rely on the same code in those sources.
i suggest that factorize some appropriate code about tokens, somewhere.
In a trait or directly in the SourcePluginBase ? @Christian, others, what do you think ?

do we need tokens elsewhere? maybe yes.

just_like_good_vibes’s picture

Hello rajab natshah,
thanks to your issue, we though to introduce a more deeper support for tokens in ui patterns sources.
so we will introduce a shared code to deal with tokens here : https://www.drupal.org/project/ui_patterns/issues/3540970

rajab natshah’s picture

Thanks to Florent first
I'm with your direction Mikael, for the deeper support for tokens.

General deep token integration is needed:
1- UI - so important ( for configs )
2- Twig - it will help a lot ( but we are moving to use UI Patterns as the default UI mapper )
3- Auto token change in .component.yml files could help in some cases - if we allow for that like ActiveThemeChangeSubscriber.php
4- Tokens like DEFAULT_ACTIVE_THEME , default_theme could help when switching themes with old View modes, Views being used with an old theme, which has to move to the new theme ( VMI link )

just_like_good_vibes’s picture

Title: [2.0.8] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.9] Add Support for Attributes Prop Type Source Replacing Token Values
just_like_good_vibes’s picture

Title: [2.0.9] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.10] Add Support for Attributes Prop Type Source Replacing Token Values
rajab natshah’s picture

rajab natshah’s picture

Title: [2.0.10] Add Support for Attributes Prop Type Source Replacing Token Values » [2.0.10] Add token replacement support to AttributesWidget using new centralized token and normalizer services from SourcePluginBase
rajab natshah’s picture

Oh may, the new method is so clean.
Done the needed refactor.

Example test after the change:
tokens in Attributes

rajab natshah’s picture

Assigned: rajab natshah » Unassigned
Status: Active » Needs review
pdureau’s picture

Title: [2.0.10] Add token replacement support to AttributesWidget using new centralized token and normalizer services from SourcePluginBase » [2.0.11] Add token replacement support to AttributesWidget using new centralized token and normalizer services from SourcePluginBase
just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes

hello, i see the issue is in need review,
i will
grab it now if it needs review,
thank you

ipumpkin’s picture

Status: Needs review » Reviewed & tested by the community

Nice featue to included

just_like_good_vibes’s picture

Title: [2.0.11] Add token replacement support to AttributesWidget using new centralized token and normalizer services from SourcePluginBase » Add token replacement support to AttributesWidget using new centralized token and normalizer services from SourcePluginBase

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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