Url schema processing breaks component usage in templates

Created on 2 March 2025, 10 days ago

Problem/Motivation

I am trying to define a URL as a property in my component:

props:
  type: object
  properties:
    url:
      "$ref": ui-patterns://url

If I want to use this property in a story, I enter a string, which works perfectly. The string is converted into a url object as expected.

name: Button
component: "my_theme:button"

props:
  url: "https://www.example.com"

the drupal uri schema does not work. Shouldn't this one be just as applicable?

name: Button
component: "my_theme:button"

props:
  url: "internal:/<front>"

Now I want to use my component within Drupal. So I pass a URL object in my template (not SDC, but within e.g. node.html.twig) into my button component. However, a string is now accepted.

  {%- include "my_theme:button" with {
    label: 'label',
    url: url,
  } only -%}

Is there something wrong with this concept? I am assuming that I am transferring a URL object.

Another but related question: In addition, I want to use the Drupal link function ‘{{ link() }}’ within my component, into which I then pass my URL object. This accepts a URL object as the URL parameter, as I expect.

The sdc_devel module shows me the error:
‘Forbidden Twig function: `link`. PHP URL object, or useless if URL string.’

I would have assumed that the function within Drupal should always be used in preference to hardcoding links. Otherwise I have no possibility to process these links in processing (for example when checking permissions).

Have I not understood something about the basic concept of UI patterns? :)

💬 Support request
Status

Active

Version

2.0

Component

UI Patterns Library

Created by

🇩🇪Germany hauke-vq Berlin, Germany

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

Comments & Activities

  • Issue created by @hauke-vq
  • 🇩🇪Germany hauke-vq Berlin, Germany

    I have now realised that everything works as it should. What I don't understand is why a URL is converted into a string and why I can't use it in functions like link(). If I build links hardcoded together "href=‘{{ url }}", then I no longer have reasonable link handling.

    But this is not a problem of UI-Patterns, but is ultimately covered by the Drupal core.

Production build 0.71.5 2024