You are here

public function RulesDebugLog::renderHelper in Rules 8.3

Renders the log of one event invocation.

Called recursively, consuming all the log lines for this event.

1 call to RulesDebugLog::renderHelper()
RulesDebugLog::build in src/Logger/RulesDebugLog.php
Assembles the entire log into a render array.

File

src/Logger/RulesDebugLog.php, line 157

Class

RulesDebugLog
Logger that stores Rules debug logs with the session service.

Namespace

Drupal\rules\Logger

Code

public function renderHelper(&$line = 0) {
  $build = [];
  $startTime = $this->logs[$line]['timestamp'];
  while ($line < count($this->logs)) {
    if ($build && !empty($this->logs[$line]['scope'])) {

      // This next entry stems from another evaluated set so we create a
      // new container for its log messages then fill that container with
      // a recursive call to renderHelper().
      $link = NULL;
      if (isset($this->logs[$line]['path'])) {
        $link = Link::fromTextAndUrl($this
          ->t('edit'), Url::fromUserInput('/' . $this->logs[$line]['path']))
          ->toString();
      }
      $build[$line] = [
        '#type' => 'details',
        // @codingStandardsIgnoreStart
        '#title' => $this
          ->t($this->logs[$line]['message'], $this->logs[$line]['context']) . ' [' . $link . ']',
      ];
      $thisline = $line;
      $build[$thisline][] = $this
        ->renderHelper($line);
    }
    else {

      // This next entry is a leaf of the evaluated set so we just have to
      // add the details of the log entry.
      $link = NULL;
      if (isset($this->logs[$line]['path']) && !isset($this->logs[$line]['scope'])) {
        $link = [
          'title' => $this
            ->t('edit'),
          'url' => Url::fromUserInput('/' . $this->logs[$line]['path']),
        ];
      }
      $build[$line] = [
        '#theme' => 'rules_debug_log_element',
        '#starttime' => $startTime,
        '#timestamp' => $this->logs[$line]['timestamp'],
        '#level' => $this->logs[$line]['level'],
        // @codingStandardsIgnoreStart
        '#text' => $this
          ->t($this->logs[$line]['message'], $this->logs[$line]['context']),
        // @codingStandardsIgnoreEnd
        '#link' => $link,
      ];
      if (isset($this->logs[$line]['scope']) && !$this->logs[$line]['scope']) {

        // This was the last log entry of this set.
        return [
          '#theme' => 'item_list',
          '#items' => $build,
        ];
      }
    }
    $line++;
  }
  return [
    '#theme' => 'item_list',
    '#items' => $build,
  ];
}