public static function WebformYaml::encode in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Utility/WebformYaml.php \Drupal\webform\Utility\WebformYaml::encode()
Encodes data into the serialization format.
Parameters
mixed $data: The data to encode.
Return value
string The encoded data.
Throws
\Drupal\Component\Serialization\Exception\InvalidDataTypeException
Overrides SerializationInterface::encode
30 calls to WebformYaml::encode()
- DebugWebformHandler::submitForm in src/
Plugin/ WebformHandler/ DebugWebformHandler.php - Submit webform submission form.
- OverrideWebformVariant::buildConfigurationForm in src/
Plugin/ WebformVariant/ OverrideWebformVariant.php - Form constructor.
- OverrideWebformVariant::debug in src/
Plugin/ WebformVariant/ OverrideWebformVariant.php - Display debugging information.
- Webform::initElementsTranslation in src/
Entity/ Webform.php - Initialize elements translation.
- Webform::setElements in src/
Entity/ Webform.php - Sets elements (YAML) value.
File
- src/
Utility/ WebformYaml.php, line 18
Class
- WebformYaml
- Provides YAML tidy function.
Namespace
Drupal\webform\UtilityCode
public static function encode($data) {
// Convert \r\n to \n so that multiline strings are properly formatted.
// @see \Symfony\Component\Yaml\Dumper::dump
if (is_array($data)) {
static::normalize($data);
}
// If empty array then return an empty string instead of '{ }'.
if (is_array($data) && empty($data)) {
return '';
}
$dumper = new Dumper(2);
$yaml = $dumper
->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
// Remove return after array delimiter.
$yaml = preg_replace('#((?:\\n|^)[ ]*-)\\n[ ]+(\\w|[\'"])#', '\\1 \\2', $yaml);
return trim($yaml);
}