You are here

function podcast_preprocess_views_view_field in Podcast (using Views) 8

Implements hook_preprocess_HOOK().

File

./podcast.module, line 101
Primary module hooks for the podcast module.

Code

function podcast_preprocess_views_view_field(&$variables) {

  /** @var \Drupal\views\Plugin\views\field\EntityField $field */
  $field = $variables['field'];

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  $style = $view->style_plugin;
  if (!$style instanceof Rss) {
    return;
  }
  $find_mapping_key = function ($current_field, $options) {
    foreach ($options as $field_mapping => $field_name) {
      if ($current_field === $field_name) {
        $clean_key = preg_replace('/_field$/u', '', $field_mapping);
        $clean_key = Html::cleanCssIdentifier($clean_key);
        return $clean_key;
      }
    }
    return NULL;
  };
  $cdataFields = [
    'description',
    'itunessummary',
    'itunesseason',
    'itunesepisode',
  ];
  if (in_array($find_mapping_key($field->options['id'], $style->options), $cdataFields, TRUE) || in_array($find_mapping_key($field->options['id'], $view->rowPlugin->options), $cdataFields, TRUE)) {
    $variables['output'] = ViewsRenderPipelineMarkup::create('<![CDATA[' . $variables['output'] . ']]>');
  }
}