Closed (fixed)
Project:
Metatag
Version:
7.x-1.0-alpha3
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Nov 2011 at 18:06 UTC
Updated:
5 Sep 2012 at 08:41 UTC
Hello, dear friends!
Great Thanks for so marvellous module!
But I have an error while using it:
After adding any token from 'taxonomy field' group I get the error
Notice: Undefined index: taxonomy_term in function taxonomy_field_formatter_view() (line 1449 in /modules/taxonomy/taxonomy.module).
Notice: Trying to get property of non-object in function taxonomy_field_formatter_view() (line 1449 in /modules/taxonomy/taxonomy.module).Also there're commas instead of keywords in the code of the page.
For example, if I have taxonomy_field 'field_tags' where any article has 2 tags: 'first' and 'swcond', and if I put in Meta Tags setting the token '[node:field_tags]', I'll get 2 such errors and in the tag "<meta name...> like this: " , ,"
Is it any bug or my mistake or generally the Token module error?
Thank You!
Comments
Comment #1
flomar commentedI Have the same Problem, did you find a solution?
Comment #2
fietserwinI have the same problem and have been debugging the code to try to find the cause of the error. so far, I did not manage to find the real cause, but have a workaround. Can you test it, to see if we are talking about the same problem.
Change this: file metatag.module, function metatag_field_attach_view_alter():
To:
For some reason, a cached entity is not completely loaded and prepared for view, but does have the flag '_field_view_prepared' that prevents additional information (in this case: the taxonomy object for the given tid) to be loaded.
Note: this does not seem to be a bug in metatag, but deeper down. This is just a workaround.
Comment #3
fietserwinoops, posted twice, removing text.
Comment #4
fietserwinOK, I did some further debugging. The problem occurs when metatags uses fields that will not be displayed. These fields will not be "prepared for viewing".
Details of the error
- A node is prepared for viewing.
- The fields of the node are attached.
- The fields (that are not set to hidden) are prepared for viewing
=> For taxonomy reference fields that are not displayed the term will not be loaded.
- Metatags module wants to add its metatags to the node.
- It finds a metatag with a token referring to a taxonomy field that will not be displayed and thus has not been prepared.
- It asks the token system to generate it.
- Token system forwards this request to the token module (calling field_tokens()).
- Token module renders the field (calling field view_field()).
- Field module looks at the entity and sees that it has the flag _field_view_prepared,
and decides that it does not have to prepare the field for viewing again.
- Rendering will fail due to missing information leading to the above notice and an empty result.
- Token replacement will be empty.
- Metatags will output the empty string somewhere in the title or in another metatag.
In which module is the error?
I think that the flag '_field_view_prepared' is on the wrong level. This flag seems to have been added to prevent multiple executions of field view preparing code. If this flag should have been added to each field that is really prepared, the field module could see that a field has not been prepared while it now is being asked to render it...
This would make it an error in core and as such it will easily take 6 months to 1 year before it is going to be committed...
Alternatively, metatags or token can be blamed for not knowing the internals of field module (...) where they should as they can assume to do something that is not main stream They may assume that they are rendering information that will not be made visible to the client on the page itself (after all, it is meta-information) and thus take precautions to prevent this error from happening.
There are issues in core regarding the _field_view_prepared flag, but none that would solve this.
Comment #5
damienmckennaDoes this still happen with the current alpha8 release and the latest Token module?
Comment #6
fietserwinI tested it on an installation with:
- D7.14
- Metatag 7.x-1.0-alpha8
- Token 7.x-1.2
And could not reproduce it anymore.
As the "offending" function (the one for which I proposed a workaround for) does no longer exist, you apparently rewrote the implementation that retrieves the tokens.