Problem/Motivation

There have been several occasions where I have needed a list of all the terms associated with a given entity. Most notably, when working on the DART and DFP modules it is desirable to include the terms of the current node (or other entity) in the ad tag for targeting purposes. In d6 this was easily accomplished with taxonomy_node_get_terms

Proposed resolution

add a function to taxonomy.module called taxonomy_get_entity_terms()

Remaining tasks

needs review

Comments

lliss’s picture

Status: Needs review » Needs work

So far as I can tell this does not work. I tested by adding terms to a node. Then ran

$node = node_load(1);
$result = taxonomy_get_entity_terms($node, 'node');

and got an error.

bleen’s picture

Issue tags: +Needs tests

Ill take a look and add tests

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB

This patch works, and also adds a simpletest

Status: Needs review » Needs work

The last submitted patch, taxonomy_get_entity_terms.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB

this passes locally

Status: Needs review » Needs work

The last submitted patch, taxonomy_get_entity_terms.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB

huh? ... try this testbot

lliss’s picture

StatusFileSize
new2.36 KB

Need a comment for the bundle parameter. With that exception the code seems fine and the tests passed. So I think it is fine to add, particularly since it's a helper funtion and probably won't be called very often so far as I can tell.

star-szr’s picture

Status: Needs review » Needs work

Thanks @bleen18 and @lliss! A couple minor points.

  1. +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.phpundefined
    @@ -172,6 +172,17 @@ class TermTest extends TaxonomyTestBase {
    +    $this->assertTrue(empty($diff), 'All the terms were successfully retrieved using taxonomy_get_entity_terms() wthout any extras.');
    +
    +
    

    The wording of this assertion message might be confusing out of context. Maybe something like "The correct terms were retrieved using taxonomy_get_entity_terms()."? It also looks there is an extra newline here.

  2. +++ b/core/modules/taxonomy/taxonomy.moduleundefined
    @@ -906,6 +906,37 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities
    + * @param $bundle
    + *  The bundle name for which to return instances.
    

    There should be another space before this parameter description.

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB

A good suggestion and a good catch (in that order)

star-szr’s picture

StatusFileSize
new2.33 KB

Looks good, thanks @bleen18! Rerolled to get rid of the tab character :)

bleen’s picture

#11: 1613196-11.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1613196-11.patch, failed testing.

mgifford’s picture

Assigned: bleen » Unassigned
Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

eric115’s picture

It looks like this didn't make it into Drupal 7 either, so I am going to mark this as a feature request instead of a bug.

As a side note if anyone needs something like this for their project, maybe consider creating a trait that can be used on bundle classes now that bundle classes are available in core.

eric115’s picture

Title: There should exist a method to retrieve all taxonomy terms associated with an entity (regression from D6) » Add a method to retrieve all taxonomy terms associated with an entity (regression from D6)
Category: Bug report » Feature request

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.