public function PageGeneralForm::validatePath in Page Manager 8.4
Same name and namespace in other branches
- 8 page_manager_ui/src/Form/PageGeneralForm.php \Drupal\page_manager_ui\Form\PageGeneralForm::validatePath()
File
- page_manager_ui/
src/ Form/ PageGeneralForm.php, line 163
Class
Namespace
Drupal\page_manager_ui\FormCode
public function validatePath(&$element, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/** @var $page \Drupal\page_manager\Entity\Page */
$page = $cached_values['page'];
// Ensure the path has a leading slash.
if ($value = trim($element['#value'], '/')) {
$value = '/' . $value;
$form_state
->setValueForElement($element, $value);
// Ensure each path is unique.
$path_query = $this->pageStorage
->getQuery()
->condition('path', $value);
if (!$page
->isNew()) {
$path_query
->condition('id', $page
->id(), '<>');
}
$path = $path_query
->execute();
if ($path) {
$form_state
->setErrorByName('path', $this
->t('The page path must be unique.'));
}
}
else {
$form_state
->setErrorByName('path', $this
->t("Path is required."));
}
}