comparison core/modules/taxonomy/taxonomy.module @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents c2387f117808
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
4 * @file 4 * @file
5 * Enables the organization of content into categories. 5 * Enables the organization of content into categories.
6 */ 6 */
7 7
8 use Drupal\Component\Utility\Tags; 8 use Drupal\Component\Utility\Tags;
9 use Drupal\Component\Utility\Unicode;
10 use Drupal\Core\Entity\EntityInterface; 9 use Drupal\Core\Entity\EntityInterface;
11 use Drupal\Core\Entity\Sql\SqlContentEntityStorage; 10 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
12 use Drupal\Core\Render\Element; 11 use Drupal\Core\Render\Element;
13 use Drupal\Core\Routing\RouteMatchInterface; 12 use Drupal\Core\Routing\RouteMatchInterface;
14 use Drupal\Core\Url; 13 use Drupal\Core\Url;
51 * Implements hook_help(). 50 * Implements hook_help().
52 */ 51 */
53 function taxonomy_help($route_name, RouteMatchInterface $route_match) { 52 function taxonomy_help($route_name, RouteMatchInterface $route_match) {
54 switch ($route_name) { 53 switch ($route_name) {
55 case 'help.page.taxonomy': 54 case 'help.page.taxonomy':
56 $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#'; 55 $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#';
57 $output = ''; 56 $output = '';
58 $output .= '<h3>' . t('About') . '</h3>'; 57 $output .= '<h3>' . t('About') . '</h3>';
59 $output .= '<p>' . t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', [':permissions' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-taxonomy'])]) . '</p>'; 58 $output .= '<p>' . t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', [':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-taxonomy'])->toString()]) . '</p>';
60 $output .= '<p>' . t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', [':taxonomy' => 'https://www.drupal.org/documentation/modules/taxonomy/']) . '</p>'; 59 $output .= '<p>' . t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', [':taxonomy' => 'https://www.drupal.org/documentation/modules/taxonomy/']) . '</p>';
61 $output .= '<h3>' . t('Uses') . '</h3>'; 60 $output .= '<h3>' . t('Uses') . '</h3>';
62 $output .= '<dl>'; 61 $output .= '<dl>';
63 $output .= '<dt>' . t('Managing vocabularies') . '</dt>'; 62 $output .= '<dt>' . t('Managing vocabularies') . '</dt>';
64 $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', [':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection'), ':field_ui' => $field_ui_url]) . '</dd>'; 63 $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', [':taxonomy_admin' => Url::fromRoute('entity.taxonomy_vocabulary.collection')->toString(), ':field_ui' => $field_ui_url]) . '</dd>';
65 $output .= '<dt>' . t('Managing terms') . '</dt>'; 64 $output .= '<dt>' . t('Managing terms') . '</dt>';
66 $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', [':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection')]) . ' </dd>'; 65 $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', [':taxonomy_admin' => Url::fromRoute('entity.taxonomy_vocabulary.collection')->toString()]) . ' </dd>';
67 $output .= '<dt>' . t('Classifying entity content') . '</dt>'; 66 $output .= '<dt>' . t('Classifying entity content') . '</dt>';
68 $output .= '<dd>' . t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', [':field_ui' => $field_ui_url, ':field' => \Drupal::url('help.page', ['name' => 'field']), ':entity_reference' => \Drupal::url('help.page', ['name' => 'entity_reference'])]) . '</dd>'; 67 $output .= '<dd>' . t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', [':field_ui' => $field_ui_url, ':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':entity_reference' => Url::fromRoute('help.page', ['name' => 'entity_reference'])->toString()]) . '</dd>';
69 $output .= '<dt>' . t('Adding new terms during content creation') . '</dt>'; 68 $output .= '<dt>' . t('Adding new terms during content creation') . '</dt>';
70 $output .= '<dd>' . t("Allowing users to add new terms gradually builds a vocabulary as content is added and edited. Users can add new terms if either of the two <em>Autocomplete</em> widgets is chosen for the Taxonomy term reference field in the <em>Manage form display</em> page for the field. You will also need to enable the <em>Create referenced entities if they don't already exist</em> option, and restrict the field to one vocabulary.") . '</dd>'; 69 $output .= '<dd>' . t("Allowing users to add new terms gradually builds a vocabulary as content is added and edited. Users can add new terms if either of the two <em>Autocomplete</em> widgets is chosen for the Taxonomy term reference field in the <em>Manage form display</em> page for the field. You will also need to enable the <em>Create referenced entities if they don't already exist</em> option, and restrict the field to one vocabulary.") . '</dd>';
71 $output .= '<dt>' . t('Configuring displays and form displays') . '</dt>'; 70 $output .= '<dt>' . t('Configuring displays and form displays') . '</dt>';
72 $output .= '<dd>' . t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', [':entity_reference' => \Drupal::url('help.page', ['name' => 'entity_reference'])]) . '</li>'; 71 $output .= '<dd>' . t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', [':entity_reference' => Url::fromRoute('help.page', ['name' => 'entity_reference'])->toString()]) . '</li>';
73 $output .= '</ul>'; 72 $output .= '</ul>';
74 $output .= '</dd>'; 73 $output .= '</dd>';
75 $output .= '</dl>'; 74 $output .= '</dl>';
76 return $output; 75 return $output;
77 76
78 case 'entity.taxonomy_vocabulary.collection': 77 case 'entity.taxonomy_vocabulary.collection':
79 $output = '<p>' . t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '</p>'; 78 $output = '<p>' . t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '</p>';
80 return $output; 79 return $output;
81 80 }
82 case 'entity.taxonomy_vocabulary.overview_form': 81 }
83 $vocabulary = $route_match->getParameter('taxonomy_vocabulary'); 82
84 if (\Drupal::currentUser()->hasPermission('administer taxonomy') || \Drupal::currentUser()->hasPermission('edit terms in ' . $vocabulary->id())) { 83 /**
85 switch ($vocabulary->getHierarchy()) { 84 * Implements hook_entity_type_alter().
86 case VocabularyInterface::HIERARCHY_DISABLED: 85 */
87 return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>'; 86 function taxonomy_entity_type_alter(array &$entity_types) {
88 case VocabularyInterface::HIERARCHY_SINGLE: 87 // @todo Moderation is disabled for taxonomy terms until when we have an UI
89 return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>'; 88 // for them.
90 case VocabularyInterface::HIERARCHY_MULTIPLE: 89 // @see https://www.drupal.org/project/drupal/issues/2899923
91 return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>'; 90 $entity_types['taxonomy_term']->setHandlerClass('moderation', '');
92 }
93 }
94 else {
95 switch ($vocabulary->getHierarchy()) {
96 case VocabularyInterface::HIERARCHY_DISABLED:
97 return '<p>' . t('%capital_name contains the following terms.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
98 case VocabularyInterface::HIERARCHY_SINGLE:
99 return '<p>' . t('%capital_name contains terms grouped under parent terms', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
100 case VocabularyInterface::HIERARCHY_MULTIPLE:
101 return '<p>' . t('%capital_name contains terms with multiple parents.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
102 }
103 }
104 }
105 } 91 }
106 92
107 /** 93 /**
108 * Entity URI callback. 94 * Entity URI callback.
109 */ 95 */
122 foreach ($term->uriRelationships() as $rel) { 108 foreach ($term->uriRelationships() as $rel) {
123 // Set the URI relationships, like canonical. 109 // Set the URI relationships, like canonical.
124 $page['#attached']['html_head_link'][] = [ 110 $page['#attached']['html_head_link'][] = [
125 [ 111 [
126 'rel' => $rel, 112 'rel' => $rel,
127 'href' => $term->url($rel), 113 'href' => $term->toUrl($rel)->toString(),
128 ], 114 ],
129 TRUE, 115 TRUE,
130 ]; 116 ];
131 117
132 // Set the term path as the canonical URL to prevent duplicate content. 118 // Set the term path as the canonical URL to prevent duplicate content.
133 if ($rel == 'canonical') { 119 if ($rel == 'canonical') {
134 // Set the non-aliased canonical path as a default shortlink. 120 // Set the non-aliased canonical path as a default shortlink.
135 $page['#attached']['html_head_link'][] = [ 121 $page['#attached']['html_head_link'][] = [
136 [ 122 [
137 'rel' => 'shortlink', 123 'rel' => 'shortlink',
138 'href' => $term->url($rel, ['alias' => TRUE]), 124 'href' => $term->toUrl($rel, ['alias' => TRUE])->toString(),
139 ], 125 ],
140 TRUE, 126 TRUE,
141 ]; 127 ];
142 } 128 }
143 } 129 }
154 ], 140 ],
155 ]; 141 ];
156 } 142 }
157 143
158 /** 144 /**
159 * Checks and updates the hierarchy flag of a vocabulary. 145 * Checks the hierarchy flag of a vocabulary.
160 * 146 *
161 * Checks the current parents of all terms in a vocabulary and updates the 147 * Checks the current parents of all terms in a vocabulary. If no term has
162 * vocabulary's hierarchy setting to the lowest possible level. If no term 148 * parent terms then the vocabulary will be given a hierarchy of
163 * has parent terms then the vocabulary will be given a hierarchy of
164 * VocabularyInterface::HIERARCHY_DISABLED. If any term has a single parent then 149 * VocabularyInterface::HIERARCHY_DISABLED. If any term has a single parent then
165 * the vocabulary will be given a hierarchy of 150 * the vocabulary will be given a hierarchy of
166 * VocabularyInterface::HIERARCHY_SINGLE. If any term has multiple parents then 151 * VocabularyInterface::HIERARCHY_SINGLE. If any term has multiple parents then
167 * the vocabulary will be given a hierarchy of 152 * the vocabulary will be given a hierarchy of
168 * VocabularyInterface::HIERARCHY_MULTIPLE. 153 * VocabularyInterface::HIERARCHY_MULTIPLE.
170 * @param \Drupal\taxonomy\VocabularyInterface $vocabulary 155 * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
171 * A taxonomy vocabulary entity. 156 * A taxonomy vocabulary entity.
172 * @param $changed_term 157 * @param $changed_term
173 * An array of the term structure that was updated. 158 * An array of the term structure that was updated.
174 * 159 *
175 * @return 160 * @return int
176 * An integer that represents the level of the vocabulary's hierarchy. 161 * An integer that represents the level of the vocabulary's hierarchy.
162 *
163 * @deprecated in Drupal 8.7.x. Will be removed before Drupal 9.0.0. Use
164 * \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType() instead.
177 */ 165 */
178 function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $changed_term) { 166 function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $changed_term) {
179 $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vocabulary->id()); 167 @trigger_error('taxonomy_check_vocabulary_hierarchy() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.x. Use \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType() instead.', E_USER_DEPRECATED);
180 $hierarchy = VocabularyInterface::HIERARCHY_DISABLED; 168 return \Drupal::entityTypeManager()->getStorage('taxonomy_term')->getVocabularyHierarchyType($vocabulary->id());
181 foreach ($tree as $term) {
182 // Update the changed term with the new parent value before comparison.
183 if ($term->tid == $changed_term['tid']) {
184 $term = (object) $changed_term;
185 $term->parents = $term->parent;
186 }
187 // Check this term's parent count.
188 if (count($term->parents) > 1) {
189 $hierarchy = VocabularyInterface::HIERARCHY_MULTIPLE;
190 break;
191 }
192 elseif (count($term->parents) == 1 && !isset($term->parents[0])) {
193 $hierarchy = VocabularyInterface::HIERARCHY_SINGLE;
194 }
195 }
196 if ($hierarchy != $vocabulary->getHierarchy()) {
197 $vocabulary->setHierarchy($hierarchy);
198 $vocabulary->save();
199 }
200
201 return $hierarchy;
202 } 169 }
203 170
204 /** 171 /**
205 * Generates an array which displays a term detail page. 172 * Generates an array which displays a term detail page.
206 * 173 *
272 $variables['view_mode'] = $variables['elements']['#view_mode']; 239 $variables['view_mode'] = $variables['elements']['#view_mode'];
273 $variables['term'] = $variables['elements']['#taxonomy_term']; 240 $variables['term'] = $variables['elements']['#taxonomy_term'];
274 /** @var \Drupal\taxonomy\TermInterface $term */ 241 /** @var \Drupal\taxonomy\TermInterface $term */
275 $term = $variables['term']; 242 $term = $variables['term'];
276 243
277 $variables['url'] = $term->url(); 244 $variables['url'] = $term->toUrl()->toString();
278 // We use name here because that is what appears in the UI. 245 // We use name here because that is what appears in the UI.
279 $variables['name'] = $variables['elements']['name']; 246 $variables['name'] = $variables['elements']['name'];
280 unset($variables['elements']['name']); 247 unset($variables['elements']['name']);
281 $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term); 248 $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
282 249
372 * 339 *
373 * This function should be used whenever you need to load more than one term 340 * This function should be used whenever you need to load more than one term
374 * from the database. Terms are loaded into memory and will not require 341 * from the database. Terms are loaded into memory and will not require
375 * database access if loaded again during the same page request. 342 * database access if loaded again during the same page request.
376 * 343 *
377 * @see entity_load_multiple()
378 * @see \Drupal\Core\Entity\Query\EntityQueryInterface
379 *
380 * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
381 * Use \Drupal\taxonomy\Entity\Term::loadMultiple().
382 *
383 * @param array $tids 344 * @param array $tids
384 * (optional) An array of entity IDs. If omitted, all entities are loaded. 345 * (optional) An array of entity IDs. If omitted, all entities are loaded.
385 * 346 *
386 * @return array 347 * @return array
387 * An array of taxonomy term entities, indexed by tid. When no results are 348 * An array of taxonomy term entities, indexed by tid. When no results are
388 * found, an empty array is returned. 349 * found, an empty array is returned.
350 *
351 * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
352 * \Drupal\taxonomy\Entity\Term::loadMultiple().
353 *
354 * @see https://www.drupal.org/node/2266845
389 */ 355 */
390 function taxonomy_term_load_multiple(array $tids = NULL) { 356 function taxonomy_term_load_multiple(array $tids = NULL) {
357 @trigger_error('taxonomy_term_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Term::loadMultiple(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
391 return Term::loadMultiple($tids); 358 return Term::loadMultiple($tids);
392 } 359 }
393 360
394 /** 361 /**
395 * Loads multiple taxonomy vocabularies based on certain conditions. 362 * Loads multiple taxonomy vocabularies based on certain conditions.
396 * 363 *
397 * This function should be used whenever you need to load more than one 364 * This function should be used whenever you need to load more than one
398 * vocabulary from the database. Terms are loaded into memory and will not 365 * vocabulary from the database. Terms are loaded into memory and will not
399 * require database access if loaded again during the same page request. 366 * require database access if loaded again during the same page request.
400 * 367 *
401 * @see entity_load_multiple()
402 *
403 * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
404 * Use \Drupal\taxonomy\Entity\Vocabulary::loadMultiple().
405 *
406 * @param array $vids 368 * @param array $vids
407 * (optional) An array of entity IDs. If omitted, all entities are loaded. 369 * (optional) An array of entity IDs. If omitted, all entities are loaded.
408 * 370 *
409 * @return array 371 * @return array
410 * An array of vocabulary objects, indexed by vid. 372 * An array of vocabulary objects, indexed by vid.
373 *
374 * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
375 * \Drupal\taxonomy\Entity\Vocabulary::loadMultiple().
376 *
377 * @see https://www.drupal.org/node/2266845
411 */ 378 */
412 function taxonomy_vocabulary_load_multiple(array $vids = NULL) { 379 function taxonomy_vocabulary_load_multiple(array $vids = NULL) {
380 @trigger_error('taxonomy_vocabulary_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Vocabulary::loadMultiple(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
413 return Vocabulary::loadMultiple($vids); 381 return Vocabulary::loadMultiple($vids);
414 } 382 }
415 383
416 /** 384 /**
417 * Return the taxonomy vocabulary entity matching a vocabulary ID. 385 * Return the taxonomy vocabulary entity matching a vocabulary ID.
418 *
419 * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
420 * Use \Drupal\taxonomy\Entity\Vocabulary::load().
421 * 386 *
422 * @param int $vid 387 * @param int $vid
423 * The vocabulary's ID. 388 * The vocabulary's ID.
424 * 389 *
425 * @return \Drupal\taxonomy\Entity\Vocabulary|null 390 * @return \Drupal\taxonomy\Entity\Vocabulary|null
426 * The taxonomy vocabulary entity, if exists, NULL otherwise. Results are 391 * The taxonomy vocabulary entity, if exists, NULL otherwise. Results are
427 * statically cached. 392 * statically cached.
393 *
394 * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
395 * \Drupal\taxonomy\Entity\Vocabulary::load().
396 *
397 * @see https://www.drupal.org/node/2266845
428 */ 398 */
429 function taxonomy_vocabulary_load($vid) { 399 function taxonomy_vocabulary_load($vid) {
400 @trigger_error('taxonomy_vocabulary_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Vocabulary::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
430 return Vocabulary::load($vid); 401 return Vocabulary::load($vid);
431 } 402 }
432 403
433 /** 404 /**
434 * Return the taxonomy term entity matching a term ID. 405 * Return the taxonomy term entity matching a term ID.
435 *
436 * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
437 * Use \Drupal\taxonomy\Entity\Term::load().
438 * 406 *
439 * @param $tid 407 * @param $tid
440 * A term's ID 408 * A term's ID
441 * 409 *
442 * @return \Drupal\taxonomy\Entity\Term|null 410 * @return \Drupal\taxonomy\Entity\Term|null
443 * A taxonomy term entity, or NULL if the term was not found. Results are 411 * A taxonomy term entity, or NULL if the term was not found. Results are
444 * statically cached. 412 * statically cached.
413 *
414 * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
415 * Drupal\taxonomy\Entity\Term::load().
416 *
417 * @see https://www.drupal.org/node/2266845
445 */ 418 */
446 function taxonomy_term_load($tid) { 419 function taxonomy_term_load($tid) {
420 @trigger_error('taxonomy_term_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Term::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
447 if (!is_numeric($tid)) { 421 if (!is_numeric($tid)) {
448 return NULL; 422 return NULL;
449 } 423 }
450 return Term::load($tid); 424 return Term::load($tid);
451 } 425 }
546 } 520 }
547 } 521 }
548 } 522 }
549 // Insert index entries for all the node's terms. 523 // Insert index entries for all the node's terms.
550 if (!empty($tid_all)) { 524 if (!empty($tid_all)) {
525 $connection = \Drupal::database();
551 foreach ($tid_all as $tid) { 526 foreach ($tid_all as $tid) {
552 db_merge('taxonomy_index') 527 $connection->merge('taxonomy_index')
553 ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()]) 528 ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
554 ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()]) 529 ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
555 ->execute(); 530 ->execute();
556 } 531 }
557 } 532 }
585 * @param \Drupal\Core\Entity\EntityInterface $node 560 * @param \Drupal\Core\Entity\EntityInterface $node
586 * The node entity. 561 * The node entity.
587 */ 562 */
588 function taxonomy_delete_node_index(EntityInterface $node) { 563 function taxonomy_delete_node_index(EntityInterface $node) {
589 if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) { 564 if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) {
590 db_delete('taxonomy_index')->condition('nid', $node->id())->execute(); 565 \Drupal::database()->delete('taxonomy_index')->condition('nid', $node->id())->execute();
591 } 566 }
592 } 567 }
593 568
594 /** 569 /**
595 * Implements hook_ENTITY_TYPE_delete() for taxonomy_term entities. 570 * Implements hook_ENTITY_TYPE_delete() for taxonomy_term entities.
596 */ 571 */
597 function taxonomy_taxonomy_term_delete(Term $term) { 572 function taxonomy_taxonomy_term_delete(Term $term) {
598 if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) { 573 if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) {
599 // Clean up the {taxonomy_index} table when terms are deleted. 574 // Clean up the {taxonomy_index} table when terms are deleted.
600 db_delete('taxonomy_index')->condition('tid', $term->id())->execute(); 575 \Drupal::database()->delete('taxonomy_index')->condition('tid', $term->id())->execute();
601 } 576 }
602 } 577 }
603 578
604 /** 579 /**
605 * @} End of "defgroup taxonomy_index". 580 * @} End of "defgroup taxonomy_index".