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
Comment | File | Size | Author |
---|---|---|---|
#25 | taxonomy-term-reference-exception-1697284-25.patch | 937 bytes | pefferen |
#20 | taxonomy-term-reference-exception-1697284-20.patch | 969 bytes | deepak_123 |
#16 | taxonomy-term-reference-exception-1697284-16.patch | 937 bytes | egfrith |
#13 | 1697284-term-reference-exception.patch | 937 bytes | Island Usurper |
#10 | 1697284-9.patch | 652 bytes | egfrith |
Comments
Comment #1
Jing Qian CreditAttribution: Jing Qian commentedHere 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;
Comment #2
marvin_B8 CreditAttribution: marvin_B8 commentedi think this is a little bit safer
Comment #3
apanag CreditAttribution: apanag commentedWorked for me.
Thank you very much for your patch.
Comment #4
floydm CreditAttribution: floydm commentedYay to this. Much more robust, and fixed a sticky problem I was having. Thank you much, qian.jing.2005 and marvin_B8!
Comment #5
chellman CreditAttribution: chellman commentedI 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.
Comment #6
chellman CreditAttribution: chellman commentedLong-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.
Comment #7
marcoka CreditAttribution: marcoka commentedi 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
Comment #8
egfrith CreditAttribution: egfrith commentedThe 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.
Comment #10
egfrith CreditAttribution: egfrith commentedNew 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.
Comment #11
dcam CreditAttribution: dcam commentedActivating Testbot.
Comment #13
Island Usurper CreditAttribution: Island Usurper commentedI 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.
Comment #14
yngens2 CreditAttribution: yngens2 commentedWith 7.32 it gives:
Comment #15
cbrody CreditAttribution: cbrody commented#13 worked for me with 7.32. Wondering why this hasn't been committed though?
Comment #16
egfrith CreditAttribution: egfrith commentedUploading new patch with no offset. If this passes, we should probably mark this issue as RTBC.
Comment #17
egfrith CreditAttribution: egfrith commented@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.
Comment #18
David_Rothstein CreditAttribution: David_Rothstein commentedSee #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?)
Comment #19
joelpittetComment #20
deepak_123 CreditAttribution: deepak_123 commented#16 is not working for me as the line numbers are different in 7.41 version. Posting the newer patch.
Comment #21
joelpittet@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 yourgit diff --relative . > 1697284.patch
Comment #22
drupalshrek CreditAttribution: drupalshrek commentedI 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
Comment #23
Colin @ PCMarket CreditAttribution: Colin @ PCMarket commentedI 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
Comment #24
drupalshrek CreditAttribution: drupalshrek commentedChanging status to "Active" since https://www.drupal.org/node/1697284#comment-10709190 has a way to reproduce.
Comment #25
pefferen CreditAttribution: pefferen at Triquanta commentedThe fix in #16 and #20 is working for me. I recreated a the patch file from #20.
Comment #26
pefferen CreditAttribution: pefferen at Triquanta commentedComment #28
vegansupreme CreditAttribution: vegansupreme commented#25 works for me!
Comment #29
geek-merlinAs @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.