You are here

public function DevelopmentEnvironmentController::mailLogPage in Development Environment 8

Log page for an individual email.

Parameters

int $lid: The log item ID.

Return value

array A render array representing a single email log page.

Overrides DevelopmentEnvironmentControllerInterface::mailLogPage

1 string reference to 'DevelopmentEnvironmentController::mailLogPage'
development_environment.routing.yml in ./development_environment.routing.yml
development_environment.routing.yml

File

src/Controller/DevelopmentEnvironmentController.php, line 148

Class

DevelopmentEnvironmentController
The DevelopmentEnvironmentController class.

Namespace

Drupal\development_environment\Controller

Code

public function mailLogPage($lid) {
  $mail_log = $this->database
    ->query('SELECT timestamp, email_data FROM {development_environment_log} WHERE lid = :lid', [
    ':lid' => $lid,
  ])
    ->fetch();
  if (!$mail_log) {
    throw new NotFoundHttpException();
  }
  $mail_info = unserialize($mail_log->email_data);
  if (is_array($mail_info['body'])) {
    $body = implode('<br/>', $mail_info['body']);
  }
  else {
    $body = $mail_info['body'];
  }
  $page = [
    'header' => [
      '#prefix' => '<h2>',
      '#suffix' => '</h2>',
      '#markup' => $this
        ->t('The following email was not sent as this is a development environment'),
    ],
    'email' => [
      '#type' => 'details',
      '#title' => $this
        ->t('Email data'),
      '#open' => TRUE,
      'time' => [
        '#prefix' => '<p>',
        '#suffix' => '</p>',
        '#markup' => $this
          ->t('Time: %time', [
          '%time' => $this->dateFormatter
            ->format($mail_log->timestamp, 'short', '', $this->currentUser
            ->getTimeZone()),
        ]),
      ],
      'recipient' => [
        '#prefix' => '<p>',
        '#suffix' => '</p>',
        '#markup' => $this
          ->t('Recipient: %recipient', [
          '%recipient' => $mail_info['to'],
        ]),
      ],
      'subject' => [
        '#prefix' => '<p>',
        '#suffix' => '</p>',
        '#markup' => $this
          ->t('Subject: %subject', [
          '%subject' => $mail_info['subject'],
        ]),
      ],
      'body' => [
        '#prefix' => '<div>',
        '#suffix' => '</div><br/>',
        '#markup' => $this
          ->t('Body: %body', [
          '%body' => $body,
        ]),
      ],
      'headers' => [
        '#prefix' => '<div>',
        '#suffix' => '</div>',
        '#markup' => $this
          ->t('Headers:') . $this->varDumpService
          ->varDump($mail_info['headers'], TRUE, TRUE),
      ],
    ],
    'raw_mail_data' => [
      '#type' => 'details',
      '#title' => $this
        ->t('Raw email data'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      'data' => [
        '#markup' => $this->varDumpService
          ->varDump($mail_info, TRUE, TRUE),
      ],
    ],
  ];
  return $page;
}