You are here

public function OpmlFields::buildOptionsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::buildOptionsForm()

Provide a form for setting options.

Overrides RowPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/row/OpmlFields.php, line 51
Contains \Drupal\views\Plugin\views\row\OpmlFields.

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 = array(
    '' => $this
      ->t('- None -'),
  );
  $view_fields_labels = $this->displayHandler
    ->getFieldLabels();
  $view_fields_labels = array_merge($initial_labels, $view_fields_labels);
  $types = array(
    'rss' => $this
      ->t('RSS'),
    'link' => $this
      ->t('Link'),
    'include' => $this
      ->t('Include'),
  );
  $types = array_merge($initial_labels, $types);
  $form['type_field'] = array(
    '#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'] = array(
    '#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'] = array(
    '#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'] = array(
    '#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' => array(
      'visible' => array(
        ':input[name="row_options[type_field]"]' => array(
          'value' => 'rss',
        ),
      ),
    ),
  );
  $form['html_url_field'] = array(
    '#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' => array(
      'visible' => array(
        ':input[name="row_options[type_field]"]' => array(
          'value' => 'rss',
        ),
      ),
    ),
  );
  $form['language_field'] = array(
    '#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' => array(
      'visible' => array(
        ':input[name="row_options[type_field]"]' => array(
          'value' => 'rss',
        ),
      ),
    ),
  );
  $form['xml_url_field'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('XML URL 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['xml_url_field'],
    '#states' => array(
      'visible' => array(
        ':input[name="row_options[type_field]"]' => array(
          'value' => 'rss',
        ),
      ),
    ),
  );
  $form['url_field'] = array(
    '#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' => array(
      'visible' => array(
        ':input[name="row_options[type_field]"]' => array(
          array(
            'value' => 'link',
          ),
          array(
            'value' => 'include',
          ),
        ),
      ),
    ),
  );
}