Overview

We need to allow creating links within code components. This probably means we need to have a URL prop type. However, this may not be enough since we need to figure out how do we generate the actual href value needed out of the URL.

Proposed resolution

Provide an example of how to create links within code components.

User interface changes

CommentFileSizeAuthor
#9 xb-code-component-link-prop.gif10.68 MBbalintbrews
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

lauriii created an issue. See original summary.

wim leers’s picture

The back-end already allows this:

# @see https://json-schema.org/understanding-json-schema/reference/strings
experience_builder.json_schema.prop.string:
…
    format:
      requiredKey: false
      type: string
      label: 'Format'
      constraints:
        Choice:
          # @see https://json-schema.org/understanding-json-schema/reference/type#built-in-formats
          # @see Drupal\experience_builder\JsonSchemaInterpreter\JsonSchemaStringFormat::computeStorablePropShape()
          - date-time
          - date
          - email
          - idn-email
          - uri
          - uri-reference
          - iri
          - iri-reference

So it's just a matter of adding something like:

diff --git a/ui/src/features/code-editor/component-data/Props.tsx b/ui/src/features/code-editor/component-data/Props.tsx
index 6bc1e9a02..bd69a8e3e 100644
--- a/ui/src/features/code-editor/component-data/Props.tsx
+++ b/ui/src/features/code-editor/component-data/Props.tsx
@@ -55,6 +55,11 @@ const UI_PROP_TYPES: Record<string, UiPropType> = {
     displayName: 'Text area',
     _ref: 'json-schema-definitions://experience_builder.module/textarea',
   },
+  stringUrl: {
+    type: 'string',
+    displayName: 'URL',
+    format: 'uri',
+  },
   integer: { type: 'integer', displayName: 'Integer' },
   number: { type: 'number', displayName: 'Number' },
   boolean: { type: 'boolean', displayName: 'Boolean' },

… and wiring that up — like @hooroomoo did yesterday for textareas in #3507928: [Front-end] Allow adding "textarea" props in the code component editor.

wim leers’s picture

Note: this is purely about being able to create such props for code components.

It's not about the UX of entering links, for that we have #3499279: Make link widget autocomplete work (for uri and uri-reference props).

wim leers’s picture

Title: Add support for creating links within code components » Allow adding "URL" (`type: string, format: uri`) props in the code component editor
Related issues: +#3507929: Allow adding "image" props in the code component editor

Consistent naming 🤓

nagwani’s picture

Issue tags: +sprint
wim leers’s picture

Assigned: Unassigned » balintbrews

Bálint started working on this AFAIK.

balintbrews made their first commit to this issue’s fork.

balintbrews’s picture

Assigned: balintbrews » hooroomoo
Status: Active » Needs review
StatusFileSize
new10.68 MB

Link prop for code components

hooroomoo made their first commit to this issue’s fork.

hooroomoo’s picture

hooroomoo’s picture

Assigned: hooroomoo » Unassigned
Status: Needs review » Fixed
Issue tags: -sprint
wim leers’s picture

Assigned: Unassigned » balintbrews
Status: Fixed » Needs work

Awesome to see the old UI_PROP_TYPES object evolve into derivedPropTypes.ts 🔥

💯


But … 😅

I expected the relative path (see the example in the GIF in #9 and the Relative path link with example value hunk in the MR) to start with a slash.

IOW: I expected this to match

  • how \Drupal\path_alias\Entity\PathAlias stores path aliases
  • how the Content Creator enters a path aliases at e.g. /node/add/article in Drupal's Standard install profile
  • XB's all-props SDC test_string_format_uri_reference prop's example of /example-uri

Is the omission of the leading slash here intentional? If so: what's the rationale?

If it's not intentional: can we change it in a follow-up? 🙏

balintbrews’s picture

Status: Needs work » Fixed
Issue tags: +Needs followup

It was barely a UX decision I made, and since the validation (based on the JSON Schema definition) passed on those values, I forgot to match this how Drupal usually expects these. Let's change in a follow-up.

Status: Fixed » Closed (fixed)

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