function RowPluginBase::buildOptionsForm
Same name in other branches
- 9 core/modules/views/src/Plugin/views/row/RowPluginBase.php \Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm()
- 8.9.x core/modules/views/src/Plugin/views/row/RowPluginBase.php \Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm()
- 11.x 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
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.
File
-
core/
modules/ views/ src/ Plugin/ views/ row/ RowPluginBase.php, line 88
Class
- RowPluginBase
- Base class for Views row plugins.
Namespace
Drupal\views\Plugin\views\rowCode
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, $this->displayHandler, $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',
];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.