You are here

public function TableWebformExporter::writeHeader in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformExporter/TableWebformExporter.php \Drupal\webform\Plugin\WebformExporter\TableWebformExporter::writeHeader()

Write header to export.

Overrides WebformExporterBase::writeHeader

File

src/Plugin/WebformExporter/TableWebformExporter.php, line 46

Class

TableWebformExporter
Defines a HTML table exporter.

Namespace

Drupal\webform\Plugin\WebformExporter

Code

public function writeHeader() {
  $header = $this
    ->buildHeader();
  $file_handle = $this->fileHandle;
  if ($this->configuration['source_entity']) {
    $title = $this->configuration['source_entity']
      ->label();
  }
  elseif ($this->configuration['webform']) {
    $title = $this->configuration['webform']
      ->label();
  }
  else {
    $title = '';
  }
  $thead = [];
  foreach ($header as $item) {
    $thead[] = '<th>' . htmlentities($item) . '</th>';
  }
  fwrite($file_handle, '<!doctype html>');
  fwrite($file_handle, '<html>');
  fwrite($file_handle, '<head>');

  // Force Excel to keep field values containing p- or br-tags within the same
  // cell.
  fwrite($file_handle, '<style>p, br {mso-data-placement:same-cell;}</style>');
  fwrite($file_handle, '<meta charset="utf-8">');
  if ($title) {
    fwrite($file_handle, '<title>' . $title . '</title>');
  }
  fwrite($file_handle, '</head>');
  fwrite($file_handle, '<body>');
  fwrite($file_handle, '<table border="1">');
  fwrite($file_handle, '<thead><tr bgcolor="#cccccc" valign="top">');
  fwrite($file_handle, implode(PHP_EOL, $thead));
  fwrite($file_handle, '</tr></thead>');
  fwrite($file_handle, '<tbody>');
}