Skip to content
Snippets Groups Projects
Commit 612f5131 authored by Wolfgang Ziegler's avatar Wolfgang Ziegler
Browse files

Issue #3202372 by fago: Improve handling of json props when using Vue.js markup style

parent 5857b685
No related branches found
Tags 8.x-2.0-beta5
1 merge request!9Issue #3202372: Improve handling of json props when using Vue.js markup style
......@@ -38,15 +38,23 @@ function template_preprocess_custom_element(&$variables) {
// Generate variables for easier usage in the template.
/** @var \Drupal\custom_elements\CustomElement $custom_element */
$custom_element = $variables['custom_element'];
$markup_style = \Drupal::config('custom_elements.settings')->get('markup_style');
$variables['attributes'] = new Attribute();
foreach ($custom_element->getAttributes() as $key => $value) {
// Take care of struct values and json-encode them as necessary.
$variables['attributes'][$key] = is_array($value) ? json_encode($value) : $value;
if (is_array($value)) {
$value = json_encode($value);
// For vue mark-up style let vue evaluate the json to an object.
// See https://vuejs.org/v2/guide/components-props.html#Passing-an-Object
if ($markup_style == 'vue-3') {
$key = ":$key";
}
}
$variables['attributes'][$key] = $value;
}
$variables['tag_prefix'] = $custom_element->getTagPrefix() ? $custom_element->getTagPrefix() . '-' : '';
$variables['tag'] = $custom_element->getTag();
$markup_style = \Drupal::config('custom_elements.settings')->get('markup_style');
if ($markup_style == 'vue-3') {
$variables['slots'] = custom_elements_prepare_slots_as_vue_3($custom_element);
}
......
......@@ -45,7 +45,7 @@ class ParagraphGalleryProcessor implements CustomElementProcessorInterface {
'description' => $media_image->field_description->value,
];
}
$element->setAttribute(':sources', $sources);
$element->setAttribute('sources', $sources);
// Always add a title attribute if field_title is there.
if (isset($paragraph->field_title) && $paragraph->field_title->value) {
......
......@@ -310,7 +310,7 @@ EOF;
],
]));
$expected_markup = <<<EOF
<pg-gallery :sources="$expected_json" type="gallery" view-mode="full"/>
<pg-gallery sources="$expected_json" type="gallery" view-mode="full"/>
EOF;
// Editors strip trailing spaces, so do so for the generated markup.
Assert::assertXmlStringEqualsXmlString($expected_markup, str_replace(" \n", "\n", $markup));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment