Skip to content
Snippets Groups Projects
Commit 507b19c7 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

Issue #3494404 by just_like_good_vibes, grimreaper: Add "data from a field"...

Issue #3494404 by just_like_good_vibes, grimreaper: Add "data from a field" source to variant prop type
parent 4ff25e45
No related branches found
No related tags found
1 merge request!300Resolve #3494404 "Add data from"
Pipeline #372329 passed
......@@ -189,6 +189,7 @@ class ComponentForm extends ComponentFormBase {
$component = static::getComponent($element);
if (isset($component->metadata->schema['properties']['variant'])) {
$element['variant_id'] = self::buildComponentVariantSelectorForm(
$element,
$component_id,
$element['#default_value']['variant_id'] ?? NULL,
);
......@@ -239,6 +240,7 @@ class ComponentForm extends ComponentFormBase {
* The variant select.
*/
private static function buildComponentVariantSelectorForm(
array $element,
string $component_id,
array|NULL $default_variant_id,
): array {
......@@ -249,6 +251,10 @@ class ComponentForm extends ComponentFormBase {
"#component_id" => $component_id,
"#prop_id" => 'variant',
'#default_value' => $default_variant_id,
'#source_contexts' => $element['#source_contexts'],
'#tag_filter' => $element['#tag_filter'],
'#ajax_url' => $element['#ajax_url'] ?? NULL,
'#wrap' => TRUE,
];
}
......
......@@ -17,6 +17,7 @@ use Drupal\ui_patterns\PropTypePluginBase;
label: new TranslatableMarkup('Variant'),
description: new TranslatableMarkup('Prop type for component variants.'),
default_source: 'select',
convert_from: ['string'],
schema: ['type' => ['string'], 'enum' => []],
priority: 1
)]
......@@ -36,4 +37,13 @@ class VariantPropType extends PropTypePluginBase {
return static::normalizeEnumValue($value, $enum);
}
/**
* {@inheritdoc}
*/
public static function convertFrom(string $prop_type, mixed $value): mixed {
return match ($prop_type) {
'string' => (string) $value,
};
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment