New answers tagged

1 vote

Unable to add newly created term to the node

To append an entity reference item use: $node->field_foo[] = ['target_id' => 123]; And as Kevin noted in the comments, make sure you save the entity. $node->save();
user avatar
  • 163k
0 votes

Related content by taxonomy term but using a relationship between terms

I solved this using Views Token Arguments - solution here: https://www.drupal.org/forum/support/post-installation/2022-05-07/related-content-by-taxonomy-term-but-using-a-relationship-between-terms
user avatar
  • 55
0 votes

Token service not replacing text with term as a token

Drupal out-of-the-box has only basic token support, which can replace core entity standard fields like [term:name] or [term:description]. Configured fields, usually those with a prefix field_, need ...
user avatar
  • 86.9k
0 votes

How to display a comma-separated list of multiple field values?

The https://drupal.stackexchange.com/a/238069/5501 should work. However if you need to remove all markup from the output and ensure no whitespaces/new lines exists in it then it become tricky: items|...
user avatar
0 votes

How can I get the machine name of a taxonomy term knowing its tid?

With D8 something like this. $parameters = \Drupal::routeMatch()->getParameters()->all(); if (isset($parameters['taxonomy_term'])) { $term = $parameters['taxonomy_term']; $vid = $term->...
user avatar
0 votes

Retrieve translated taxonomy term in current language programatically

An approach in preprocess node (handles multiple term references): function HOOK_preprocess_node(&$variables) { $node = $variables['node']; $langcode = \Drupal::languageManager()->...
user avatar
  • 1,829

Top 50 recent answers are included