You are here

public function Table::formatHtml in YAML Form 8

Format an element's value as HTML.

Parameters

array $element: An element.

array|mixed $value: A value.

array $options: An array of options.

Return value

array|string The element's value formatted as an HTML string or a render array.

Overrides YamlFormElementBase::formatHtml

1 call to Table::formatHtml()
Table::formatText in src/Plugin/YamlFormElement/Table.php
Format an element's value as plain text.

File

src/Plugin/YamlFormElement/Table.php, line 103

Class

Table
Provides a 'table' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatHtml(array &$element, $value, array $options = []) {

  // Undo form submission elements and convert rows back into a simple
  // render array.
  $rows = [];
  foreach ($value as $row_key => $row_element) {
    $element[$row_key] = [];
    foreach ($row_element['#value'] as $column_key => $column_element) {
      if (isset($column_element['#value'])) {
        if (is_string($column_element['#value']) || $column_element['#value'] instanceof TranslatableMarkup) {
          $value = [
            '#markup' => $column_element['#value'],
          ];
        }
        else {
          $value = $column_element['#value'];
        }
      }
      elseif (isset($column_element['#markup'])) {
        $value = [
          '#markup' => $column_element['#markup'],
        ];
      }
      else {
        $value = '';
      }
      $rows[$row_key][$column_key] = [
        'data' => $value,
      ];
    }
  }
  return $rows + $element;
}