Added support for default values for <channel> elements
authorMaciej Zgadzaj
Thu, 2 Feb 2012 00:57:11 +0000 (01:57 +0100)
committerMaciej Zgadzaj
Thu, 2 Feb 2012 00:57:11 +0000 (01:57 +0100)
views/views_plugin_style_rss_fields.inc
views/views_rss_views_fields.theme.inc

index 31e4e9b..288f0ad 100644 (file)
@@ -113,10 +113,19 @@ class views_plugin_style_rss_fields extends views_plugin_style {
                 '#collapsed' => TRUE,
               );
             }
+            if (isset($this->options['channel'][$namespace][$element_name])) {
+              $default_value = $this->options['channel'][$namespace][$element_name];
+            }
+            elseif (isset($definition['default_value'])) {
+              $default_value = $definition['default_value'];
+            }
+            else {
+              $default_value = NULL;
+            }
             $form['channel'][$namespace][$element_name] = array(
               '#title' => isset($definition['title']) ? $definition['title'] : $element,
               '#type' => isset($definition['type']) ? $definition['type'] : 'textfield',
-              '#default_value' => isset($this->options['channel'][$namespace][$element_name]) ? $this->options['channel'][$namespace][$element_name] : NULL,
+              '#default_value' => $default_value,
               '#description' => isset($definition['description']) ? $definition['description'] : NULL,
               '#required' => isset($definition['required']) ? $definition['required'] : FALSE,
             );
index ed4cc89..462d646 100644 (file)
@@ -10,7 +10,15 @@ function template_preprocess_views_view_views_rss_fields(&$vars) {
   $vars['channel'] = '';
   foreach ($view->style_plugin->xml_channel_elements() as $element => $definition) {
     list($namespace, $element_name) = $view->style_plugin->extract_element_names($element, 'core');
-    $value = isset($view->style_plugin->options['channel'][$namespace][$element_name]) ? $view->style_plugin->options['channel'][$namespace][$element_name] : NULL;
+    if (isset($view->style_plugin->options['channel'][$namespace][$element_name])) {
+      $value = $view->style_plugin->options['channel'][$namespace][$element_name];
+    }
+    elseif (isset($definition['default_value'])) {
+      $value = $definition['default_value'];
+    }
+    else {
+      $value = NULL;
+    }
     // Preprocess element value.
     if (isset($definition['preprocess functions']) && is_array($definition['preprocess functions'])) {
       foreach ($definition['preprocess functions'] as $preprocess_function) {