1 block.news.inc public DashboardNewsBlock::getContent()

Return the content of a block.

Return value

mixed:

Overrides Block::getContent

File

core/modules/dashboard/includes/block.news.inc, line 41
Dashboard block displaying BackdropCMS.org news items.

Class

DashboardNewsBlock

Code

public function getContent() {
  $news = $this->getNews();

  $links = array();
  if ($news) {
    foreach ($news as $key => $notifications) {
      $notification_date = format_date($notifications['timestamp'], 'custom', 'M j, Y');
      $date_classes = array('class' => array('notification-date'));
      // A notification is considered new, if no more than 14 days (1209600
      // seconds) have lapsed.
      $is_new = (time() - $notifications['timestamp']) < 1209600;
      if ($is_new) {
        $date_classes['class'][] = 'marker';
      }
      $notification_date = '<span ' . backdrop_attributes($date_classes) . '>' . $notification_date . '</span>';
      $notification_link = l($notifications['title'], $notifications['url'], array('attributes' => array('target' => '_blank')));
      $notification_summary = filter_xss($notifications['summary']);

      $notification = array(
        'data' => '<p>' . $notification_date . ': ' . $notification_link . ' - ' . $notification_summary . '</p>',
      );

      if ($is_new) {
        $notification['class'] = array('is-new');
      }

      $links[] = $notification;
    }
  }

  $build = array();
  if (empty($links)) {
    $build['list'] = array(
      '#type' => 'markup',
      '#markup' => t('No news at this time.'),
    );
  }
  else {
    $build['list'] = array(
      '#theme' => 'item_list',
      '#items' => $links,
    );
  }

  return $build;
}