You are here

protected function RssFields::mapRow in Views RSS 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/row/RssFields.php \Drupal\views_rss\Plugin\views\row\RssFields::mapRow()

Protected fuction mapRow.

1 call to RssFields::mapRow()
RssFields::render in src/Plugin/views/row/RssFields.php
Function render.

File

src/Plugin/views/row/RssFields.php, line 154

Class

RssFields
Renders an RSS item based on fields.

Namespace

Drupal\views_rss\Plugin\views\row

Code

protected function mapRow($row) {
  $rendered_fields = $raw_fields = array();
  $field_ids = array_keys($this->view->field);
  if (!empty($field_ids)) {
    foreach ($field_ids as $field_id) {

      // Render the final field value.
      $rendered_fields[$field_id] = $this
        ->getField($row->index, $field_id);

      // Also let's keep raw value for further processing.
      $raw_fields[$field_id] = array();
      if (method_exists($this->view->field[$field_id], 'getItems')) {
        $raw_fields[$field_id]['items'] = $this->view->field[$field_id]
          ->getItems($row);
      }
    }
  }

  // Rewrite view rows to XML item rows.
  $item_elements = views_rss_get('item_elements');
  foreach ($rendered_fields as $field_id => $rendered_field) {
    $item = $raw_item = array();
    foreach ($item_elements as $module => $module_item_elements) {
      foreach ($module_item_elements as $element => $definition) {
        list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
        if (!empty($this->options['item'][$namespace][$module][$element_name])) {
          $field_name = $this->options['item'][$namespace][$module][$element_name];
        }
        elseif (!empty($definition['group']) && !empty($this->options['item'][$namespace][$module][$definition['group']][$element_name])) {
          $field_name = $this->options['item'][$namespace][$module][$definition['group']][$element_name];
        }
        else {
          $field_name = NULL;
        }

        // Assign values for all elements, not only those defined in view settings.
        // If element value is not defined in view settings, let's just assign NULL.
        // It will not be passed to final theme function anyway during processing
        // taking place in template_preprocess_views_view_views_rss().
        if (!empty($rendered_fields[$field_name])) {
          $item[$module][$element] = $rendered_fields[$field_name];
        }
        else {
          $item[$module][$element] = NULL;
        }

        // Keep raw values too.
        if (!empty($raw_fields[$field_name])) {
          $raw_item[$module][$element] = $raw_fields[$field_name];
        }
      }
    }
  }
  $this->view->views_rss['raw_items'][$row->index] = $raw_item;
  return $item;
}