AnswerBun.com

taxonomy_term entity loadByProperties depth not found

Drupal Answers Asked by Sivaji on October 9, 2020

The terms returned contain depth as a Term object attribute.

$vocabulary = 'category';
$entity_manager = Drupal::entityTypeManager();
$entity_storage = $entity_manager->getStorage('taxonomy_term');
$terms = $entity_storage->loadTree($vocabulary);

However, when I try to load terms by depth, I get an error.

$entity_manager = Drupal::entityTypeManager();
$entity_storage = $entity_manager->getStorage('taxonomy_term');
$terms = $entity_storage->loadByProperties([
  'vid' => $vocabulary,
  'depth' => 0,
]);

The error is the following.

Uncaught PHP Exception DrupalCoreEntityQueryQueryException: "’depth’ not found

What is the way to find attributes I can use on loadByProperties()?

One Answer

What is the way to find attributes I can use on loadByProperties()?

I guess with Devel's Kint, loading one and then looking at the "iterator contents" tab

  $entity_manager = Drupal::entityTypeManager();
  $entity_storage = $entity_manager->getStorage('taxonomy_term');
  $term = $entity_storage->load(1);
  kint($term);

enter image description here

Correct answer by No Sssweat on October 9, 2020

Add your own answers!

Related Questions

How to programmatically reference entities?

1  Asked on October 26, 2021 by sveggen

   

custom action plugin with ConfigurationForm

1  Asked on October 26, 2021

     

grouped paragraphs by field not filtering to current language

1  Asked on October 26, 2021 by turpentyne

     

How do I migrate node entity references?

0  Asked on October 26, 2021 by alexandre

     

Form textfield AJAX validation “deletes” injected services to form

1  Asked on October 26, 2021 by pedro-tentugal

   

Allowing anonymous users to contact node authors

1  Asked on October 26, 2021 by aroopk

     

How to cache a view for all users of a role?

1  Asked on October 26, 2021 by ktrev

     

Is it feasible to migrate by only migrating content?

2  Asked on October 26, 2021 by benjen

   

Get the breadcrumbs for a specific node other than the current

1  Asked on October 26, 2021 by nils-riedemann

     

Views exposed filters without “Apply” button

3  Asked on October 26, 2021

   

Saving form data and running custom queries in mysql

1  Asked on October 26, 2021 by benn-moffat

     

Add additional fields to the postal address

1  Asked on October 26, 2021 by jay-haase

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP