From ab414f0de453e3f98862e0d2af3187092891acbc Mon Sep 17 00:00:00 2001 From: Andrew Rivera Date: Wed, 4 Oct 2023 13:31:22 -0700 Subject: [PATCH] DS-1053: Update data array --- src/Utils.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Utils.php b/src/Utils.php index bb60306a..8f339146 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -275,6 +275,28 @@ public static function buildPropsArray($items, $schema, $isData = FALSE) { } } + if ($isData) { + // Convert data attributes to array. + // In our twig templates, we check for attribute values. E.g. + // {{ this.data.height.value }}. + // Previously, {{ this.data.height }} was an Attribute. So the above would + // use the `value()` method to get its value. + // As of Drupal 10, we are no longer allowed to use the `value()` method + // inside of Twig. + // The code below converts `$props` from an Attribute object to + // an array. The array becomes `$this['data']['height']['value']`. So the + // existing twig templates will not need to be altered. + $data = []; + if (isset($props)) { + foreach ($props as $key => $value) { + $data[$key]['value'] = $value->value(); + } + if (isset($data)) { + $props = $data; + } + } + } + return $props; }