Problem/Motivation

Part of #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() effort.

Proposed resolution

Deprecate the following taxonomy.module procedural functions:

taxonomy_vocabulary_get_names()
taxonomy_term_uri()
taxonomy_term_load_multiple_by_name()
taxonomy_terms_static_reset()
taxonomy_vocabulary_static_reset()
taxonomy_implode_tags()
taxonomy_term_title()

Deprecate usage of drupal_static_reset() with 'taxonomy_vocabulary_get_names' as parameter.

Remaining tasks

None.

User interface changes

None.

API changes

See Proposed resolution section.

Data model changes

None.

Release notes snippet

N/A

Issue fork drupal-3039039

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

Patch.

claudiu.cristea’s picture

StatusFileSize
new9.53 KB

Ouch!

jibran’s picture

Status: Needs review » Reviewed & tested by the community

This makes sense to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

error: core/modules/taxonomy/tests/src/Functional/VocabularyCrudTest.php: does not exist in index

alexpott’s picture

  1. +++ b/core/includes/bootstrap.inc
    @@ -950,6 +950,10 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
    +    return;
    

    The return here is not correct. We should still continue with the original behaviour even though it is pointless. Deprecations should by and large not change behaviour.

  2. +++ b/core/modules/taxonomy/taxonomy.module
    @@ -337,8 +334,7 @@ function taxonomy_vocabulary_get_names() {
       if (isset($vocabulary)) {
    -    $vocabularies = taxonomy_vocabulary_get_names();
    -    if (isset($vocabularies[$vocabulary])) {
    +    if (\Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->load($vocabulary)) {
           $values['vid'] = $vocabulary;
         }
         else {
    

    I don't get why we both checking for the existence of the vocabulary. We don't save a query because a non-existent vocab will need a query to work out it doesn't exist and if we only did:

      if (isset($vocabulary)) {
        $values['vid'] = $vocabulary;
      }
    

    We'd still get an empty array and the taxonomy_term_data table has a key on vid so the query will be quick if it doesn't exist.

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new9.46 KB
new9.46 KB

I made the changes on points #6.1 and #6.2 (even if I'm not sure about point 2).
The patch has also been rerolled, as VocabularyCrudTest has been moved from Functional to Kernel test.

pguillard’s picture

yogeshmpawar’s picture

Issue tags: -Needs reroll

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

hardik_patel_12’s picture

StatusFileSize
new9.46 KB
new6.53 KB

Changing deprecation message from Drupal 8.8.0 and will be removed before Drupal 9.0.0 to Drupal 9.1.0 and will be removed before Drupal 10.0.0.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs review » Needs work

Sorry but the deprecation needs updating again.

claudiu.cristea’s picture

@alexpott, I disagree with #6.1 because there's no replacement for this deprecation. The only thing we need, if taxonomy_vocabulary_get_names is passed, is to trigger the deprecation message. Here we're not replacing a procedural function with a service. However, it doesn't hurt, just that conceptually I think it's not quite OK.

claudiu.cristea’s picture

Status: Needs work » Needs review
  • Fixed message Drupal versions, including the change record.
  • Using $this->expectDeprecation() instead of annotation.
  • Compacted the test and converted into a kernel test to avoid the container Hocus Pocus.
  • Changed the if(...) from drupal_static_reset() into a switch() {...} anticipating other deprecations.
longwave’s picture

Status: Needs review » Reviewed & tested by the community

RTBC for these changes, +1 to using a switch in drupal_static_reset.

I think all the legacy code in the argument validator plugins can be removed, I can't see how it can ever work, but that's for a followup (or an issue might already exist).

longwave’s picture

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Big fan of this issue. This is a thing I wanted cleaned up as a subsystem maintainer for Taxonomy (but the whole release management thing got in the way). A few nitpicks and a couple questions:

  1. +++ b/core/includes/bootstrap.inc
    @@ -614,6 +614,9 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
    +    @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);
    

    We're at 9.3 now.

    Also, we normally avoid contractions in core text (so "There is" rather than "There's").

  2. +++ b/core/modules/taxonomy/src/VocabularyStorage.php
    @@ -9,14 +9,6 @@
    -  /**
    -   * {@inheritdoc}
    -   */
    -  public function resetCache(array $ids = NULL) {
    -    drupal_static_reset('taxonomy_vocabulary_get_names');
    -    parent::resetCache($ids);
    -  }
    -
    

    Hmm, is it safe to just rip out this method implementation?

  3. +++ b/core/modules/taxonomy/taxonomy.module
    @@ -211,20 +211,17 @@ function taxonomy_vocabulary_static_reset(array $ids = NULL) {
    + * @deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use
    ...
    +  @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);
    

    Ditto on updating this to say 9.3.

  4. +++ b/core/modules/taxonomy/taxonomy.module
    @@ -244,14 +241,7 @@ function taxonomy_vocabulary_get_names() {
    -    else {
    -      // Return an empty array when filtering by a non-existing vocabulary.
    -      return [];
    -    }
    

    What's happening to this code path? Does this case have test coverage?

  5. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -92,11 +92,6 @@ public function testTaxonomyVocabularyLoadMultiple() {
    -    // Fetch the names for all vocabularies, confirm that they are keyed by
    -    // machine name.
    -    $names = taxonomy_vocabulary_get_names();
    -    $this->assertEquals($vocabulary1->id(), $names[$vocabulary1->id()]);
    

    This test coverage should maybe be moved to a legacy test?
     

  6. Finally, I think the CR should also mention the bit about the static cache.

Thanks for working on this!

claudiu.cristea’s picture

Status: Needs work » Needs review

#21.1, 3: Fixed.
#21.2: Why wouldn't be? Keeping drupal_static_reset('taxonomy_vocabulary_get_names'); there would trigger the deprecation message. If we remove then, there's only the call to the parent.
#21.4: Added a test for the whole procedural function. However, that function is only used in tests. Shouldn't we deprecate it in this issue too?
#21.5: Moved the coverage in legacy test.
#21.6: Fixed.

catch’s picture

Makes sense to me to deprecate taxonomy_term_load_multiple_by_name() here as well.

claudiu.cristea’s picture

OK, deprecated also taxonomy_term_load_multiple_by_name(). Note that I've moved the taxonomy_term_load_multiple_by_name() coverage in deprecation/legacy test. Anyway, the test was wrongly a functional test. It should have been kernel test.

claudiu.cristea’s picture

Title: Deprecate taxonomy_vocabulary_get_names() » Deprecate taxonomy_vocabulary_get_names() & taxonomy_term_load_multiple_by_name()
claudiu.cristea’s picture

Going to the rest of procedural functions from taxonomy.module:

  • taxonomy_implode_tags(): Not used anywhere, not even in tests.
  • taxonomy_term_title(): Just a wrapper around $term->getName(), which is a wrapper around $term->label().
  • taxonomy_terms_static_reset(): Wraps \Drupal::entityTypeManager()->getStorage('taxonomy_term')->resetCache();.
  • taxonomy_vocabulary_static_reset(): Wraps \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->resetCache($ids).

Any clue if it's appropriate to deprecate them in this step?

catch’s picture

@claudiu.cristea if they don't have usages (or just one or two), then it makes sense to me to deprecate them in one issue - it's unlikely to conflict with other patches, a single change record will make things easier to find etc.

claudiu.cristea’s picture

Title: Deprecate taxonomy_vocabulary_get_names() & taxonomy_term_load_multiple_by_name() » Deprecate some procedural functions in taxonomy.module
Issue summary: View changes

Updated title, IS and CR as per #23 and #27.

claudiu.cristea’s picture

Issue summary: View changes

Fixed the test and remarks from @Berdir.

claudiu.cristea’s picture

Issue summary: View changes

Addressed @catch remarks.

daffie’s picture

We are using the MR in this issue.

tim.plunkett’s picture

Status: Needs review » Needs work

That "legacy" code in the Views handlers was removed from core in #1552396: Convert vocabularies into configuration but accidentally reintroduced in #1850792-26: Make init() method consistent across all views plugins. Because of that isset() check, it has been dead code this entire time, and the whole init() method can be removed in both cases.

xjm’s picture

Re: #32, I believe @tim.plunkett is referring to @longwave's comment here.

I think cleaning that up could be a followup issue? Since replacing the prodedural functions with entity API calls are 1:1 changes, but removing dead code in views handlers is a different logical scope.

tedbow made their first commit to this issue’s fork.

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community
Related issues: +#3221149: Remove dead code in Taxonomy's Views handlers

I opened a follow-up here: #3221149: Remove dead code in Taxonomy's Views handlers
With that out of the way, the rest of the patch seems fine. Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs work

NW for the above point about the scope creep of rewriting the legacy test vs. the original one. They should be kept as similar as possible. Thanks!

claudiu.cristea’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @claudiu.cristea, the test changes are so much more straightforward now. I like that you kept the new test additions too.

alexpott’s picture

I think that #3221149: Remove dead code in Taxonomy's Views handlers should land before this patch. It removes all runtime usages of taxonomy_term_load_multiple_by_name() except for taxonomy_term_load_multiple_by_name() (which itself is only called by test code) and makes the performance impact of this patch non-existent. If this patch lands first it will result in additional queries because we're calling \Drupal::entityQuery('taxonomy_vocabulary')->execute(); instead of taxonomy_vocabulary_get_names(). The old code implements a static cache whereas entity queries are uncached and results in additional queries to the config table.

xjm’s picture

This issue is RTBC. That one is not. Either is easy to reroll. Therefore, since I think this is also committable, I'm going to go ahead and commit this despite #39.

  • xjm committed 4f77a10 on 9.3.x
    Issue #3039039 by claudiu.cristea, pguillard, Hardik_Patel_12, tedbow,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 9.3.x and published the CR. Thanks!

@pguillard, in the future, please include interdiffs when updating patches. (For merge requests, they are not needed.) Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.