function views_rss_plugin_style_fields::options_form in Views RSS 7.2
Same name and namespace in other branches
- 6.2 views/views_rss_plugin_style_fields.inc \views_rss_plugin_style_fields::options_form()
Provide a form for setting options.
_state
Parameters
array $form:
Overrides views_plugin_style::options_form
File
- views/
views_rss_plugin_style_fields.inc, line 92 - Extends the view_plugin_style class to provide new RSS view style.
Class
- views_rss_plugin_style_fields
- @file Extends the view_plugin_style class to provide new 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)) {
drupal_set_message(t('You need at least one field before you can configure your field settings.'), 'error');
}
else {
// 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();
}
}
// Element groups could be used both in channel and item settings.
$element_groups = views_rss_get('element_groups');
// Channel elements settings.
$channel_elements = views_rss_get('channel_elements');
if (count($channel_elements)) {
foreach ($channel_elements as $module => $module_channel_elements) {
foreach ($module_channel_elements as $element => $definition) {
if (!isset($definition['configurable']) || $definition['configurable']) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Add fieldset for namespace if not yet added.
if (!isset($form['channel'][$namespace])) {
$form['channel'][$namespace] = array(
'#type' => 'fieldset',
'#title' => t('Channel elements : @namespace', array(
'@namespace' => $namespace,
)),
'#description' => t('Provide values for <channel> elements in "@namespace" namespace. See <a href="@guide_url">Views RSS documentation</a> for more information.', array(
'@namespace' => $namespace,
'@guide_url' => url('http://drupal.org/node/1344136'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
// Prepare form element.
$default_value = NULL;
if (!empty($this->options['channel'][$namespace][$module][$element_name])) {
$default_value = $this->options['channel'][$namespace][$module][$element_name];
}
$form_item = array(
'#type' => 'textfield',
'#title' => filter_xss(isset($definition['title']) ? $definition['title'] : $element_name),
'#description' => filter_xss(isset($definition['description']) ? $definition['description'] : NULL),
'#default_value' => $default_value,
);
// Allow to overwrite default form element.
if (!empty($definition['settings form'])) {
$form_item = array_merge($form_item, $definition['settings form']);
// Make sure that #options is an associative array.
if (!empty($definition['settings form']['#options'])) {
$form_item['#options'] = views_rss_map_assoc($definition['settings form']['#options']);
}
}
if (!empty($definition['settings form options callback'])) {
$function = $definition['settings form options callback'];
$form_item['#options'] = views_rss_map_assoc($function());
}
// Add help link if provided.
if (!empty($definition['help'])) {
$form_item['#description'] .= ' ' . l('[?]', $definition['help'], array(
'attributes' => array(
'title' => t('Need more information?'),
),
));
}
// Check if element should be displayed in a subgroup.
if (!empty($definition['group'])) {
// Add a subgroup to the form if it not yet added.
if (!isset($form['channel'][$namespace][$module][$definition['group']])) {
// Does module provide the group definition?
$group_title = !empty($element_groups[$module][$definition['group']]['title']) ? $element_groups[$module][$definition['group']]['title'] : $definition['group'];
$group_description = !empty($element_groups[$module][$definition['group']]['description']) ? $element_groups[$module][$definition['group']]['description'] : NULL;
$form['channel'][$namespace][$module][$definition['group']] = array(
'#type' => 'fieldset',
'#title' => filter_xss($group_title),
'#description' => filter_xss($group_description),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
$form['channel'][$namespace][$module][$definition['group']][$element_name] = $form_item;
}
else {
$form['channel'][$namespace][$module][$element_name] = $form_item;
}
}
}
}
}
// Item elements settings.
$item_elements = views_rss_get('item_elements');
if (count($item_elements)) {
foreach ($item_elements as $module => $module_item_elements) {
foreach ($module_item_elements as $element => $definition) {
if (!isset($definition['configurable']) || $definition['configurable']) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Add fieldset for namespace if not yet added.
if (!isset($form['item'][$namespace])) {
$form['item'][$namespace] = array(
'#type' => 'fieldset',
'#title' => t('Item elements : @namespace', array(
'@namespace' => $namespace,
)),
'#description' => t('Select fields containing relevant values for <item> elements in "@namespace" namespace. See <a href="@guide_url">Views RSS documentation</a> for more information.', array(
'@namespace' => $namespace,
'@guide_url' => url('http://drupal.org/node/1344136'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
// Prepare form element.
$default_value = NULL;
if (!empty($this->options['item'][$namespace][$module][$element_name])) {
$default_value = $this->options['item'][$namespace][$module][$element_name];
}
$form_item = array(
'#type' => 'select',
'#title' => filter_xss(isset($definition['title']) ? $definition['title'] : $element_name),
'#description' => filter_xss(isset($definition['description']) ? $definition['description'] : NULL),
'#options' => $field_names,
'#default_value' => $default_value,
);
// Allow to overwrite default form element.
if (!empty($definition['settings form'])) {
$form_item = array_merge($form_item, $definition['settings form']);
// Make sure that #options is an associative array.
if (!empty($definition['settings form']['#options'])) {
$form_item['#options'] = views_rss_map_assoc($definition['settings form']['#options']);
}
}
// Add help link if provided.
if (isset($definition['help']) && $definition['help']) {
$form_item['#description'] .= ' ' . l('[?]', $definition['help'], array(
'attributes' => array(
'title' => t('Need more information?'),
),
));
}
// Check if element should be displayed in a subgroup.
if (isset($definition['group']) && $definition['group']) {
// Add a subgroup to the form if it not yet added.
if (!isset($form['item'][$namespace][$module][$definition['group']])) {
// Does module provide the group definition?
$group_title = !empty($element_groups[$module][$definition['group']]['title']) ? $element_groups[$module][$definition['group']]['title'] : $definition['group'];
$group_description = !empty($element_groups[$module][$definition['group']]['description']) ? $element_groups[$module][$definition['group']]['description'] : NULL;
$form['item'][$namespace][$module][$definition['group']] = array(
'#type' => 'fieldset',
'#title' => filter_xss($group_title),
'#description' => filter_xss($group_description),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
$form['item'][$namespace][$module][$definition['group']][$element_name] = $form_item;
}
else {
$form['item'][$namespace][$module][$element_name] = $form_item;
}
}
}
}
}
// Undefined namespaces derived from <channel> and/or <item>
// elements defined by extension modules.
$namespaces = views_rss_get('namespaces');
if (count($namespaces)) {
foreach ($namespaces as $module => $module_namespaces) {
foreach ($module_namespaces as $namespace => $definition) {
if (empty($definition['uri'])) {
// Add fieldset for namespace if not yet added.
if (!isset($form['namespaces'])) {
$form['namespaces'] = array(
'#type' => 'fieldset',
'#title' => t('Namespaces'),
'#description' => t('Enter missing URLs for namespaces derived from <channel> and/or <item> elements defined by extension modules.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
if (!empty($this->options['namespaces'][$module][$namespace])) {
$default_value = $this->options['namespaces'][$module][$namespace];
}
else {
$default_value = NULL;
}
$form['namespaces'][$module][$namespace] = array(
'#type' => 'textfield',
'#title' => check_plain($namespace),
'#default_value' => $default_value,
);
}
}
}
}
// Other feed settings.
$form['feed_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Other feed settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['feed_settings']['absolute_paths'] = array(
'#type' => 'checkbox',
'#title' => t("Replace relative paths with absolute URLs"),
'#description' => t('Enabling this option will replace all relative paths (like <em>/node/1</em>) with absolute URLs (<em>!absolute_url</em>) in all feed elements configured to use this feature (for example <description> element).', array(
'!absolute_url' => trim($GLOBALS['base_url'], '/') . '/node/1',
)),
'#default_value' => !empty($this->options['feed_settings']['absolute_paths']) || !isset($this->options['feed_settings']['absolute_paths']),
'#weight' => 1,
);
$form['feed_settings']['feed_in_links'] = array(
'#type' => 'checkbox',
'#title' => t('Display feed icon in the links attached to the view'),
'#default_value' => !empty($this->options['feed_settings']['feed_in_links']),
'#weight' => 3,
);
}
}