For example, if I edit a 'description' meta tag for a node that is promoted to the front page, and then view the source code of my frontpage, I see the description of the individual node, which is wrong. The code should be using the formatter to output the meta tag and not use hook_entity_load() which can be called at any time on an entity whether it is being viewed or not.

Comments

valthebald’s picture

Status: Postponed » Active

You're right, yet without global configuration page (#1100570: Add configuration page with global keywords) it's the only way to change meta tags on the default front page. These changes would be done in one iteration

valthebald’s picture

Assigned: Unassigned » valthebald
Status: Active » Postponed

Can't be done without hook_entity_view called by taxonomy_term_page() (see issue #1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term)

das-peter’s picture

Even if this report is postponed - I'll continue here.
Since I use panels and views to create mashup sites from several entities it's not possible to define which meta tags have to be used.

Thus I've added a instance configuration setting to the field which allows to exclude a field content from being set on entity_load.
Besides that I changed the implementation of hook_field_formatter_view() to add the meta tags but not to display the content as link. (Any need for these links? Related #1124328: Field labels printed at bottom of page when Link module enabled)
With this approach it's also possible to define the output for each available display mode.
And in panels you can just add the fields as you like to the content to set the meta tags.

Another thing I added is a rules integration which allows you to set meta tags based on rules. With this integration it's possible to set meta tags even on entity unrelated pages.

valthebald’s picture

Hi das-peter,
your patch answers #1124328: Field labels printed at bottom of page when Link module enabled, which is of course not postponed and has to be addressed.
Actually, I was going to fix it without adding new setting to instance, just output nothing on formatter_view.
Do you think there are use cases which need actual output of meta tags to HTML?

valthebald’s picture

Actually, #1124328: Field labels printed at bottom of page when Link module enabled was not solved by the patch.
I need some more time to understand what happens.

valthebald’s picture

I've committed metatags_quick.rules.inc found in your patch without any change, yet replaced formatter handling to work with the link module.
Please do not comment on this patch here, because it is not related to hook_entity_load issue

andypost’s picture

Status: Active » Needs work

Probably better to check that entity is viewed as page by analizing


$menu_item = menu_get_item();
if ($menu_item['path'] == $entity->uri['path']) {
  // Set page meta.
}
// Unset fields in formatter.

Not sure about views pages but I think this could be solved in separate issue

valthebald’s picture

That won't work if site does not use path module or multiple URL aliases exist for the same path

Linus’s picture

Any news on this? At the moment the module is quite useless for sites with views and panels.

The results on my site are really weird.
On some nodes I see the meta-tags from the related taxonomy term, on other nodes I see meta-tags from content loaded via views.
On one page i even see meta-tags from a node that is just referenced in a reference field from another node, which is loaded in a view...

valthebald’s picture

Status: Needs work » Needs review
StatusFileSize
new2.01 KB

Due to the still missing call to hook_entity_view on entity page view handlers, I can't move this to hook_entity_view.
Attached patch implements different approach:
instead of direct adding meta tags to HTML head, they are collected to internal storage, and outputted during page build (hook_page_build). Meta is output only if belongs to active object (or there is no active object at all)

#9 - there is suggested (but not yet implemented) solution for the path-based meta tags at #1146018: Meta tags based on path, please check

Bronislovas’s picture

Patch is really working! Thanks

valthebald’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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