Due to a recent update of Drupal core, I'm getting the following error:

Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1601 of taxonomy.module)

Now, this is caused because the core taxonomy hook taxonomy_field_formatter_view() has an argument called $items that expects an array of values that have two elements: tid, a numeric value, and taxonomy_term which is the taxonomy term object.

In the case of my code, each array in $items is missing the taxonomy_term element.

Now a simple fix would be to hack core and simply set $item['taxonomy_term'] = taxonomy_term_load($item['tid']) if it doesn't already exist. But of course, hacking core is a no-no so I'm trying to find a way to catch the $items argument for taxonomy_field_formatter_view() before it is passed to this hook.

What's the approach here? Would defining hook_field_formatter_view() in a custom module and fixing the $items argument work? Presumably not because the core hook is going to fall over first, so I'll need to modify it before it's passed into these hooks?

2 Answers 2


Implement hook_module_implements_alter and replace taxonomy_field_formatter_view() to your function.


I'd advise to use one of the Field formatter API hooks before modifying a Drupal core hook, even with hook_module_implements_alter, you might get unpleasant surprises if someone else is using it.

What I'd do is to prepare your items using hook_field_formatter_prepare_view and as it's passed by reference, it should arrive fine to your formatter_view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.