From 1b09c10e002d5da8faceb57f06e9f8cee484da1e Mon Sep 17 00:00:00 2001
From: Jakob Perry <japerry@45640.no-reply.drupal.org>
Date: Fri, 13 Apr 2018 16:55:55 -0500
Subject: [PATCH] #2909040

---
 page_manager_ui/src/Form/PageGeneralForm.php | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/page_manager_ui/src/Form/PageGeneralForm.php b/page_manager_ui/src/Form/PageGeneralForm.php
index 2cf26b1..f33c1c9 100644
--- a/page_manager_ui/src/Form/PageGeneralForm.php
+++ b/page_manager_ui/src/Form/PageGeneralForm.php
@@ -77,6 +77,7 @@ class PageGeneralForm extends FormBase {
       '#title' => $this->t('Path'),
       '#maxlength' => 255,
       '#default_value' => $page->getPath(),
+      '#description' => $this->t('Path to your custom page. Beginning and Ending slashes are automatically removed.'),
       '#required' => TRUE,
       '#element_validate' => [[$this, 'validatePath']],
     ];
@@ -171,18 +172,23 @@ class PageGeneralForm extends FormBase {
     $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(), '<>');
+    if ($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.'));
+      }
     }
-    $path = $path_query->execute();
-    if ($path) {
-      $form_state->setErrorByName('path', $this->t('The page path must be unique.'));
+    // Check to make sure the path exists after stripping slashes.
+    else {
+      $form_state->setErrorByName('path', $this->t("Path is required."));
     }
   }
 
-- 
2.10.1 (Apple Git-78)

