public function SqlBase::validateOptionsForm in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::validateOptionsForm()
Provide the default form form for validating options.
Overrides PagerPluginBase::validateOptionsForm
File
- core/
modules/ views/ src/ Plugin/ views/ pager/ SqlBase.php, line 226
Class
- SqlBase
- A common base class for sql based pager.
Namespace
Drupal\views\Plugin\views\pagerCode
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
// Only accept integer values.
$error = FALSE;
$exposed_options = $form_state
->getValue([
'pager_options',
'expose',
'items_per_page_options',
]);
if (strpos($exposed_options, '.') !== FALSE) {
$error = TRUE;
}
$options = explode(',', $exposed_options);
if (!$error && is_array($options)) {
foreach ($options as $option) {
if (!is_numeric($option) || intval($option) == 0) {
$error = TRUE;
}
}
}
else {
$error = TRUE;
}
if ($error) {
$form_state
->setErrorByName('pager_options][expose][items_per_page_options', $this
->t('Insert a list of integer numeric values separated by commas: e.g: 10, 20, 50, 100'));
}
// Make sure that the items_per_page is part of the expose settings.
if (!$form_state
->isValueEmpty([
'pager_options',
'expose',
'items_per_page',
]) && !$form_state
->isValueEmpty([
'pager_options',
'items_per_page',
])) {
$items_per_page = $form_state
->getValue([
'pager_options',
'items_per_page',
]);
if (array_search($items_per_page, $options) === FALSE) {
$form_state
->setErrorByName('pager_options][expose][items_per_page_options', $this
->t("The <em>Exposed items per page</em> field's options must include the value from the <em>Items per page</em> field (@items_per_page).", [
'@items_per_page' => $items_per_page,
]));
}
}
}