1<?php
2
3namespace Drupal\taxonomy;
4
5use Drupal\Core\Entity\EntityInterface;
6use Drupal\Core\Entity\ContentEntityStorageInterface;
7
8/**
9 * Defines an interface for taxonomy_term entity storage classes.
10 */
11interface TermStorageInterface extends ContentEntityStorageInterface {
12
13  /**
14   * Removed reference to terms from term_hierarchy.
15   *
16   * @param array $tids
17   *   Array of terms that need to be removed from hierarchy.
18   *
19   * @todo Remove this method in Drupal 9.0.x. Now the parent references are
20   *   automatically cleared when deleting a taxonomy term.
21   *   https://www.drupal.org/node/2785693
22   */
23  public function deleteTermHierarchy($tids);
24
25  /**
26   * Updates terms hierarchy information with the hierarchy trail of it.
27   *
28   * @param \Drupal\Core\Entity\EntityInterface $term
29   *   Term entity that needs to be added to term hierarchy information.
30   *
31   * @todo remove this method Drupal 9.0.x. Now the parent references are
32   *   automatically updates when when a taxonomy term is added/updated.
33   *   https://www.drupal.org/node/2785693
34   */
35  public function updateTermHierarchy(EntityInterface $term);
36
37  /**
38   * Finds all parents of a given term ID.
39   *
40   * @param int $tid
41   *   Term ID to retrieve parents for.
42   *
43   * @return \Drupal\taxonomy\TermInterface[]
44   *   An array of term objects which are the parents of the term $tid.
45   */
46  public function loadParents($tid);
47
48  /**
49   * Finds all ancestors of a given term ID.
50   *
51   * @param int $tid
52   *   Term ID to retrieve ancestors for.
53   *
54   * @return \Drupal\taxonomy\TermInterface[]
55   *   An array of term objects which are the ancestors of the term $tid.
56   */
57  public function loadAllParents($tid);
58
59  /**
60   * Finds all children of a term ID.
61   *
62   * @param int $tid
63   *   Term ID to retrieve children for.
64   * @param string $vid
65   *   An optional vocabulary ID to restrict the child search.
66   *
67   * @return \Drupal\taxonomy\TermInterface[]
68   *   An array of term objects that are the children of the term $tid.
69   */
70  public function loadChildren($tid, $vid = NULL);
71
72  /**
73   * Finds all terms in a given vocabulary ID.
74   *
75   * @param string $vid
76   *   Vocabulary ID to retrieve terms for.
77   * @param int $parent
78   *   The term ID under which to generate the tree. If 0, generate the tree
79   *   for the entire vocabulary.
80   * @param int $max_depth
81   *   The number of levels of the tree to return. Leave NULL to return all
82   *   levels.
83   * @param bool $load_entities
84   *   If TRUE, a full entity load will occur on the term objects. Otherwise
85   *   they are partial objects queried directly from the {taxonomy_term_data}
86   *   table to save execution time and memory consumption when listing large
87   *   numbers of terms. Defaults to FALSE.
88   *
89   * @return object[]|\Drupal\taxonomy\TermInterface[]
90   *   An array of term objects that are the children of the vocabulary $vid.
91   */
92  public function loadTree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE);
93
94  /**
95   * Count the number of nodes in a given vocabulary ID.
96   *
97   * @param string $vid
98   *   Vocabulary ID to retrieve terms for.
99   *
100   * @return int
101   *   A count of the nodes in a given vocabulary ID.
102   */
103  public function nodeCount($vid);
104
105  /**
106   * Reset the weights for a given vocabulary ID.
107   *
108   * @param string $vid
109   *   Vocabulary ID to retrieve terms for.
110   */
111  public function resetWeights($vid);
112
113  /**
114   * Returns all terms used to tag some given nodes.
115   *
116   * @param array $nids
117   *   Node IDs to retrieve terms for.
118   * @param array $vocabs
119   *   (optional) A vocabularies array to restrict the term search. Defaults to
120   *   empty array.
121   * @param string $langcode
122   *   (optional) A language code to restrict the term search. Defaults to NULL.
123   *
124   * @return array
125   *   An array of nids and the term entities they were tagged with.
126   */
127  public function getNodeTerms(array $nids, array $vocabs = [], $langcode = NULL);
128
129  /**
130   * Returns the hierarchy type for a specific vocabulary ID.
131   *
132   * @param string $vid
133   *   Vocabulary ID to retrieve the hierarchy type for.
134   *
135   * @return int
136   *   The vocabulary hierarchy.
137   *   Possible values:
138   *    - VocabularyInterface::HIERARCHY_DISABLED: No parents.
139   *    - VocabularyInterface::HIERARCHY_SINGLE: Single parent.
140   *    - VocabularyInterface::HIERARCHY_MULTIPLE: Multiple parents.
141   */
142  public function getVocabularyHierarchyType($vid);
143
144  /**
145   * Gets a list of term IDs with pending revisions.
146   *
147   * @return int[]
148   *   An array of term IDs which have pending revisions, keyed by their
149   *   revision IDs.
150   *
151   * @internal
152   */
153  public function getTermIdsWithPendingRevisions();
154
155}
156