You are here

public function RowPluginBase::buildOptionsForm in Drupal 9

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

Provide a form for setting options.

Overrides PluginBase::buildOptionsForm

7 calls to RowPluginBase::buildOptionsForm()
DataFieldRow::buildOptionsForm in core/modules/rest/src/Plugin/views/row/DataFieldRow.php
Provide a form for setting options.
EntityRow::buildOptionsForm in core/modules/views/src/Plugin/views/row/EntityRow.php
Provide a form for setting options.
Fields::buildOptionsForm in core/modules/views/src/Plugin/views/row/Fields.php
Provide a form for setting options.
OpmlFields::buildOptionsForm in core/modules/views/src/Plugin/views/row/OpmlFields.php
Provide a form for setting options.
RowTest::buildOptionsForm in core/modules/views/tests/modules/views_test_data/src/Plugin/views/row/RowTest.php
Provide a form for setting options.

... See full list

8 methods override RowPluginBase::buildOptionsForm()
DataFieldRow::buildOptionsForm in core/modules/rest/src/Plugin/views/row/DataFieldRow.php
Provide a form for setting options.
EntityRow::buildOptionsForm in core/modules/views/src/Plugin/views/row/EntityRow.php
Provide a form for setting options.
Fields::buildOptionsForm in core/modules/views/src/Plugin/views/row/Fields.php
Provide a form for setting options.
OpmlFields::buildOptionsForm in core/modules/views/src/Plugin/views/row/OpmlFields.php
Provide a form for setting options.
RowTest::buildOptionsForm in core/modules/views/tests/modules/views_test_data/src/Plugin/views/row/RowTest.php
Provide a form for setting options.

... See full list

File

core/modules/views/src/Plugin/views/row/RowPluginBase.php, line 76

Class

RowPluginBase
Base class for Views row plugins.

Namespace

Drupal\views\Plugin\views\row

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  if (isset($this->base_table)) {
    $executable = $form_state
      ->get('view')
      ->getExecutable();

    // A whole bunch of code to figure out what relationships are valid for
    // this item.
    $relationships = $executable->display_handler
      ->getOption('relationships');
    $relationship_options = [];
    foreach ($relationships as $relationship) {
      $relationship_handler = Views::handlerManager('relationship')
        ->getHandler($relationship);

      // If this relationship is valid for this type, add it to the list.
      $data = Views::viewsData()
        ->get($relationship['table']);
      $base = $data[$relationship['field']]['relationship']['base'];
      if ($base == $this->base_table) {
        $relationship_handler
          ->init($executable, $relationship);
        $relationship_options[$relationship['id']] = $relationship_handler
          ->adminLabel();
      }
    }
    if (!empty($relationship_options)) {
      $relationship_options = array_merge([
        'none' => $this
          ->t('Do not use a relationship'),
      ], $relationship_options);
      $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
      if (empty($relationship_options[$rel])) {

        // Pick the first relationship.
        $rel = key($relationship_options);
      }
      $form['relationship'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Relationship'),
        '#options' => $relationship_options,
        '#default_value' => $rel,
      ];
    }
    else {
      $form['relationship'] = [
        '#type' => 'value',
        '#value' => 'none',
      ];
    }
  }
}