You are here

public function DefaultController::webform_email_reply_previous in Webform Email Reply 8

1 string reference to 'DefaultController::webform_email_reply_previous'
webform_email_reply.routing.yml in ./webform_email_reply.routing.yml
webform_email_reply.routing.yml

File

src/Controller/DefaultController.php, line 92
Contains \Drupal\webform_email_reply\Controller\DefaultController.

Class

DefaultController
Default controller for the webform_email_reply module.

Namespace

Drupal\webform_email_reply\Controller

Code

public function webform_email_reply_previous($webform, $webform_submission) {

  // Set the header.
  $header = [
    [
      'data' => t('#'),
      'field' => 'eid',
      'sort' => 'desc',
    ],
    [
      'data' => t('Sent by'),
    ],
    [
      'data' => t('Sent at'),
      'field' => 'replied',
    ],
    [
      'data' => t('Message'),
    ],
    [
      'data' => t('Attachment'),
    ],
  ];

  // Get the submissions.
  $replies = webform_email_reply_get_replies($webform, $webform_submission);
  $rows = [];
  foreach ($replies as $key => $reply) {
    $row = [];
    $row['eid'] = ++$key;
    $row['from'] = $reply->from_address;
    $row['replied'] = $this->dateFormatter
      ->format($reply->replied, 'short');
    $row['message'] = $reply->message;
    $file_display = 'none';
    if ($reply->fid) {
      $file = File::load($reply->fid);
      $uri = file_create_url($file
        ->getFileUri());

      // $file_display = [
      //   '#type' => 'link',
      //   '#title' => $this->t('View'),
      //   '#url' => $uri,
      // ];
    }
    $row['attachment'] = $file_display;
    $rows[] = $row;
  }
  $output = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  ];
  $output['pager'] = [
    '#type' => 'pager',
  ];
  return $output;
}