Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

Assuming Entity API is installed we can use entity_delete_multiple which should be faster than deleting one every time. define("MY_VOCAB", "tags"); function _custom_zap_vocab() { $vocab = taxonomy_vocabulary_machine_name_load(MY_VOCAB); $tree = taxonomy_get_tree($vocab->vid); $tids = array_map(function($term){ return $term->tid; }, $...


1

The vocabulary name is the bundle ID of the term, which you can get through the node object: {{ node.field_taxo.entity.bundle }} This works only when the field has content. For an empty field you would have to dig into the field definition you get from the same field object and check whether the field is restricted to a single target bundle.


2

You can install Devel's submodule Kint, and then in your template print {{ kint() }} to get a pretty-printed dump of all available variables. Unfortunately I couldn't find the vocabulary label/name in there. Only the field label: {{ content.field_taxo_fruit['#title'] }} @4k4's answer below only prints the vocabulary's machine name. But not the label/name. ...


0

It's very simple to create the tree structure output you're looking for: Create the Content type Views, add the Taxonomy term Field next to the Title field, under Format Views settings choose to group by the Taxonomy field Grouping field Nr.1 On the Taxonomy field choose Exclude from display. This will give you a list of nodes that are displayed in ...


0

I have a view set up that sounds similar to what I think you are trying to accomplish: Create your content view filtering by taxonomy. Create your taxonomy view. Go back to your content view and use "no results behavior" under "advanced" and insert your taxonomy view into your content view as a "global view area". Now where there is no content assigned ...


0

Before creating a term, it's better to check if it's exist, here is the code: use Drupal\taxonomy\Entity\Term; if ($terms = taxonomy_term_load_multiple_by_name($term_value, 'vocabulary')) { // Only use the first term returned; there should only be one anyways if we do this right. $term = reset($terms); } else { $term = Term::create([ 'name' => ...


0

That's probably an opinion-based thing and actually also a too broad question. But here's what I'd do: Programmatically create a new block. Provide a hook_theme and your own template to later render the output the way you want. Follow one answer from How to get all node entities tagged with a specific term? to get the data you need. In the block's build() ...


0

For me this solve the problem: # Only attempt to stub real (non-zero) parents. parent_id: - plugin: skip_on_empty method: process source: parent - plugin: migration_lookup migration: d7_taxonomy_term // this migration parent: plugin: default_value default_value: 0 source: '@parent_id' Source: https://...


0

You can also use entity field queries to load by fields on the term $result = \Drupal::entityQuery('taxonomy_term') ->condition('field_my_field_name', 'Whatever Value') ->execute();


0

There are features in Views concerning taxonomy hierarchy, displaying terms with depth, you should look into it. There is also Group by field option under Format in Views where you can, for example, group by Parent field (Parent of the Taxonomy term). You may need to add a Relationship for the Taxonomy field first before you can see those extra Fields/...


0

If anyone else lands here looking for an answer, after going around in circles for many many hours, I found out the solution. When I gave up and was about to recreate a core component in order to overcome this issue, the first thing to do was to delete this taxonomy term, however, Drupal flagged to me that it'd affect the Access Scheme / Taxonomy Main. ...


0

If you need term entity, you can use 'loadByProperties()'. $vid = 'vocabulary_name'; /** @var \Drupal\taxonomy\Entity\Term[] $terms */ $terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => $vid]);


Top 50 recent answers are included