Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cl_server
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
cl_server
Merge requests
!23
Upcast attributes in any variable
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Upcast attributes in any variable
issue/cl_server-3406011:3406011-upcast-attributes-in
into
2.x
Overview
0
Commits
1
Pipelines
1
Changes
1
Open
Pierre Rudloff
requested to merge
issue/cl_server-3406011:3406011-upcast-attributes-in
into
2.x
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
Closes
#3406011
0
0
Merge request reports
Compare
2.x
2.x (HEAD)
and
latest version
latest version
04118500
1 commit,
1 year ago
1 file
+
10
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Controller/ServerEndpointController.php
+
10
−
6
Options
@@ -186,9 +186,12 @@ class ServerEndpointController extends ControllerBase {
private
function
generateRenderArray
(
Component
$component
,
array
$context
):
array
{
$metadata
=
$component
->
metadata
;
// Try to convert a key-value attributes property into the Drupal object.
if
(
$this
->
attributesPropNeedsUpcasting
(
$context
,
$metadata
))
{
$context
[
'attributes'
]
=
new
Attribute
(
$context
[
'attributes'
]);
};
foreach
(
$context
as
$key
=>
$value
)
{
if
(
$this
->
attributesPropNeedsUpcasting
(
$context
,
$key
,
$metadata
))
{
$context
[
$key
]
=
new
Attribute
(
$value
);
}
}
$block_names
=
array_keys
(
$metadata
->
slots
);
$slots
=
array_map
(
static
fn
(
string
$slot_str
)
=>
[
@@ -218,13 +221,14 @@ class ServerEndpointController extends ControllerBase {
*
* @param array $context
* The template context.
* @param string $key
* @param \Drupal\sdc\Component\ComponentMetadata $metadata
* The component metadata.
*/
private
function
attributesPropNeedsUpcasting
(
array
$context
,
ComponentMetadata
$metadata
)
{
private
function
attributesPropNeedsUpcasting
(
array
$context
,
string
$key
,
ComponentMetadata
$metadata
)
{
$properties
=
$metadata
->
schema
[
'properties'
]
??
[];
$context_has_attributes
=
is_array
(
$context
[
'attributes'
]
??
NULL
);
$metadata_has_attributes
=
(
$properties
[
'attributes'
][
'type'
][
0
]
??
NULL
)
===
"Drupal\Core\Template\Attribute"
;
$context_has_attributes
=
is_array
(
$context
[
$key
]
??
NULL
);
$metadata_has_attributes
=
(
$properties
[
$key
][
'type'
][
0
]
??
NULL
)
===
"Drupal\Core\Template\Attribute"
;
return
$context_has_attributes
&&
$metadata_has_attributes
;
}
Loading