From 4de61d303974a46ba44736d544cbf8738ff327a1 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 2 Mar 2012 20:35:41 -0500 Subject: [PATCH] dereine suggestion and last customization - Add option_definition implementation. - Let configure the RSS item guid. --- plugins/views_plugin_row_rss_fields.inc | 53 ++++++++++++++++++++++++++---- 1 files changed, 46 insertions(+), 7 deletions(-) diff --git a/plugins/views_plugin_row_rss_fields.inc b/plugins/views_plugin_row_rss_fields.inc index 36a56e5..7e43ce6 100644 --- a/plugins/views_plugin_row_rss_fields.inc +++ b/plugins/views_plugin_row_rss_fields.inc @@ -8,6 +8,18 @@ * Plugin which render an RSS item based on fields. */ class views_plugin_row_rss_fields extends views_plugin_row { + function option_definition() { + $options = parent::option_definition(); + $options['title_field'] = array('default' => 'none'); + $options['link_field'] = array('default' => 'none'); + $options['description_field'] = array('default' => 'none'); + $options['creator_field'] = array('default' => 'none'); + $options['date_field'] = array('default' => 'none'); + $options['guid_field_options']['guid_field'] = array('default' => 'none'); + $options['guid_field_options']['guid_field_is_permalink'] = array('default' => TRUE); + return $options; + } + function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); @@ -51,6 +63,25 @@ class views_plugin_row_rss_fields extends views_plugin_row { '#options' => $view_fields, '#default_value' => $this->options['date_field'], ); + $form['guid_field_options'] = array( + '#type' => 'fieldset', + '#title' => t('GUID settings'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['guid_field_options']['guid_field'] = array( + '#type' => 'select', + '#title' => t('GUID field'), + '#description' => t('The Globally unique identifier of the RSS item.'), + '#options' => $view_fields, + '#default_value' => $this->options['guid_field_options']['guid_field'], + ); + $form['guid_field_options']['guid_field_is_permalink'] = array( + '#type' => 'checkbox', + '#title' => t('GUID is permalink'), + '#description' => t('The RSS item GUID is a permalink.'), + '#default_value' => $this->options['guid_field_options']['guid_field_is_permalink'], + ); } function validate() { @@ -62,11 +93,14 @@ class views_plugin_row_rss_fields extends views_plugin_row { break; } } + // Once more for guid. + if (empty($this->options['guid_field_options']['guid_field']) || $this->options['guid_field_options']['guid_field'] == 'none') { + $errors[] = t('Row style plugin requires specifying which views fields to use for RSS item.'); + } return $errors; } function render($row) { - global $base_url; static $row_index; if (!isset($row_index)) { $row_index = 0; @@ -83,12 +117,17 @@ class views_plugin_row_rss_fields extends views_plugin_row { 'value' => $this->get_field($row_index, $this->options['creator_field']), 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), ), - // @todo let configure this - array( - 'key' => 'guid', - 'value' => $item->link, - 'attributes' => array('isPermaLink' => 'true') - ), + ); + $guid_is_permalink_string = 'false'; + $item_guid = $this->get_field($row_index, $this->options['guid_field_options']['guid_field']); + if ($this->options['guid_field_options']['guid_field_is_permalink']) { + $guid_is_permalink_string = 'true'; + $item_guid = url($item_guid, array('absolute' => TRUE)); + } + $item->elements[] = array( + 'key' => 'guid', + 'value' => $item_guid, + 'attributes' => array('isPermaLink' => $guid_is_permalink_string) ); $row_index++; -- 1.7.9