You are here

protected function RssFields::getChannelElements in Views RSS 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/RssFields.php \Drupal\views_rss\Plugin\views\style\RssFields::getChannelElements()

Return an array of additional XHTML elements to add to the channel.

Return value

An array that can be passed to format_xml_elements().

1 call to RssFields::getChannelElements()
RssFields::render in src/Plugin/views/style/RssFields.php
Render the display in this style.

File

src/Plugin/views/style/RssFields.php, line 302
Definition of Drupal\views\Plugin\views\style\Rss.

Class

RssFields
Default style plugin to render an RSS feed from fields.

Namespace

Drupal\views_rss\Plugin\views\style

Code

protected function getChannelElements() {
  $elements = array();
  foreach (views_rss_get('channel_elements') as $module => $module_channel_elements) {
    foreach ($module_channel_elements as $element => $definition) {
      list($element_namespace, $element_name) = views_rss_extract_element_names($element, 'core');

      // Try to fetch namespace value from view configuration.
      if (isset($this->options['channel'][$element_namespace][$module][$element_name])) {
        $element_value = $this->options['channel'][$element_namespace][$module][$element_name];
      }
      elseif (isset($definition['default_value'])) {
        $element_value = $definition['default_value'];
      }
      else {
        $element_value = NULL;
      }

      // Start building XML channel element array compatible with
      // format_xml_elements().
      $rss_element = array(
        'key' => $element,
        'value' => $element_value,
      );
      if (!empty($element_namespace) && $element_namespace != 'core') {
        $rss_element['namespace'] = $element_namespace;
      }

      // It might happen than a preprocess function will need to split one
      // element into multiple ones - this will for example happen for channel
      // <category> element, if multiple categories were provided (separated
      // by a comma) - they will need to be printed as multiple <category>
      // elements - therefore we need to work on array of RSS elements here.
      $rss_elements = array(
        $rss_element,
      );

      // Preprocess element value.
      if (isset($definition['preprocess functions']) && is_array($definition['preprocess functions'])) {
        foreach ($definition['preprocess functions'] as $preprocess_function) {
          if (function_exists($preprocess_function)) {
            $item_variables = array(
              'elements' => &$rss_elements,
              'item' => $this->options['channel'],
              'view' => $this->view,
            );
            $preprocess_function($item_variables);
          }
        }
      }
      foreach ($rss_elements as $rss_element) {
        if (!empty($rss_element['value']) || !empty($rss_element['attributes'])) {
          $elements[] = $rss_element;
        }
      }
    }
  }
  return $elements;
}