You are here

function NodejsLogger::renderRow in Node.js integration 8

Renders a watchdog row.

1 call to NodejsLogger::renderRow()
NodejsLogger::log in nodejs_watchdog/src/Logger/NodejsLogger.php
Logs with an arbitrary level.

File

nodejs_watchdog/src/Logger/NodejsLogger.php, line 83

Class

NodejsLogger
Sends Nodejs messages for events.

Namespace

Drupal\nodejs_watchdog\Logger

Code

function renderRow($row) {
  $row_attributes = [];
  $output = '';
  $cells = [];
  foreach ($row as $key => $value) {
    if ($key == 'data') {
      $cells = $value;
    }
    else {
      $row_attributes[$key] = $value;
    }
  }
  if (!empty($cells)) {
    $output .= '<tr' . new Attribute($row_attributes) . '>';
    foreach ($cells as $cell) {
      if (is_array($cell)) {
        $data = isset($cell['data']) ? $cell['data'] : '';

        // Cell's data property can be a string or a renderable array.
        if (is_array($data)) {
          $data = $this->container
            ->get('renderer')
            ->renderRoot($data);
        }
        unset($cell['data']);
        $attributes = new Attribute($cell);
      }
      else {
        $attributes = '';
        $data = $cell;
      }
      $output .= '<td' . $attributes . '>' . $data . '</td>';
    }
    $output .= '</tr>';
  }
  return $output;
}