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',
];
}
}
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | daisy-ui-button.png | 838.11 KB | gcalex5 |
Issue fork ui_patterns-3548222
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
Comment #2
gcalex5 commentedComment #3
g4mbiniAm not to get what you want to achieve ... Can you send me screenshots of the form widget with some visual indications ?
Comment #4
gcalex5 commentedThe 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.
Comment #5
g4mbiniAh 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 ;)
Comment #6
g4mbiniComment #7
g4mbiniComment #8
christian.wiedemann commentedAh yes I see. Is an easy fix.
Comment #9
christian.wiedemann commentedComment #10
christian.wiedemann commentedComment #12
christian.wiedemann commentedComment #13
christian.wiedemann commentedHi @gcalex5 can you check. @just_like_good_vibes can you have a short look.
Comment #14
gcalex5 commentedDisabled the alter hook I had in the OP, cleared caches, applied the diff from MR 435. Confirmed that fixes it.
Comment #15
just_like_good_vibesgood for merge
Comment #16
pdureau commentedComment #18
christian.wiedemann commented