You are here

public function Rss::render in Support Ticketing System 8

Render a row object. This usually passes through to a theme template of some form, but not always.

Parameters

object $row: A single row of the query result, so an element of $view->result.

Return value

string The rendered output of a single row, used by the style plugin.

Overrides RowPluginBase::render

File

modules/support_ticket/src/Plugin/views/row/Rss.php, line 94
Contains \Drupal\support_ticket\Plugin\views\row\Rss.

Class

Rss
Plugin which performs a support_ticket_view on the resulting object and formats it as an RSS item.

Namespace

Drupal\support_ticket\Plugin\views\row

Code

public function render($row) {
  global $base_url;
  $stid = $row->{$this->field_alias};
  if (!is_numeric($stid)) {
    return;
  }
  $display_mode = $this->options['view_mode'];
  if ($display_mode == 'default') {
    $display_mode = \Drupal::config('system.rss')
      ->get('items.view_mode');
  }

  // Load the specified support ticket:

  /** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */
  $support_ticket = $this->support_tickets[$stid];
  if (empty($support_ticket)) {
    return;
  }
  $description_build = [];
  $support_ticket->link = $support_ticket
    ->url('canonical', array(
    'absolute' => TRUE,
  ));
  $support_ticket->rss_namespaces = array();
  $support_ticket->rss_elements = array(
    array(
      'key' => 'pubDate',
      'value' => gmdate('r', $support_ticket
        ->getCreatedTime()),
    ),
    array(
      'key' => 'dc:creator',
      'value' => $support_ticket
        ->getOwner()
        ->getDisplayName(),
    ),
    array(
      'key' => 'guid',
      'value' => $support_ticket
        ->id() . ' at ' . $base_url,
      'attributes' => array(
        'isPermaLink' => 'false',
      ),
    ),
  );

  // The support ticket gets built and modules add to or modify $support_ticket->rss_elements
  // and $support_ticket->rss_namespaces.
  $build_mode = $display_mode;
  $build = support_ticket_view($support_ticket, $build_mode);
  unset($build['#theme']);
  if (!empty($support_ticket->rss_namespaces)) {
    $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $support_ticket->rss_namespaces);
  }
  elseif (function_exists('rdf_get_namespaces')) {

    // Merge RDF namespaces in the XML namespaces in case they are used
    // further in the RSS content.
    $xml_rdf_namespaces = array();
    foreach (rdf_get_namespaces() as $prefix => $uri) {
      $xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
    }
    $this->view->style_plugin->namespaces += $xml_rdf_namespaces;
  }
  if ($display_mode != 'title') {

    // We render support ticket contents.
    $description_build = $build;
  }
  $item = new \stdClass();
  $item->description = $description_build;
  $item->title = $support_ticket
    ->label();
  $item->link = $support_ticket->link;

  // Provide a reference so that the render call in
  // template_preprocess_views_view_row_rss() can still access it.
  $item->elements =& $support_ticket->rss_elements;
  $item->stid = $support_ticket
    ->id();
  $build = array(
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $item,
  );
  return $build;
}