public function CustomBreadcrumbsForm::validateForm in Custom Breadcrumbs 1.x
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ CustomBreadcrumbsForm.php, line 232
Class
- CustomBreadcrumbsForm
- Custom breadcrumbs form.
Namespace
Drupal\custom_breadcrumbs\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$pages = $values['breadcrumbPaths'];
$urlList = [];
$urlList = explode(PHP_EOL, $pages);
foreach ($urlList as $url) {
$trimUrl = trim($url);
// Validate Slash.
if ($trimUrl !== '<front>' && $trimUrl !== '<nolink>' && $trimUrl[0] !== '/' && $trimUrl[0] !== '[') {
$form_state
->setErrorByName('pages', $this
->t("@url needs to start with a slash if it is a URL or with a square bracket if it is a token.", [
'@url' => $trimUrl,
]));
}
}
}