Create a constant for root term ID

Created on 17 November 2023, 8 months ago
Updated 1 March 2024, 4 months ago

Problem/Motivation

Follow up from โœจ Create TermInterface methods ::hasRootParent(), ::hasNonRootParent() Needs review
The taxonomy term can have root(0) as parent, which is hardcoded at multiple places.
So as per the suggestion in the related issue, it was advised to create a constant for the root and use that constant instead of hardcoding 0.
Comment link - https://git.drupalcode.org/project/drupal/-/merge_requests/5171#note_231753
E.g
if ($term->parents[0] == 0)

Steps to reproduce

NA

Proposed resolution

  1. Add a constant
  2. Replace hardcoded 0 used for root parent with the constant

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Taxonomyย  โ†’

Last updated 4 days ago

  • Maintained by
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States @xjm
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @smustgrave
  • First commit to issue fork.
  • Assigned to jigarius
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada jigarius Montrรฉal

    Working on it.

  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada jigarius Montrรฉal

    I didn't change it in any tests though. Maybe we should continue to verify a hard-corded '0' in the tests. Opinions? Suggestions?

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Think if we are going to add a constant we should use it in the tests also.

  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada jigarius Montrรฉal

    I've updated the tests to use TermInterface::ID_ROOT. Additionally, I found some more instances of "0", which I've replaced.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Just in OverviewTerms.php there seem to be 6 places the constant could be used.

  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankithashetty Karnataka, India

    MR updated with relevant changes, please review.

    Thanks!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    @ankithashetty thanks but this was assigned to another user just fyi.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankithashetty Karnataka, India

    My apologies. I kind of missed it. Will make sure to check that next time.โœŒ๐Ÿผ

  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Believe instances have been addressed, left a question for the committer.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    hanks for working on improving Drupal core.

    The issue summary here should explain the problem being solved. This needs an issue summary update to add that and to provide links to the relevant comments in the other issue. Remember, that not all reviewers or committers will be familiar with the originating issue. Let's make an issue inviting for reviewers and committers. Issue summaries do matter. โ†’

    Thanks.

  • Status changed to Needs review 7 months ago
  • Issue was unassigned.
  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    IS seems to have been updated.

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    @ankithashetty, thanks for updating the Issue Summary. It is much easier to understand and thus inviting for a reviewer.

    The diff no longer applies, this needs to be rebased locally.

    I do think this needs a different name for the constant, as stated in the MR. Ideas?

    How can we be sure that all test instances have been changed? What can I do as a reviewer to be sure? For example, I did a little digging and found there is a method \Drupal\Tests\taxonomy\Functional\TermTest::getParentTids that refers top 0 and not the new constant. Nor, have the usages of that method been changed to use the new constant.

    Setting to NW for the above.

  • The constant name 'TERM_ROOT_ID' can be misleading as it might be interpreted as the ID for the root term itself.

    However, the constant actually holds the ID for the parent of the root term.
    It would be more accurate to name the constant something like "ROOT_TERM_PARENT_ID."

    I have identified other scenarios where this constant needs to be used, and I am currently working on it.

  • Status changed to Needs review 6 months ago
  • I have renamed ID_ROOT to ROOT_TERM_ID and updated few more places with new constant.

    I see parent term id hardcoded in many test files. Do we need to replace those test files?

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Believe we should use the constant in tests also.

  • Status changed to Needs review 6 months ago
  • Updated remaining files with the constant ROOT_TERM_ID.

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Believe test replacements have been completed.

  • Status changed to Needs work 4 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia kostyashupenko Omsk
  • ๐Ÿ‡ท๐Ÿ‡บRussia kostyashupenko Omsk

    Rebased, conflicts were resolved carefully. However it needs review again.

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Seems to have check errors

Production build 0.69.0 2024