Skip to content
Snippets Groups Projects

Important patch updates:

Open Alex Pott requested to merge issue/drupal-3313863:3313863-translation-of-config into 11.x
8 files
+ 114
11
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -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