You are here

public function DataFieldRow::buildOptionsForm in Zircon Profile 8

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

Provide a form for setting options.

Overrides RowPluginBase::buildOptionsForm

File

core/modules/rest/src/Plugin/views/row/DataFieldRow.php, line 77
Contains \Drupal\rest\Plugin\views\row\DataFieldRow.

Class

DataFieldRow
Plugin which displays fields as raw data.

Namespace

Drupal\rest\Plugin\views\row

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['field_options'] = array(
    '#type' => 'table',
    '#header' => array(
      $this
        ->t('Field'),
      $this
        ->t('Alias'),
      $this
        ->t('Raw output'),
    ),
    '#empty' => $this
      ->t('You have no fields. Add some to your view.'),
    '#tree' => TRUE,
  );
  $options = $this->options['field_options'];
  if ($fields = $this->view->display_handler
    ->getOption('fields')) {
    foreach ($fields as $id => $field) {
      $form['field_options'][$id]['field'] = array(
        '#markup' => $id,
      );
      $form['field_options'][$id]['alias'] = array(
        '#title' => $this
          ->t('Alias for @id', array(
          '@id' => $id,
        )),
        '#title_display' => 'invisible',
        '#type' => 'textfield',
        '#default_value' => isset($options[$id]['alias']) ? $options[$id]['alias'] : '',
        '#element_validate' => array(
          array(
            $this,
            'validateAliasName',
          ),
        ),
      );
      $form['field_options'][$id]['raw_output'] = array(
        '#title' => $this
          ->t('Raw output for @id', array(
          '@id' => $id,
        )),
        '#title_display' => 'invisible',
        '#type' => 'checkbox',
        '#default_value' => isset($options[$id]['raw_output']) ? $options[$id]['raw_output'] : '',
      );
    }
  }
}