Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / taxonomy / src / TermForm.php
index 1eae95a0d4f3bfcd32440d1c505b74732a93c981..6de48e0af4b66a66713ba351f68bce69d6bb2f03 100644 (file)
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
 
 /**
  * Base for handler for taxonomy term edit forms.
+ *
+ * @internal
  */
 class TermForm extends ContentEntityForm {
 
@@ -36,14 +38,17 @@ class TermForm extends ContentEntityForm {
     // before loading the full vocabulary. Contrib modules can then intercept
     // before hook_form_alter to provide scalable alternatives.
     if (!$this->config('taxonomy.settings')->get('override_selector')) {
-      $parent = array_keys($taxonomy_storage->loadParents($term->id()));
-      $children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id());
-
-      // A term can't be the child of itself, nor of its children.
-      foreach ($children as $child) {
-        $exclude[] = $child->tid;
+      $exclude = [];
+      if (!$term->isNew()) {
+        $parent = array_keys($taxonomy_storage->loadParents($term->id()));
+        $children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id());
+
+        // A term can't be the child of itself, nor of its children.
+        foreach ($children as $child) {
+          $exclude[] = $child->tid;
+        }
+        $exclude[] = $term->id();
       }
-      $exclude[] = $term->id();
 
       $tree = $taxonomy_storage->loadTree($vocabulary->id());
       $options = ['<' . $this->t('root') . '>'];