From aef08e90785a2e4c4b64d6a02ef24a98dd7d63f0 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa <florent.torregrosa@gmail.com> Date: Fri, 2 Aug 2024 13:19:59 +0200 Subject: [PATCH] Issue #3465432 by pdureau, Grimreaper: [2.0.0-beta1] empty variants in pattern() Twig function --- modules/ui_patterns_legacy/src/Template/TwigExtension.php | 8 +++++++- src/ComponentPluginManager.php | 1 - src/Plugin/UiPatterns/PropType/VariantPropType.php | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/ui_patterns_legacy/src/Template/TwigExtension.php b/modules/ui_patterns_legacy/src/Template/TwigExtension.php index 58ebc0036..220fdaef8 100644 --- a/modules/ui_patterns_legacy/src/Template/TwigExtension.php +++ b/modules/ui_patterns_legacy/src/Template/TwigExtension.php @@ -56,8 +56,14 @@ class TwigExtension extends AbstractExtension { $element = [ '#type' => 'pattern', '#id' => $id, - '#variant' => $variant, ]; + + // Variant is a JSON-schema enum where empty string is not always allowed. + // Moreover, we don't allow empty variant. + if (!empty($variant)) { + $element['#variant'] = $variant; + } + // We use the compact format, so it will be resolved by // RenderableConverter::resolveCompactFormat() before being converted to // the SDC format. diff --git a/src/ComponentPluginManager.php b/src/ComponentPluginManager.php index cbec4c449..768b7cc2f 100644 --- a/src/ComponentPluginManager.php +++ b/src/ComponentPluginManager.php @@ -163,7 +163,6 @@ class ComponentPluginManager extends SdcPluginManager implements CategorizingPlu } return [ 'title' => 'Variant', - 'type' => 'string', '$ref' => "ui-patterns://variant", 'enum' => $enums, 'meta:enum' => $meta_enums, diff --git a/src/Plugin/UiPatterns/PropType/VariantPropType.php b/src/Plugin/UiPatterns/PropType/VariantPropType.php index ca17553d1..da53ff769 100644 --- a/src/Plugin/UiPatterns/PropType/VariantPropType.php +++ b/src/Plugin/UiPatterns/PropType/VariantPropType.php @@ -14,10 +14,10 @@ use Drupal\ui_patterns\PropTypePluginBase; #[PropType( id: 'variant', label: new TranslatableMarkup('Variant'), - description: new TranslatableMarkup('Prop Type for component variants.'), + description: new TranslatableMarkup('Prop type for component variants.'), default_source: 'select', - schema: [], - priority: 10 + schema: ['type' => ['string'], 'enum' => []], + priority: 1 )] class VariantPropType extends PropTypePluginBase { -- GitLab