Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/src/TermForm.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
5 use Drupal\Core\Entity\ContentEntityForm; | 5 use Drupal\Core\Entity\ContentEntityForm; |
6 use Drupal\Core\Form\FormStateInterface; | 6 use Drupal\Core\Form\FormStateInterface; |
7 | 7 |
8 /** | 8 /** |
9 * Base for handler for taxonomy term edit forms. | 9 * Base for handler for taxonomy term edit forms. |
10 * | |
11 * @internal | |
10 */ | 12 */ |
11 class TermForm extends ContentEntityForm { | 13 class TermForm extends ContentEntityForm { |
12 | 14 |
13 /** | 15 /** |
14 * {@inheritdoc} | 16 * {@inheritdoc} |
34 // \Drupal\taxonomy\TermStorageInterface::loadParents() may contain large | 36 // \Drupal\taxonomy\TermStorageInterface::loadParents() may contain large |
35 // numbers of items so we check for taxonomy.settings:override_selector | 37 // numbers of items so we check for taxonomy.settings:override_selector |
36 // before loading the full vocabulary. Contrib modules can then intercept | 38 // before loading the full vocabulary. Contrib modules can then intercept |
37 // before hook_form_alter to provide scalable alternatives. | 39 // before hook_form_alter to provide scalable alternatives. |
38 if (!$this->config('taxonomy.settings')->get('override_selector')) { | 40 if (!$this->config('taxonomy.settings')->get('override_selector')) { |
39 $parent = array_keys($taxonomy_storage->loadParents($term->id())); | 41 $exclude = []; |
40 $children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id()); | 42 if (!$term->isNew()) { |
43 $parent = array_keys($taxonomy_storage->loadParents($term->id())); | |
44 $children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id()); | |
41 | 45 |
42 // A term can't be the child of itself, nor of its children. | 46 // A term can't be the child of itself, nor of its children. |
43 foreach ($children as $child) { | 47 foreach ($children as $child) { |
44 $exclude[] = $child->tid; | 48 $exclude[] = $child->tid; |
49 } | |
50 $exclude[] = $term->id(); | |
45 } | 51 } |
46 $exclude[] = $term->id(); | |
47 | 52 |
48 $tree = $taxonomy_storage->loadTree($vocabulary->id()); | 53 $tree = $taxonomy_storage->loadTree($vocabulary->id()); |
49 $options = ['<' . $this->t('root') . '>']; | 54 $options = ['<' . $this->t('root') . '>']; |
50 if (empty($parent)) { | 55 if (empty($parent)) { |
51 $parent = [0]; | 56 $parent = [0]; |