function OpmlFields::buildOptionsForm

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::buildOptionsForm()
  2. 10 core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::buildOptionsForm()
  3. 11.x core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::buildOptionsForm()

Overrides RowPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/row/OpmlFields.php, line 46

Class

OpmlFields
Renders an OPML item based on fields.

Namespace

Drupal\views\Plugin\views\row

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $initial_labels = [
        '' => $this->t('- None -'),
    ];
    $view_fields_labels = $this->displayHandler
        ->getFieldLabels();
    $view_fields_labels = array_merge($initial_labels, $view_fields_labels);
    $types = [
        'rss' => $this->t('RSS'),
        'link' => $this->t('Link'),
        'include' => $this->t('Include'),
    ];
    $types = array_merge($initial_labels, $types);
    $form['type_field'] = [
        '#type' => 'select',
        '#title' => $this->t('Type attribute'),
        '#description' => $this->t('The type of this row.'),
        '#options' => $types,
        '#default_value' => $this->options['type_field'],
    ];
    $form['text_field'] = [
        '#type' => 'select',
        '#title' => $this->t('Text attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML text attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['text_field'],
        '#required' => TRUE,
    ];
    $form['created_field'] = [
        '#type' => 'select',
        '#title' => $this->t('Created attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML created attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['created_field'],
    ];
    $form['description_field'] = [
        '#type' => 'select',
        '#title' => $this->t('Description attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML description attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['description_field'],
        '#states' => [
            'visible' => [
                ':input[name="row_options[type_field]"]' => [
                    'value' => 'rss',
                ],
            ],
        ],
    ];
    $form['html_url_field'] = [
        '#type' => 'select',
        '#title' => $this->t('HTML URL attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML htmlUrl attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['html_url_field'],
        '#states' => [
            'visible' => [
                ':input[name="row_options[type_field]"]' => [
                    'value' => 'rss',
                ],
            ],
        ],
    ];
    $form['language_field'] = [
        '#type' => 'select',
        '#title' => $this->t('Language attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML language attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['language_field'],
        '#states' => [
            'visible' => [
                ':input[name="row_options[type_field]"]' => [
                    'value' => 'rss',
                ],
            ],
        ],
    ];
    $form['xml_url_field'] = [
        '#type' => 'select',
        '#title' => $this->t('XML URL attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML XML URL attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['xml_url_field'],
        '#states' => [
            'visible' => [
                ':input[name="row_options[type_field]"]' => [
                    'value' => 'rss',
                ],
            ],
        ],
    ];
    $form['url_field'] = [
        '#type' => 'select',
        '#title' => $this->t('URL attribute'),
        '#description' => $this->t('The field that is going to be used as the OPML URL attribute for each row.'),
        '#options' => $view_fields_labels,
        '#default_value' => $this->options['url_field'],
        '#states' => [
            'visible' => [
                ':input[name="row_options[type_field]"]' => [
                    [
                        'value' => 'link',
                    ],
                    [
                        'value' => 'include',
                    ],
                ],
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.