Top-level taxonomy term entity query

Created on 16 January 2023, over 2 years ago
Updated 25 January 2023, over 2 years ago

Problem/Motivation

This query doesn't work:

// Gimme all top-level terms from 'topic' vocab.
$tids = \Drupal::entityTypeManager::getStorage('taxonomy_term')
  ->getQuery()
  ->accessCheck(FALSE)
  ->condition('vid', 'topic')
  ->condition('parent', '0')
  ->execute();

Especially after 🐛 Latest core taxonomy changes are breaking rdf_taxonomy Fixed , fixing this became trickier as we define a top-level term in two ways:

  • When the term's vocabulary doesn't provide a parent mapping -> it's a top-level term
  • When the term has multiple parent triples (aka multiple parents) and one of them is the vocab RDF type' -> it's (also) a top-level term

Steps to reproduce

Write a kernel regression test

Proposed resolution

Some hints:

  • Implement hook_query_sparql_reference_alter() and check for a 'parent' condition (=, !=, <>, IN, NOT IN) with '0' value.
  • If found, move the condition in an OR conjunction and add also a 'parent (NOT) EXISTS' condition under OR.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024