You are here

public function FiaFields::render in Facebook Instant Articles 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 EntityRow::render

File

src/Plugin/views/row/FiaFields.php, line 40
Contains Drupal\fb_instant_articles\Plugin\views\row\RssFields.

Class

FiaFields
Renders an RSS item based on fields.

Namespace

Drupal\fb_instant_articles\Plugin\views\row

Code

public function render($row) {

  /**
   * @var \Drupal\views\ResultRow $row
   */
  global $base_url;

  /**
   * @var \Drupal\Core\Entity\ContentEntityInterface $entity
   */
  $entity = $row->_entity;

  /**
   * @var []string $options
   */
  $options = $this->options;

  // Create the OPML item array.
  $item = parent::render($row);
  $options['langcode'] = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  switch (true) {
    default:
    case $entity instanceof \Drupal\node\Entity\Node:
      $options['row'] = $row;

      /**
       * @var \Drupal\node\Entity\Node $entity
       */
      $options['title'] = $entity
        ->getTitle();
      $options['author'] = $entity
        ->getOwner()
        ->getAccountName();
      $options['created'] = '@' . $entity
        ->getCreatedTime();
      $options['modified'] = '@' . $entity
        ->getChangedTime();
      $options['link'] = $entity
        ->toLink(NULL, 'canonical', [
        'absolute' => true,
      ]);
      $options['guid'] = $entity
        ->uuid();

      /**
       * @var \Drupal\user\UserInterface $author
       */
      $author = $entity
        ->getOwner();
      $options['author'] = $author
        ->toLink(NULL, 'canonical', [
        'absolute' => true,
      ]);
  }
  $build = [
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $options,
    '#row' => $item,
    '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
  ];
  return $build;
}