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
1906eb4c
Commit
1906eb4c
authored
2 months ago
by
Florent Torregrosa
Committed by
Pierre Dureau
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3488582
by grimreaper, pdureau: Side effect in links prop type normalization casting
parent
486c760c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!270
Issue #3488582 by grimreaper, pdureau: Side effect in links prop type normalization casting
Pipeline
#353312
passed
2 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/UiPatterns/PropType/AttributesPropType.php
+1
-1
1 addition, 1 deletion
src/Plugin/UiPatterns/PropType/AttributesPropType.php
src/Plugin/UiPatterns/PropType/LinksPropType.php
+6
-15
6 additions, 15 deletions
src/Plugin/UiPatterns/PropType/LinksPropType.php
with
7 additions
and
16 deletions
src/Plugin/UiPatterns/PropType/AttributesPropType.php
+
1
−
1
View file @
1906eb4c
...
...
@@ -53,7 +53,7 @@ class AttributesPropType extends PropTypePluginBase {
plugins are expected to return a mapping to not break SDC prop validation
against the prop type schema.
*/
if
(
is_array
(
$value
))
{
if
(
is_array
(
$value
)
&&
!
empty
(
$value
)
)
{
// Attribute::createAttributeValue() is already normalizing some stuff:
// - 'class' attribute must be a list
// - MarkupInterface values must be resolved.
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/UiPatterns/PropType/LinksPropType.php
+
6
−
15
View file @
1906eb4c
...
...
@@ -115,20 +115,14 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin
*/
protected
static
function
normalizeLink
(
array
$item
):
array
{
$item
=
self
::
normalizeAttributes
(
$item
);
// Do not normalize title as it can be a string or a renderable array.
if
(
array_key_exists
(
"text"
,
$item
))
{
// Examples: links.html.twig, breadcrumb.html.twig, pager.html.twig,
// views_mini_pager.html.twig.
if
(
is_scalar
(
$item
[
"text"
])
||
$item
[
"text"
]
instanceof
\Stringable
)
{
$item
[
"title"
]
=
(
string
)
$item
[
"text"
];
}
else
{
$item
[
"title"
]
=
$item
[
"text"
];
}
$item
[
"title"
]
=
$item
[
"text"
];
unset
(
$item
[
"text"
]);
}
if
(
!
is_string
(
$item
[
"title"
]))
{
$item
[
"title"
]
=
(
string
)
$item
[
"title"
];
}
if
(
array_key_exists
(
"href"
,
$item
))
{
// Examples: pager.html.twig, views_mini_pager.html.twig.
$item
[
"url"
]
=
$item
[
"href"
];
...
...
@@ -150,16 +144,13 @@ class LinksPropType extends PropTypePluginBase implements ContainerFactoryPlugin
if
(
!
array_key_exists
(
$property
,
$item
))
{
return
$item
;
}
if
(
is_a
(
$item
[
$property
],
'\Drupal\Core\Template\Attribute'
))
{
$item
[
$property
]
=
$item
[
$property
]
->
toArray
();
}
$item
[
$property
]
=
AttributesPropType
::
normalize
(
$item
[
$property
]);
// Empty PHP arrays are converted in JSON arrays instead of JSON objects
// by json_encode(), so it is better to remove them.
if
(
is_array
(
$item
[
$property
])
&&
empty
(
$item
[
$property
]))
{
if
(
empty
(
$item
[
$property
]))
{
unset
(
$item
[
$property
]);
return
$item
;
}
$item
[
$property
]
=
AttributesPropType
::
normalize
(
$item
[
$property
]);
return
$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