function views_plugin_style_rss_fields::options_form in Views RSS 6
Same name and namespace in other branches
- 7 views/views_plugin_style_rss_fields.inc \views_plugin_style_rss_fields::options_form()
Provide a form for setting options.
_state
Parameters
array $form:
File
- views/
views_plugin_style_rss_fields.inc, line 77
Class
- views_plugin_style_rss_fields
- Extend the view_plugin_style class to provide an RSS view style.
Code
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$handlers = $this->display->handler
->get_handlers('field');
if (empty($handlers)) {
$form['error_markup'] = array(
'#value' => t('You need at least one field before you can configure your field settings'),
'#prefix' => '<div class="error form-item description">',
'#suffix' => '</div>',
);
}
else {
// Feed Description
$form['feed_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Feed settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -5,
);
// Legacy setting: previously Feed Description fieldset name was different.
// Should probably rather go to hook_update_N()...
if (isset($this->options['description']['feed_description']) && $this->options['description']['feed_description']) {
$this->options['feed_settings']['feed_description'] = $this->options['description']['feed_description'];
}
$form['feed_settings']['feed_description'] = array(
'#title' => t('Feed description'),
'#type' => 'textarea',
'#default_value' => isset($this->options['feed_settings']['feed_description']) ? $this->options['feed_settings']['feed_description'] : '',
'#description' => t('Description for this feed. If left blank, the default site mission will be used.'),
);
// Namespaces
$form['feed_settings']['namespaces'] = array(
'#type' => 'fieldset',
'#title' => t('XML namespace definitions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Loop through all available fields (both predefined by this module
// as well as those coming from hook_views_rss_item_fields_alter()
// implementations by other modules) and check if there are any other
// namespaces that should be added to configuration form.
$predefined_namespaces = $this
->xml_namespaces();
foreach (array_keys($this
->xml_fields()) as $field_name) {
if (strstr($field_name, ':')) {
list($namespace, $field) = explode(':', $field_name);
// Namespaces predefined by this module should be excluded.
if (!in_array($namespace, array_keys($predefined_namespaces))) {
$form['feed_settings']['namespaces'][$namespace] = array(
'#title' => t('URI reference for "%namespace" namespace', array(
'%namespace' => $namespace,
)),
'#type' => 'textfield',
'#default_value' => isset($this->options['feed_settings']['namespaces'][$namespace]) ? $this->options['feed_settings']['namespaces'][$namespace] : NULL,
'#description' => t("Example: <em>http://base.google.com/ns/1.0</em>"),
);
}
}
}
$form['feed_settings']['feed_in_links'] = array(
'#type' => 'checkbox',
'#default_value' => !empty($this->options['feed_settings']['feed_in_links']),
'#title' => t('Display feed icon in the links attached to the view.'),
'#weight' => 10,
);
// Field Chooser
$field_names = array(
'' => '--',
);
foreach ($handlers as $field => $handler) {
if ($label = $handler
->label()) {
$field_names[$field] = $label;
}
else {
$field_names[$field] = $handler
->ui_name();
}
}
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => 'Field settings',
'#description' => t('Select the fields that relevant data for each element of the feed. See <a href="@guide_url">Views RSS configuration guide</a> for more information.', array(
'@guide_url' => url('http://drupal.org/node/1344136'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 0,
);
foreach ($this
->xml_fields() as $k => $option) {
$form['fields'][$k] = array(
'#type' => 'select',
'#title' => $option['title'],
'#description' => isset($option['description']) ? $option['description'] : '',
'#options' => $field_names,
'#default_value' => $this->options['fields'][$k],
);
}
// GeoRSS
$form['georss'] = array(
'#type' => 'fieldset',
'#title' => t('GeoRSS field settings'),
'#description' => t('Select fields that provide the latitude and longitude values for feed items.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 5,
);
$form['georss']['lat'] = array(
'#type' => 'select',
'#title' => t('Latitude'),
'#options' => $field_names,
'#default_value' => $this->options['georss']['lat'],
);
$form['georss']['lon'] = array(
'#type' => 'select',
'#title' => t('Longitude'),
'#options' => $field_names,
'#default_value' => $this->options['georss']['lon'],
);
$form['georss']['featureName'] = array(
'#type' => 'select',
'#title' => t('Feature Name'),
'#options' => $field_names,
'#default_value' => $this->options['georss']['featureName'],
);
}
}