You are here

public function EditionsController::nodeEditionsPage in Simplenews Scheduler 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/EditionsController.php \Drupal\simplenews_scheduler\Controller\EditionsController::nodeEditionsPage()
1 string reference to 'EditionsController::nodeEditionsPage'
simplenews_scheduler.routing.yml in ./simplenews_scheduler.routing.yml
simplenews_scheduler.routing.yml

File

src/Controller/EditionsController.php, line 105
Contains \Drupal\simplenews_scheduler\Controller\EditionsController.

Class

EditionsController
Default controller for the simplenews_scheduler module.

Namespace

Drupal\simplenews_scheduler\Controller

Code

public function nodeEditionsPage(NodeInterface $node) {
  $nid = $this
    ->getPid($node);
  $output = array();
  $rows = array();
  if ($nid == $node
    ->id()) {

    // This is the template newsletter.
    $output['prefix']['#markup'] = '<p>' . t('This is a newsletter template node of which all corresponding editions nodes are based on.') . '</p>';

    // Load the corresponding editions from the database to further process.
    $result = $this->database
      ->select('simplenews_scheduler_editions', 's')
      ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
      ->limit(20)
      ->fields('s')
      ->condition('s.pid', $nid)
      ->execute()
      ->fetchAll();
    foreach ($result as $row) {
      $node = $this->entityManager
        ->getStorage('node')
        ->load($row->eid);
      $rows[] = array(
        $node
          ->link(),
        format_date($row->date_issued, 'custom', 'Y-m-d H:i'),
      );
    }

    // Display a table with all editions.
    // @todo change to render array
    $output['table'] = array(
      '#type' => 'table',
      '#header' => array(
        t('Edition Node'),
        t('Date sent'),
      ),
      '#rows' => $rows,
      '#attributes' => array(
        'class' => array(
          'schedule-history',
        ),
      ),
      '#empty' => t('No scheduled newsletter editions have been sent.'),
    );
    $output['pager'] = array(
      '#type' => 'pager',
    );
  }
  else {

    // This is a newsletter edition.
    $master_node = $this->entityManager
      ->getStorage('node')
      ->load($nid);
    $output['prefix']['#markup'] = '<p>' . t('This node is part of a scheduled newsletter configuration. View the original newsletter <a href="@parent">here</a>.', array(
      '@parent' => $master_node
        ->url(),
    )) . '</p>';
  }
  return $output;
}