Skip to content
Snippets Groups Projects
Commit d37f46a6 authored by Pierre Dureau's avatar Pierre Dureau
Browse files

Issue #3472571 by pdureau, grimreaper: Links normalize drops link options

parent 0f9e8a8e
No related branches found
No related tags found
1 merge request!195Issue #3472571 by pdureau, grimreaper: Links normalize drops link options
Pipeline #278277 passed with warnings
...@@ -94,7 +94,7 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin ...@@ -94,7 +94,7 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin
protected static function normalizeLinks(array $value): array { protected static function normalizeLinks(array $value): array {
// Don't inject URL object into patterns templates, use "title" as item // Don't inject URL object into patterns templates, use "title" as item
// label and "url" as item target. // label and "url" as item target.
foreach ($value as $index => &$item) { foreach ($value as $index => $item) {
if (!is_array($item)) { if (!is_array($item)) {
unset($value[$index]); unset($value[$index]);
continue; continue;
...@@ -114,17 +114,13 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin ...@@ -114,17 +114,13 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin
$item["url"] = $item["href"]; $item["url"] = $item["href"];
unset($item["href"]); unset($item["href"]);
} }
if (!isset($item["url"]) && isset($item["link"])) { $item = self::extractLinkData($item);
// Example: links.html.twig.
$item["url"] = $item["link"]["#url"];
$item["url"]->setOptions($item["link"]["#options"]);
unset($item["link"]);
}
$item = self::normalizeUrl($item); $item = self::normalizeUrl($item);
$item = static::normalizeAttributes($item, "link_attributes"); $item = static::normalizeAttributes($item, "link_attributes");
if (array_key_exists("below", $item)) { if (array_key_exists("below", $item)) {
$item["below"] = self::normalize($item["below"]); $item["below"] = self::normalize($item["below"]);
} }
$value[$index] = $item;
} }
return array_values($value); return array_values($value);
} }
...@@ -154,6 +150,26 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin ...@@ -154,6 +150,26 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin
return $item; return $item;
} }
/**
* Extract data from link.
*
* Useful for: links.html.twig.
*/
protected static function extractLinkData(array $item): array {
if (isset($item["url"])) {
return $item;
}
if (!isset($item["link"])) {
return $item;
}
$item["url"] = $item["link"]["#url"];
if (isset($item["link"]["#options"])) {
$item["url"]->mergeOptions($item["link"]["#options"]);
}
unset($item["link"]);
return $item;
}
/** /**
* Normalize URL in an item. * Normalize URL in an item.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment