You are here

protected function YamlFormName::formatLines in YAML Form 8

Format composite element value into lines of text.

Parameters

array $element: A composite element.

array $value: Composite element values.

Return value

array Composite element values converted into lines of text.

Overrides YamlFormCompositeBase::formatLines

File

src/Plugin/YamlFormElement/YamlFormName.php, line 41

Class

YamlFormName
Provides an 'name' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

protected function formatLines(array $element, array $value) {
  $name_parts = [];
  $composite_elements = $this
    ->getCompositeElements();
  foreach (Element::children($composite_elements) as $name_part) {
    if (!empty($value[$name_part])) {
      $delimiter = in_array($name_part, [
        'suffix',
        'degree',
      ]) ? ', ' : ' ';
      $name_parts[] = $delimiter . $value[$name_part];
    }
  }
  return [
    'name' => trim(implode('', $name_parts)),
  ];
}