Problem/Motivation

When putting a "Configured" value under the form display for the button component, specifically for the "Variant" it does not seem to flow through to the frontend/twig template. This does not occur for other attributes like the "Outline?" field.

Steps to reproduce

I've created a starterkit theme and have not modified it.
Configured a form display of the button component putting the label, size, and url in the "Prop/Slot" section. And put the Variant and Outlined in the "Configured" section, selecting "Secondary" for the Variant.

Latest dev branch / Drupal 11.2

This is not an issue if you expose variant on the form, only if you attempt to use the configured section to set a preset/default.

Config export of ui_patterns_ui.component_display.ui_suite_daisyui.button.secondary.yml:

uuid: 08688978-caf5-4f58-a5ac-5f2fd8be2ec9
langcode: en
status: 1
dependencies: {  }
id: ui_suite_daisyui.button.secondary
label: Secondary
component_id: 'ui_suite_daisyui:button'
form_mode_name: secondary
content:
  url:
    widget_settings: {  }
    source_id: url
    parent: ''
    weight: '1'
    region: content
    third_party_settings: {  }
  outline:
    widget_settings: {  }
    source_id: select
    source:
      value: outline
    parent: ''
    weight: '4'
    region: configure
    third_party_settings: {  }
    settings: {  }
  size:
    widget_settings:
      title: Size
      title_display: before
      description: 'It is possible to set the size of buttons.'
      description_display: after
      required: 0
    source_id: select
    parent: ''
    weight: '2'
    region: content
    third_party_settings: {  }
    settings: {  }
  link:
    widget_settings: {  }
    source_id: checkbox
    source:
      value: false
    parent: ''
    weight: '3'
    region: configure
    third_party_settings: {  }
    settings: {  }
  variant:
    widget_settings: {  }
    source_id: select
    source:
      value: secondary
    parent: ''
    weight: '5'
    region: configure
    third_party_settings: {  }
    settings: {  }
  label:
    widget_settings: {  }
    source_id: wysiwyg
    parent: ''
    weight: '0'
    region: content
    third_party_settings: {  }
hidden:
  attributes: true
  shape: true
  responsive: true
  soft: true
  display: true
  status: true
  ghost: true
  modal_id: true
  drawer_id: true
  icon: true
  icon_position: true

Rendered markup with that setup:

<a data-component-id="ui_suite_daisyui:button" class="btn btn-outline btn-lg" href="https://google.com" role="button">
    <p>Secondary Button</p>
</a>

Workaround to set the value for the frontend, looking at what I'm assuming are the form IDs I've setup, looking at it in xdebug wasn't seeing the variant that was configured in the form display anywhere obvious:

/**
 * Implements hook_ui_patterns_component_pre_build_alter().
 */
function hook_ui_patterns_component_pre_build_alter(array &$element): void {
  // Workaround for variant not persisting into the template.
  if (!empty($element['#component']) && $element['#component'] === 'ui_suite_daisyui:button') {
    if (empty($element['#ui_patterns']['variant_id'])) {
      if (isset($element['#ui_patterns']['display_id'])) {
        if ($element['#ui_patterns']['display_id'] === 'ui_suite_daisyui.button.primary') {
          $element['#ui_patterns']['variant_id'] = [
            'source' => [
              'value' => 'primary',
            ],
            'source_id' => 'select',
          ];
        }
        if ($element['#ui_patterns']['display_id'] === 'ui_suite_daisyui.button.secondary') {
          $element['#ui_patterns']['variant_id'] = [
            'source' => [
              'value' => 'secondary',
            ],
            'source_id' => 'select',
          ];
        }
      }
    }
  }
}
CommentFileSizeAuthor
#4 daisy-ui-button.png838.11 KBgcalex5
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

gcalex5 created an issue. See original summary.

gcalex5’s picture

Issue summary: View changes
g4mbini’s picture

Am not to get what you want to achieve ... Can you send me screenshots of the form widget with some visual indications ?

gcalex5’s picture

StatusFileSize
new838.11 KB

The issue here is that when configuring the "variant" on a form display it doesn't make it to the twig template that the daisy ui theme provides. Attached is an image showing where I attempt to set that configured value.

This extends to the Alert component as well, and guessing all others with a Variant at this point, only when setting up form displays to try and do some presets. On the default non-configured component form, this issue does not present.

g4mbini’s picture

Issue tags: +UI Suite Initiative

Ah ok so you are using UI Patterns UI. I notice the same issue on my side.

This issue seems related to this UI Patterns sub-module that is experimental...

Let's move it to UI Patterns issue queue ;)

g4mbini’s picture

Project: UI Suite DaisyUI » UI Patterns (SDC in Drupal UI)
Version: 5.0.x-dev » 2.0.9
g4mbini’s picture

Component: Code » UI Patterns UI
christian.wiedemann’s picture

Ah yes I see. Is an easy fix.

christian.wiedemann’s picture

Assigned: Unassigned » christian.wiedemann
christian.wiedemann’s picture

Title: Button Variant » [2.0.10] Button Variant

christian.wiedemann’s picture

Assigned: christian.wiedemann » just_like_good_vibes
Status: Active » Needs review
christian.wiedemann’s picture

Hi @gcalex5 can you check. @just_like_good_vibes can you have a short look.

gcalex5’s picture

Disabled the alter hook I had in the OP, cleared caches, applied the diff from MR 435. Confirmed that fixes it.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » christian.wiedemann
Status: Needs review » Reviewed & tested by the community

good for merge

pdureau’s picture

Title: [2.0.10] Button Variant » [2.0.11] Button Variant

christian.wiedemann’s picture

Assigned: christian.wiedemann » Unassigned
Status: Reviewed & tested by the community » Fixed

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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