- Issue created by @Nathan Tsai
- 🇨🇦Canada Nathan Tsai
- Assigned to Nathan Tsai
- 🇨🇦Canada Nathan Tsai
When looking at
<a href="https://api.drupal.org/api/drupal/core%21modules%21taxonomy%21src%21TermStorage.php/function/TermStorage%3A%3AloadTree/8.8.x">TermStorage::loadTree</a>
, we see:if (isset($this->treeParents[$vid][$load_entities ? $term ->id() : $term->tid])) { // Clone the term so that the depth attribute remains correct // in the event of multiple parents. $term = clone $term; }
Therefore, we need to filter out duplicates.
- last update
over 1 year ago 30 pass - @nathan-tsai opened merge request.
- Status changed to Needs review
over 1 year ago 6:05pm 18 July 2023 - 🇨🇦Canada Nathan Tsai
I created a new method to preprocess the result of
TermStorage::loadTree
(including removing the duplicates):/** * Preprocesses the vocabulary taxonomy tree */ protected function getVocabularyTreeArray($vocabulary_tree, $image_field, $vocabulary) { ... }
- 🇨🇦Canada Nathan Tsai
I don't like the additional two parameters:
$image_field
and$vocabulary
.Ideally, we create another method to process the config for us:
/** * Get volcabulary name and image field */ protected function getVocabularyConfig() { $vocabulary_config = $this->configuration['vocabulary']; $vocabulary_config_split = explode('|', $vocabulary_config); return [ 'vocabulary' => $vocabulary_config_split[0] ?? null, 'image_field' => $vocabulary_config_split[1] ?? null, ] }
Or even better, we preprocess the form options when submitting to form, to create the additional keys:
$this->configuration['vocabulary_name']
and$this->configuration['image_field']
. - last update
over 1 year ago 30 pass - 🇨🇦Canada Nathan Tsai
Okay, remove the two additional parameters by just duplicating the processing config approach:
/** * Preprocesses the vocabulary taxonomy tree */ protected function getVocabularyTreeArray($vocabulary_tree) { // TODO: How can we avoid this duplicated work? $vocabulary_config = $this->configuration['vocabulary']; $vocabulary_config = explode('|', $vocabulary_config); $vocabulary = isset($vocabulary_config[0]) ? $vocabulary_config[0] : NULL; $image_field = isset($vocabulary_config[1]) ? $vocabulary_config[1] : NULL; ... }
- Issue was unassigned.
- last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass