Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
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
drupal
Merge requests
!12121
Important patch updates:
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Important patch updates:
issue/drupal-3313863:3313863-translation-of-config
into
11.x
Overview
1
Commits
4
Pipelines
3
Changes
8
Open
Alex Pott
requested to merge
issue/drupal-3313863:3313863-translation-of-config
into
11.x
3 weeks ago
Overview
1
Commits
4
Pipelines
3
Changes
8
Expand
Moved all tag parsing to Yaml class.
Implemented string translation context.
Updated two other recipes for translation.
Handled yaml validation properly with Type(['string', Stringable::class])
Fixed arguments types in ConsoleInputCollector.
Closes
#3313863
0
0
Merge request reports
Compare
11.x
version 2
9dd9663d
6 days ago
version 1
a0d7c394
3 weeks ago
11.x (HEAD)
and
latest version
latest version
17ae193d
4 commits,
5 days ago
version 2
9dd9663d
3 commits,
6 days ago
version 1
a0d7c394
2 commits,
3 weeks ago
8 files
+
114
−
11
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
core/lib/Drupal/Component/Serialization/Yaml.php
+
36
−
0
Options
@@ -5,6 +5,7 @@
@@ -5,6 +5,7 @@
use
Drupal\Component\Serialization\Exception\InvalidDataTypeException
;
use
Drupal\Component\Serialization\Exception\InvalidDataTypeException
;
use
Symfony\Component\Yaml\Dumper
;
use
Symfony\Component\Yaml\Dumper
;
use
Symfony\Component\Yaml\Parser
;
use
Symfony\Component\Yaml\Parser
;
use
Symfony\Component\Yaml\Tag\TaggedValue
;
use
Symfony\Component\Yaml\Yaml
as
SymfonyYaml
;
use
Symfony\Component\Yaml\Yaml
as
SymfonyYaml
;
/**
/**
@@ -51,4 +52,39 @@ public static function getFileExtension() {
@@ -51,4 +52,39 @@ public static function getFileExtension() {
return
'yml'
;
return
'yml'
;
}
}
/**
* Parses custom YAML tags and convert values to primitive types.
*
* Tag objects will be replaced by their raw value or, if a callback
* exists for that tag it will be used.
*
* The only tag custom tag supported by default is the '!translate' tag.
*
* @param mixed $data
* Parsed YAML data.
* @param callable[] $tag_callbacks
* Optional callbacks for tag value, indexed by tag.
*
* @return mixed
* Parsed data with parsed tag values.
*/
public
static
function
decodeTags
(
$data
,
array
$tag_callbacks
=
[])
{
if
(
is_array
(
$data
))
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
is_object
(
$value
)
&&
$value
instanceof
TaggedValue
)
{
if
(
isset
(
$tag_callbacks
[
$value
->
getTag
()]))
{
$data
[
$key
]
=
call_user_func
(
$tag_callbacks
[
$value
->
getTag
()],
$value
);
}
else
{
$data
[
$key
]
=
$value
->
getValue
();
}
}
elseif
(
is_array
(
$value
))
{
$data
[
$key
]
=
static
::
decodeTags
(
$value
,
$tag_callbacks
);
}
}
}
return
$data
;
}
}
}
Loading