Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3424701
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
drupal-3424701
Commits
19ab1c98
Verified
Commit
19ab1c98
authored
1 year ago
by
Lauri Timmanee
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3403331
by pdureau, Utkarsh_33: Prevent TypeError when using create_attribute Twig function
parent
16fc21bb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Template/TwigExtension.php
+8
-5
8 additions, 5 deletions
core/lib/Drupal/Core/Template/TwigExtension.php
core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+3
-1
3 additions, 1 deletion
core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
with
11 additions
and
6 deletions
core/lib/Drupal/Core/Template/TwigExtension.php
+
8
−
5
View file @
19ab1c98
...
...
@@ -606,15 +606,18 @@ public function safeJoin(Environment $env, $value, $glue = '') {
/**
* Creates an Attribute object.
*
* @param array $attributes
* (optional) An
associative array of key-value pairs to be converted to
* HTML attributes.
* @param
Attribute|
array $attributes
* (optional) An
existing attribute object or an associative array of
*
key-value pairs to be converted to
HTML attributes.
*
* @return \Drupal\Core\Template\Attribute
* An attributes object that has the given attributes.
*/
public
function
createAttribute
(
array
$attributes
=
[])
{
return
new
Attribute
(
$attributes
);
public
function
createAttribute
(
Attribute
|
array
$attributes
=
[])
{
if
(
\is_array
(
$attributes
))
{
return
new
Attribute
(
$attributes
);
}
return
$attributes
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+
3
−
1
View file @
19ab1c98
...
...
@@ -10,6 +10,7 @@
use
Drupal\Core\Render\Markup
;
use
Drupal\Core\Render\RenderableInterface
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\Core\Template\Attribute
;
use
Drupal\Core\Template\Loader\StringLoader
;
use
Drupal\Core\Template\TwigEnvironment
;
use
Drupal\Core\Template\TwigExtension
;
...
...
@@ -404,9 +405,10 @@ public function testCreateAttribute() {
[
'class'
=>
[
'kittens'
],
'data-toggle'
=>
'modal'
,
'data-lang'
=>
'es'
],
[
'id'
=>
'puppies'
,
'data-value'
=>
'foo'
,
'data-lang'
=>
'en'
],
[],
new
Attribute
(),
];
$result
=
$twig
->
render
(
$name
,
[
'iterations'
=>
$iterations
]);
$expected
=
'<div class="kittens" data-toggle="modal" data-lang="es"></div><div id="puppies" data-value="foo" data-lang="en"></div><div></div>'
;
$expected
=
'<div class="kittens" data-toggle="modal" data-lang="es"></div><div id="puppies" data-value="foo" data-lang="en"></div><div></div>
<div></div>
'
;
$this
->
assertEquals
(
$expected
,
$result
);
// Test default creation of empty attribute object and using its method.
...
...
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