You are here

public function TableYamlFormExporter::writeHeader in YAML Form 8

Write header to export.

Overrides YamlFormExporterBase::writeHeader

File

src/Plugin/YamlFormExporter/TableYamlFormExporter.php, line 53

Class

TableYamlFormExporter
Defines a HTML table exporter.

Namespace

Drupal\yamlform\Plugin\YamlFormExporter

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['yamlform']) {
    $title = $this->configuration['yamlform']
      ->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>');
  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("\n", $thead));
  fwrite($file_handle, '</tr></thead>');
  fwrite($file_handle, '<tbody>');
}