function FilterPluginBase::validateIdentifier
Same name in other branches
- 8.9.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateIdentifier()
- 10 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateIdentifier()
- 11.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::validateIdentifier()
Validates a filter identifier.
Sets the form error if $form_state is passed or an error string if $form_state is not passed.
Parameters
string $identifier: The identifier to check.
\Drupal\Core\Form\FormStateInterface $form_state: (optional) The current state of the form.
array $form_group: (optional) The form element to set any errors on.
Return value
string
3 calls to FilterPluginBase::validateIdentifier()
- FilterPluginBase::buildGroupValidate in core/
modules/ views/ src/ Plugin/ views/ filter/ FilterPluginBase.php - Validate the build group options form.
- FilterPluginBase::validate in core/
modules/ views/ src/ Plugin/ views/ filter/ FilterPluginBase.php - Validate that the plugin is correct and can be saved.
- FilterPluginBase::validateExposeForm in core/
modules/ views/ src/ Plugin/ views/ filter/ FilterPluginBase.php - Validate the options form.
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ FilterPluginBase.php, line 761
Class
- FilterPluginBase
- Base class for Views filters handler plugins.
Namespace
Drupal\views\Plugin\views\filterCode
protected function validateIdentifier($identifier, FormStateInterface $form_state = NULL, &$form_group = []) {
$error = '';
if (empty($identifier)) {
$error = $this->t('The identifier is required if the filter is exposed.');
}
elseif ($identifier == 'value') {
$error = $this->t('This identifier is not allowed.');
}
elseif (preg_match('/[^a-zA-Z0-9_~\\.\\-]+/', $identifier)) {
$error = $this->t('This identifier has illegal characters.');
}
if ($form_state && !$this->view->display_handler
->isIdentifierUnique($form_state->get('id'), $identifier)) {
$error = $this->t('This identifier is used by another handler.');
}
if (!empty($form_state) && !empty($error)) {
$form_state->setError($form_group, $error);
}
return $error;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.