Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_patterns
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ui_patterns
Commits
d37f46a6
Commit
d37f46a6
authored
8 months ago
by
Pierre Dureau
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3472571
by pdureau, grimreaper: Links normalize drops link options
parent
0f9e8a8e
No related branches found
No related tags found
1 merge request
!195
Issue #3472571 by pdureau, grimreaper: Links normalize drops link options
Pipeline
#278277
passed with warnings
8 months ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/UiPatterns/PropType/LinksPropType.php
+23
-7
23 additions, 7 deletions
src/Plugin/UiPatterns/PropType/LinksPropType.php
with
23 additions
and
7 deletions
src/Plugin/UiPatterns/PropType/LinksPropType.php
+
23
−
7
View file @
d37f46a6
...
@@ -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.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment