You are here

protected function YamlFormUiElementTestForm::convertTranslatableMarkupToStringRecursive in YAML Form 8

Convert all translatable markup to strings.

This allows element to be serialized.

Parameters

array $element: An element.

Return value

array The element with all translatable markup converted to strings.

1 call to YamlFormUiElementTestForm::convertTranslatableMarkupToStringRecursive()
YamlFormUiElementTestForm::buildForm in modules/yamlform_ui/src/Form/YamlFormUiElementTestForm.php
Form constructor.

File

modules/yamlform_ui/src/Form/YamlFormUiElementTestForm.php, line 224

Class

YamlFormUiElementTestForm
Provides a test form for form elements.

Namespace

Drupal\yamlform_ui\Form

Code

protected function convertTranslatableMarkupToStringRecursive(array $element) {
  foreach ($element as $key => $value) {
    if ($value instanceof TranslatableMarkup) {
      $element[$key] = (string) $value;
    }
    elseif (is_array($value)) {
      $element[$key] = $this
        ->convertTranslatableMarkupToStringRecursive($value);
    }
  }
  return $element;
}