You are here

public function YamlFormSubmissionViewBuilder::buildTable in YAML Form 8

Build table display from elements and submitted data.

Parameters

array $elements: A flattened array form elements that have values.

array $data: Submission data.

array $options:

  • excluded_elements: An array of elements to be excluded.
  • email: Format element to be send via email.

Return value

array A render array displaying the submitted values in a table.

Overrides YamlFormSubmissionViewBuilderInterface::buildTable

File

src/YamlFormSubmissionViewBuilder.php, line 187

Class

YamlFormSubmissionViewBuilder
Render controller for form submissions.

Namespace

Drupal\yamlform

Code

public function buildTable(array $elements, array $data, array $options = []) {
  $rows = [];
  foreach ($elements as $key => $element) {
    if (isset($options['excluded_elements'][$key])) {
      continue;
    }
    $plugin_id = $this->elementManager
      ->getElementPluginId($element);

    /** @var \Drupal\yamlform\YamlFormElementInterface $yamlform_element */
    $yamlform_element = $this->elementManager
      ->createInstance($plugin_id);

    // Check element view access.
    if (!$yamlform_element
      ->checkAccessRules('view', $element)) {
      continue;
    }
    $title = $element['#admin_title'] ?: $element['#title'] ?: '(' . $key . ')';
    $value = isset($data[$key]) ? $yamlform_element
      ->formatHtml($element, $data[$key], $options) : '';
    $rows[] = [
      [
        'header' => TRUE,
        'data' => $title,
      ],
      [
        'data' => is_string($value) ? [
          '#markup' => $value,
        ] : $value,
      ],
    ];
  }
  return [
    '#type' => 'table',
    '#rows' => $rows,
    '#attributes' => [
      'class' => [
        'yamlform-submission__table',
      ],
    ],
  ];
}