protected function WizardPluginBase::defaultDisplaySortsUser in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplaySortsUser()
- 9 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplaySortsUser()
Retrieves sort information based on user input for the default display.
Parameters
array $form: The full wizard form array.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the wizard form.
Return value
array An array of sort arrays keyed by ID. A sort array contains the options accepted by a sort handler.
1 call to WizardPluginBase::defaultDisplaySortsUser()
- WizardPluginBase::defaultDisplaySorts in core/
modules/ views/ src/ Plugin/ views/ wizard/ WizardPluginBase.php - Retrieves all sort information used by the default display.
File
- core/
modules/ views/ src/ Plugin/ views/ wizard/ WizardPluginBase.php, line 1015
Class
- WizardPluginBase
- Base class for Views wizard plugins.
Namespace
Drupal\views\Plugin\views\wizardCode
protected function defaultDisplaySortsUser($form, FormStateInterface $form_state) {
$sorts = [];
// Don't add a sort if there is no form value or the user set the sort to
// 'none'.
if (($sort_type = $form_state
->getValue([
'show',
'sort',
])) && $sort_type != 'none') {
[
$column,
$sort,
] = explode(':', $sort_type);
// Column either be a column-name or the table-column-name.
$column = explode('-', $column);
if (count($column) > 1) {
$table = $column[0];
$column = $column[1];
}
else {
$table = $this->base_table;
$column = $column[0];
}
// If the input is invalid, for example when the #default_value contains
// created from node, but the wizard type is another base table, make
// sure it is not added. This usually don't happen if you have js
// enabled.
$data = Views::viewsData()
->get($table);
if (isset($data[$column]['sort'])) {
$sorts[$column] = [
'id' => $column,
'table' => $table,
'field' => $column,
'order' => $sort,
'entity_type' => $data['table']['entity type'] ?? NULL,
'entity_field' => $data[$column]['entity field'] ?? NULL,
'plugin_id' => $data[$column]['sort']['id'],
];
}
}
return $sorts;
}