diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -614,6 +614,9 @@ * unit tests with a clean environment. */ function drupal_static_reset($name = NULL) { + if ($name === 'taxonomy_vocabulary_get_names') { + @trigger_error("Using drupal_static_reset() with 'taxonomy_vocabulary_get_names' as parameter is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this usage. See https://www.drupal.org/node/3039041.", E_USER_DEPRECATED); + } drupal_static($name, NULL, TRUE); } @@ -979,9 +982,6 @@ * unit tests with a clean environment. */ function drupal_static_reset($name = NULL) { - if ($name === 'taxonomy_vocabulary_get_names') { - @trigger_error("Using drupal_static_reset() with 'taxonomy_vocabulary_get_names' as parameter is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There's no replacement for this usage. See https://www.drupal.org/node/3039041.", E_USER_DEPRECATED); - } drupal_static($name, NULL, TRUE); } diff -u b/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module --- b/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -211,20 +211,17 @@ * * @return array * A list of existing vocabulary IDs. + * + * @deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use + * \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple() + * instead, to get a list of vocabulary entities keyed by vocabulary ID. + * + * @see https://www.drupal.org/node/3039041 */ function taxonomy_vocabulary_get_names() { - $names = &drupal_static(__FUNCTION__); - - if (!isset($names)) { - $names = []; - $config_names = \Drupal::configFactory()->listAll('taxonomy.vocabulary.'); - foreach ($config_names as $config_name) { - $id = substr($config_name, strlen('taxonomy.vocabulary.')); - $names[$id] = $id; - } - } - - return $names; + @trigger_error('taxonomy_vocabulary_get_names() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal::entityTypeManager()->getStorage("taxonomy_vocabulary")->loadMultiple() instead, to get a list of vocabulary entities keyed by vocabulary ID. See https://www.drupal.org/node/3039041.', E_USER_DEPRECATED); + $vids = array_keys(\Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple()); + return array_combine($vids, $vids); } /** @@ -244,14 +241,7 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { $values = ['name' => trim($name)]; if (isset($vocabulary)) { - $vocabularies = taxonomy_vocabulary_get_names(); - if (isset($vocabularies[$vocabulary])) { - $values['vid'] = $vocabulary; - } - else { - // Return an empty array when filtering by a non-existing vocabulary. - return []; - } + $values['vid'] = $vocabulary; } return \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties($values); } @@ -307,17 +297,20 @@ * * @return array * A list of existing vocabulary IDs. - * - * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use - * \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple() - * instead, to get a list of vocabulary entities keyed by vocabulary ID. - * - * @see https://www.drupal.org/node/3039041 */ function taxonomy_vocabulary_get_names() { - @trigger_error('taxonomy_vocabulary_get_names() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage("taxonomy_vocabulary")->loadMultiple() instead, to get a list of vocabulary entities keyed by vocabulary ID. See https://www.drupal.org/node/3039041.', E_USER_DEPRECATED); - $vids = array_keys(\Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple()); - return array_combine($vids, $vids); + $names = &drupal_static(__FUNCTION__); + + if (!isset($names)) { + $names = []; + $config_names = \Drupal::configFactory()->listAll('taxonomy.vocabulary.'); + foreach ($config_names as $config_name) { + $id = substr($config_name, strlen('taxonomy.vocabulary.')); + $names[$id] = $id; + } + } + + return $names; } /** @@ -337,7 +330,14 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { $values = ['name' => trim($name)]; if (isset($vocabulary)) { - $values['vid'] = $vocabulary; + $vocabularies = taxonomy_vocabulary_get_names(); + if (isset($vocabularies[$vocabulary])) { + $values['vid'] = $vocabulary; + } + else { + // Return an empty array when filtering by a non-existing vocabulary. + return []; + } } return \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties($values); } diff -u b/core/modules/taxonomy/tests/src/Unit/TaxonomyVocabularyTest.php b/core/modules/taxonomy/tests/src/Unit/TaxonomyVocabularyTest.php --- b/core/modules/taxonomy/tests/src/Unit/TaxonomyVocabularyTest.php +++ b/core/modules/taxonomy/tests/src/Unit/TaxonomyVocabularyTest.php @@ -14,7 +14,7 @@ /** * @group legacy - * @expectedDeprecation taxonomy_vocabulary_get_names() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage("taxonomy_vocabulary")->loadMultiple() instead, to get a list of vocabulary entities keyed by vocabulary ID. See https://www.drupal.org/node/3039041. + * @expectedDeprecation taxonomy_vocabulary_get_names() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal::entityTypeManager()->getStorage("taxonomy_vocabulary")->loadMultiple() instead, to get a list of vocabulary entities keyed by vocabulary ID. See https://www.drupal.org/node/3039041. * @see taxonomy_vocabulary_get_names() */ public function testTaxonomyVocabularyGetNamesDeprecation() { @@ -33,7 +33,7 @@ /** * @group legacy - * @expectedDeprecation Using drupal_static_reset() with 'taxonomy_vocabulary_get_names' as parameter is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There's no replacement for this usage. See https://www.drupal.org/node/3039041. + * @expectedDeprecation Using drupal_static_reset() with 'taxonomy_vocabulary_get_names' as parameter is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this usage. See https://www.drupal.org/node/3039041. * @see drupal_static_reset() */ public function testTaxonomyVocabularyGetNamesCacheResetDeprecation() {