public function PageGeneralForm::validatePath in Page Manager 8
Same name and namespace in other branches
- 8.4 page_manager_ui/src/Form/PageGeneralForm.php \Drupal\page_manager_ui\Form\PageGeneralForm::validatePath()
File
- page_manager_ui/
src/ Form/ PageGeneralForm.php, line 168 - Contains \Drupal\page_manager_ui\Form\PageGeneralForm.
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.
$value = '/' . trim($element['#value'], '/');
$form_state
->setValueForElement($element, $value);
// Ensure each path is unique.
$path_query = $this->entityQuery
->get('page')
->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.'));
}
}