function Yaml::encode

Same name in other branches
  1. 9 core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml::encode()
  2. 8.9.x core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml::encode()
  3. 11.x core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml::encode()

Overrides SerializationInterface::encode

16 calls to Yaml::encode()
ConfigConfiguratorTest::testExistingConfigWithKeysInDifferentOrder in core/tests/Drupal/KernelTests/Core/Recipe/ConfigConfiguratorTest.php
ConfigValidationTest::createRecipeWithInvalidDataInFile in core/tests/Drupal/KernelTests/Core/Recipe/ConfigValidationTest.php
Creates a recipe with invalid config data in a particular file.
ContentImportTest::testEntityValidationIsTriggered in core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php
Tests that the importer validates entities before saving them.
DependencyTest::testNoVersionInfo in core/modules/system/tests/src/Functional/Module/DependencyTest.php
Tests visiting admin/modules when a module outside of core has no version.
DistributionProfileExistingSettingsTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php

... See full list

File

core/lib/Drupal/Component/Serialization/Yaml.php, line 18

Class

Yaml
Provides a YAML serialization implementation using symfony/yaml.

Namespace

Drupal\Component\Serialization

Code

public static function encode($data) {
    try {
        // Set the indentation to 2 to match Drupal's coding standards.
        $yaml = new Dumper(2);
        return $yaml->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
    } catch (\Exception $e) {
        throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.