Within taxonomy_field_formatter_view function, at case 'taxonomy_term_reference_link' case option there is a directly load for term obj via $term = $item['taxonomy_term'] line
However, should we check if the term obj index 'taxonomy_term' already exist in the option field and load the term obj if it is not before calling the entity_uri function?
This is due to following 2 reasons and will lead page broken due to throw exception without cache:
1) Within the entity controller we could got a chance to load node from cache and some times the term option may only got the 'tid' but without the 'taxonomy_term' obj
2) Once the entity_uri function been called via taxonomy_field_formatter_view function, it will failed at:
taxonomy_field_formatter_view -> entity_uri -> entity_extract_ids ===>throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type. ........ because of missing term obj

So Can we put in a taxonomy_term obj check and dynamic load before calling the entity_uri within taxonomy_field_formatter_view function to make it possible handling more issues instead of a small obj missing lead page break?
thx a lot

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jing Qian’s picture

Here is some suggestion of the code change and hope other developers could have a test and see if there are any issues with it

diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index ccbd7c5..0caa7f3 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1440,14 +1440,24 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
);
}
else {
- $term = $item['taxonomy_term'];
- $uri = entity_uri('taxonomy_term', $term);
- $element[$delta] = array(
- '#type' => 'link',
- '#title' => $term->name,
- '#href' => $uri['path'],
- '#options' => $uri['options'],
- );
+ $item = FALSE;
+ if (is_array($item) && isset($item['taxonomy_term'])) {
+ $term = $item['taxonomy_term'];
+ }
+ else {
+ if (isset($item['tid'])) {
+ $term = taxonomy_term_load($item['tid']);
+ }
+ }
+ if ($item) {
+ $uri = entity_uri('taxonomy_term', $term);
+ $element[$delta] = array(
+ '#type' => 'link',
+ '#title' => $term->name,
+ '#href' => $uri['path'],
+ '#options' => $uri['options'],
+ );
+ }
}
}
break;

marvin_B8’s picture

Status: Active » Needs review
FileSize
1.22 KB

i think this is a little bit safer

apanag’s picture

Worked for me.
Thank you very much for your patch.

floydm’s picture

Yay to this. Much more robust, and fixed a sticky problem I was having. Thank you much, qian.jing.2005 and marvin_B8!

chellman’s picture

I was having a problem where forum nodes were failing to preview (regular save worked) when the Forums taxonomy was hidden in admin/structure/types/manage/forum/display.

First, there was an undefined index taxonomy_term error, then an EntityMalformedException: Missing bundle property on entity of type taxonomy_term.

I was thinking that just isset($item['taxonomy_term'] would be enough to fix it, but this looks more robust, and does work to solve this. I want to review this to see if it fails on a simpler Drupal install too.

chellman’s picture

Issue summary: View changes

Long-delayed followup. I tried to replicate this on a simple site, and wasn't able to.

In my case, I was able to track it down to an interaction with Advanced Forum module.

marcoka’s picture

i have that error. too. here is a sample screenshot of the data in the arrays that obviously show why it crashes:
http://i.imgur.com/XvHQWmZ.png

egfrith’s picture

FileSize
1.22 KB

The patch at #2 didn't apply, but the code is still compatible with the current code base, so I've recreated the patch. It solves my problem, which is a crash when trying to preview an article which has a taxonomy term field whose display is set to hidden. This problem is also described at #1270340-7: EntityMalformedException when creating a taxonomy term programmatically after upgrading Drupal core from 7.7 to 7.8, with the work-around (of displaying the taxonomy term field) at #1270340-42: EntityMalformedException when creating a taxonomy term programmatically after upgrading Drupal core from 7.7 to 7.8. The error produced was "EntityMalformedException: Missing bundle property on entity of type taxonomy_term error" at line 7729 of includes/common.inc.

Status: Needs review » Needs work

The last submitted patch, 8: 1697284-8.patch, failed testing.

egfrith’s picture

FileSize
652 bytes

New version of patch uploaded in hope it will pass tests! I think the problem with the previous patch might have been that the $term wasn't set sometimes.

dcam’s picture

Status: Needs work » Needs review

Activating Testbot.

Status: Needs review » Needs work

The last submitted patch, 10: 1697284-9.patch, failed testing.

Island Usurper’s picture

Version: 7.12 » 7.31
Status: Needs work » Needs review
FileSize
937 bytes

I think maybe the formatter should return an empty array if it can't find the right term anywhere in $item. I've added a call to watchdog() in that case so it can be tracked down too.

yngens2’s picture

With 7.32 it gives:

patching file taxonomy.module
Hunk #1 succeeded at 1598 (offset -3 lines).
cbrody’s picture

#13 worked for me with 7.32. Wondering why this hasn't been committed though?

egfrith’s picture

Version: 7.31 » 7.32
FileSize
937 bytes

Uploading new patch with no offset. If this passes, we should probably mark this issue as RTBC.

egfrith’s picture

Status: Needs review » Reviewed & tested by the community

@cbrody Re your comment, and my last one, we probably need a patch review before marking the issue RTBC. The actual committers will look at it.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
Related issues: +#2128265: Term field not displayed + Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1596 of taxonomy.module)

See #2128265-43: Term field not displayed + Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1596 of taxonomy.module) (these are essentially the same issue, but I think both might really be a duplicate of more fundamental issues anyway?)

joelpittet’s picture

Version: 7.32 » 7.x-dev
deepak_123’s picture

#16 is not working for me as the line numbers are different in 7.41 version. Posting the newer patch.

joelpittet’s picture

@deepak_123 the patch you made needs to relative to the drupal root. #20 is one folder back. If you are doing the patch in an existing git repo, add the flag --relative to your git diff --relative . > 1697284.patch

drupalshrek’s picture

I have this

EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7836 of /var/www/includes/common.inc).

on
Drupal 7.37

This happens when I added an extra field to some taxonomy vocabularies and not on others, and then I try and sort in a view on this field which is not on each vocabulary. I have a number of vocabularies (Themed - with terms like Food, Animals; Parts of Speech - with terms Adjectives, Adverbs), and I added a field to one of these vocabularies "date_done_thing". Then I tried to sort in a view by this field, and bang!

This is therefore relatively easy to reproduce:
* create a two (or more) taxonomy vocabularies, with some taxonomy terms
* on one of the taxonomy vocabularies, add an extra field, e.g. a date field
* create a view with the fields: taxonomy term name, new_date_field
* try sorting on this field

Colin @ PCMarket’s picture

I was experiencing errors with SOLR search on my drupal 7.41 site

EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7886

and this patch in #16 fixed it for me and should be committed

drupalshrek’s picture

Status: Postponed (maintainer needs more info) » Active

Changing status to "Active" since https://www.drupal.org/node/1697284#comment-10709190 has a way to reproduce.

pefferen’s picture

The fix in #16 and #20 is working for me. I recreated a the patch file from #20.

pefferen’s picture

Status: Active » Needs review

The last submitted patch, 20: taxonomy-term-reference-exception-1697284-20.patch, failed testing.

vegansupreme’s picture

#25 works for me!

geek-merlin’s picture

Status: Needs review » Closed (duplicate)

As @David_Rothstein mentioned in #18 this is a dup of #2128265: Term field not displayed + Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1596 of taxonomy.module).
I'm closing this as the other patch has the same essential approach, but covers more code paths.