By alexpott on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
11.x
Introduced in version:
11.3.0
Issue links:
Description:
\Drupal\Component\Serialization\Yaml::decodeTags() has been added to allow \Symfony\Component\Yaml\Tag\TaggedValue objects to be converted into more useful objects. This underpins the new !translate YAML tag - see Recipe's recipe.yml can be translated.
To use this method you must parse Yaml using the \Symfony\Component\Yaml\Yaml::PARSE_CUSTOM_TAGS flag which is the case for \Drupal\Component\Serialization\Yaml::decode().
For example to parse a recipe file and convert all the !translate tagged values to \Drupal\Core\StringTranslation\TranslatableMarkupobjects
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\StringTranslation\TranslatableMarkup;
$recipe_data = Yaml::decode(file_get_contents('PATH_TO/recipe.yml'));
$recipe_data = Yaml::decodeTags($recipe_data, ['translate' => TranslatableMarkup::class]);
Impacts:
Module developers
Site templates, recipes and distribution developers