public function RssFields::buildOptionsForm in Views RSS 8.2
Same name in this branch
- 8.2 src/Plugin/views/style/RssFields.php \Drupal\views_rss\Plugin\views\style\RssFields::buildOptionsForm()
- 8.2 src/Plugin/views/row/RssFields.php \Drupal\views_rss\Plugin\views\row\RssFields::buildOptionsForm()
Same name and namespace in other branches
- 8.3 src/Plugin/views/row/RssFields.php \Drupal\views_rss\Plugin\views\row\RssFields::buildOptionsForm()
Function buildOptionsForm.
Overrides RowPluginBase::buildOptionsForm
File
- src/
Plugin/ views/ row/ RssFields.php, line 53
Class
- RssFields
- Renders an RSS item based on fields.
Namespace
Drupal\views_rss\Plugin\views\rowCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$initial_labels = array(
'' => $this
->t('- None -'),
);
$view_fields_labels = $this->displayHandler
->getFieldLabels();
$view_fields_labels = array_merge($initial_labels, $view_fields_labels);
$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' => 'details',
'#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::fromUri('http://drupal.org/node/1344136'),
)),
'#open' => FALSE,
);
}
// Prepare form element.
$default_value = NULL;
if (!empty($this->options['item'][$namespace][$module][$element_name])) {
$default_value = $this->options['item'][$namespace][$module][$element_name];
}
elseif (!empty($definition['group'])) {
$default_value = $this->options['item'][$namespace][$module][$definition['group']][$element_name];
}
$form_item = array(
'#type' => 'select',
'#title' => Xss::filter(isset($definition['title']) ? $definition['title'] : $element_name),
'#description' => Xss::filter(isset($definition['description']) ? $definition['description'] : NULL),
'#options' => $view_fields_labels,
'#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'] .= ' ' . Link::fromTextAndUrl('[?]', Url::fromUri($definition['help']), array(
'attributes' => array(
'title' => t('Need more information?'),
),
))
->toString();
}
// 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' => 'details',
'#title' => Xss::filter($group_title),
'#description' => Xss::filter($group_description),
'#open' => FALSE,
);
}
$form['item'][$namespace][$module][$definition['group']][$element_name] = $form_item;
}
else {
$form['item'][$namespace][$module][$element_name] = $form_item;
}
}
}
}
}
}