Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS-1053: Update data array #4

Open
wants to merge 1 commit into
base: release/5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ public static function buildPropsArray($items, $schema, $isData = FALSE) {
}
}

if ($isData) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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;
}

Expand Down