Problem/Motivation

Using a linked taxonomy term "Name" field in a view throws a fatal error on generating the URI. The error is: "The "taxonomy_term" entity type has not been saved, and cannot have a URI." This happens because we are using a stub entity created using entity_create() instead of loading the full term. The problematic code:

$term = entity_create('taxonomy_term', array(
  'tid' => $tid,
  'vid' => $this->getValue($values, 'vid'),
));
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $term->getSystemPath();

It is trivial to create such a view, just go to the new View wizard and create a taxonomy view page with all the default options to expose the bug.

Proposed resolution

Get the full entity from the result row for rendering the link.

Remaining tasks

Review. Commit.

User interface changes

No fatal error when creating taxonomy field views.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rbayliss’s picture

Status: Active » Needs review
FileSize
1.01 KB

Patch.

blazey’s picture

Fixes the issue.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Nice find! This could use some test coverage.

rbayliss’s picture

Status: Needs work » Needs review
FileSize
6.42 KB

I realized that the term is already loaded at this point, so we can just use the getEntity() method. Also added a test.

rbayliss’s picture

Issue tags: -Needs tests
Gábor Hojtsy’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community
Issue tags: +VDC

Fatal error so should at least be major. The fix and test looks good to me.

Gábor Hojtsy’s picture

Title: Taxonomy field handler creates fatal error in linking to terms » Taxonomy field handler fatal error in linking to terms, cannot create taxonomy views with defaults
Priority: Major » Critical

Closed down #2320275: Taxonomy views do not work (fatal error) as duplicate. The default taxonomy views setting is fields based, so people cannot create a taxonomy view with the defaults thanks to this bug. Elevating to critical because that one was. (It is a fatal error you get by using a feature with default options means it is very common).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2252739-views_taxonomy_field_link-4.patch, failed testing.

dawehner’s picture

I really hope that with #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views we do have enough test coverage.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
3.45 KB
6.96 KB

The taxonomy term base fields are now in taxonomy_term_field_data (see #1498660: Refactor taxonomy entity properties to multilingual), the test view should reflect that.

Gábor Hojtsy’s picture

@dawehner: Looking at the patch and the view being patched by #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views, it does not use the link_to_taxonomy option and therefore does not expose this bug. This bug is basically appearing with taxonomy views using the taxonomy name and the link_to_taxonomy option. That is also used in default taxonomy views created by picking no custom options in the Views wizard, just providing a name and asking for a taxonomy page, which is why it was elevated so high as a bug.

Gábor Hojtsy’s picture

Issue summary: View changes

Updates issue summary.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

jhodgdon’s picture

I tested this also. Agree it works.

Did someone verify that the test fails without the patch though?

Gábor Hojtsy’s picture

Test only patch from 11 without the fix that will fail and 11 again so it keeps passing :)

Gábor Hojtsy’s picture

The test only patch feedback from testbot shows the bug proper :)

Drupal\Core\Entity\EntityMalformedException: The "taxonomy_term" entity type has not been saved, and cannot have a URI. in Drupal\Core\Entity\Entity->urlInfo() (line 152 of /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Entity/Entity.php).

jhodgdon’s picture

Great! +1 for RTBC then.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed fb27c45 and pushed to 8.0.x. Thanks!

  • alexpott committed fb27c45 on 8.0.x
    Issue #2252739 by Gábor Hojtsy, rbayliss: Fixed Taxonomy field handler...
Gábor Hojtsy’s picture

Yay, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.