Metatag uses hook_entity_view() to load its data on individual pages (#1363476: Panels integration - ensure meta tags work OOTB on entity pages). Due to a core bug (#1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term) the taxonomy term pages in both Drupal 7 & 8 do not trigger this hook, so we need a temporary solution until that issue is resolved & backported to D7.

Files: 
CommentFileSizeAuthor
#38 metatag.module.zip8.43 KBwaveer
#31 metatag-n1700160-29.patch780 bytesDamienMcKenna
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/metatag/metatag.module.
[ View ]
#23 support-taxonomy-term-pages-1700160.patch613 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]
#18 support-taxonomy-term-pages-1700160.patch773 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]
#9 support-taxonomy-term-pages-1700160.patch872 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

Comments

DamienMcKenna’s picture

Priority:Normal» Critical
Issue tags:+D7 stable release blocker

Bump.

himagarwal’s picture

Has anyone found any solution to this problem?

Subscribing.

DamienMcKenna’s picture

I think waiting for #1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term is the best plan - it's RTBC, we just need one of the core committers to commit it.

couturier’s picture

I'm new here, so I don't know if there might be something that can be done for the issue referenced in #3 to get the attention of a core committer. It looks like more progress has been made in the last few days on a patch, and they are saying that if it doesn't get committed soon, it will have to be re-rolled. Is there some way to speak up on IRC about it or submit a special request elsewhere to get it committed?

DamienMcKenna’s picture

@couturier: THe D8 maintainers are exceedingly busy and are prioritizing their time as they're best able; promises of baked goods and/or chocolate have not been able to influence them, so I suggest just being patient. Until then the patch in comment #73 should still work with the current D7 release, but let me know if it needs to be rerolled.

couturier’s picture

Yes, I saw your offer of food earlier up in the comments on that issue. Smart thinking. Too bad doughnuts can't be emailed or it might actually work. I hadn't thought to apply the patch to D7 myself, so thanks for that (I'm very new to website development). Too bad the patch can't be committed now and save you having to re-do your work. Can they take on a few more core maintainers to help out with the time crunch? Sounds like you know what you are doing and would be a good addition to the team, though I realize the time commitment to being a core maintainer is not possible for everyone.

remkovdz’s picture

I can't follow all this technical talk 100%, so I hope someone can clarify for me?

All the Taxonomy changes I make in the Meta Tag module do not have any effect at all: nothing shows up in the code frontend. This is a known issue and I should not investigate further? Thanks a lot.

DamienMcKenna’s picture

@remkovdz: Correct. Hopefully we'll get the fix rolled out soon for Drupal core so these pages work again.

marcelovani’s picture

StatusFileSize
new872 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

We need this functionality, so I am adding a patch that will do the job until the hook is implemented

marcelovani’s picture

Status:Active» Needs review
couturier’s picture

Status:Needs review» Needs work

The patch applies without breaking anything, but when I tried to make a change to the way <title> is displayed for taxonomy term pages, my changes are not implemented.

DamienMcKenna’s picture

@couturier: What are you using for the display - core functionality, Panels, Views, etc?

couturier’s picture

For the taxonomy term page, it was core functionality Drupal 7. I do not have Panels installed. If you want me to create a View to test that, I can. Update: actually, I am concurrently working on a related issue where I have installed a patch from marcelovani that adds page numbers to <title> on Views pages and taxonomy term pages when [current-page:page-number] is added to the Global title settings, so we would not need this patch for Views pagination, because the other one works. That is a major concern for SEO and why I'm following this issue here as related to it.

DamienMcKenna’s picture

@couturier: That's ok, I'll be testing the patch this evening.

DamienMcKenna’s picture

@marcelovani: The patch won't work as metatag_entity_has_metatags() is only called from metatag_entity_view() which won't be called on taxonomy term pages due to the lack of hook_entity_view() on those pages.

marcelovani’s picture

@DamienMcKenna you are right. It is working for us because we use views to list all nodes that refer to a specific term i.e. /taxonomy/term/6, which triggers the hook_entity_view when loading nodes.

I will try find a better way of fixing this.

Molfar’s picture

This patch didnt work for me.

marcelovani’s picture

StatusFileSize
new773 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

This logic is much cleaner than the previous one.

marcelovani’s picture

Status:Needs work» Needs review
couturier’s picture

Status:Needs review» Needs work

I'm not sure if I did something wrong, but I'm getting these warning messages on a taxonomy term page when I applied the patch. The custom title I set up in Meta Tags for taxonomy terms is not showing, either. It is showing only the Global settings.

Warning: Missing argument 3 for metatag_entity_view(), called in /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module on line 455 and defined in metatag_entity_view() (line 462 of /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module).
Warning: Missing argument 4 for metatag_entity_view(), called in /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module on line 455 and defined in metatag_entity_view() (line 462 of /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module).
Notice: Undefined variable: langcode in metatag_entity_view() (line 474 of /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module).
Notice: Undefined variable: view_mode in metatag_entity_view() (line 489 of /var/www/couturier/fashionbelle.biz/sites/all/modules/metatag/metatag.module).
DamienMcKenna’s picture

@marcelovani: The correct arguments for hook_entity_view() are:

<?php
  hook_entity_view
($entity, $type, $view_mode, $langcode)
?>

Therefore your code needs to be updated to pass in values for the above.

marcelovani’s picture

I have added default values for the function:
-function metatag_entity_view($entity, $entity_type, $view_mode, $langcode) {
+function metatag_entity_view($entity, $entity_type, $view_mode = 'full', $langcode = NULL) {

So that if we don't supply the other two arguments, it will use the default values

@DamienMcKenna, I would like to have a chat on skype, are you available: my skype is marcelovani

marcelovani’s picture

StatusFileSize
new613 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

To make things simpler, I am adding the two parameters when I call hook_entity_view.

marcelovani’s picture

Status:Needs work» Needs review
marcelovani’s picture

I am testing the patch on few sites.

Applying this patch alone won't fix the problem of overriding metatags for nodes/terms.

Image this case scenario:
- I set title metatag for terms to be [term:name] | [site:name] (/admin/config/search/metatags)
- I visit a term page /term/1 and the title shows term1 | test.com
- I edit the term and change the title metatag to Custom title for term1 (/taxonomy/term/1/edit)
- I visit a term page /term/1 and the title shows Custom title for term1

The scenario above will only happen if you also apply this patch http://drupal.org/node/1784896#comment-6534684
Otherwise, it will still show term1 | test.com, because the value gets overriden with the current code.

Please apply both patches (http://drupal.org/files/support-taxonomy-term-pages-1700160_1.patch, http://drupal.org/files/overriding-metatags-fall-back-parent-default-val...) and let me know how it goes, I am testing this on 6 different sites which have different modules and configuration, so far it seems to work fine.

couturier’s picture

Status:Needs review» Reviewed & tested by the community

Yes! With these two patches, the titles for taxonomy term pages can be successfully changed, independently from the Global settings.

Molfar’s picture

DamienMcKenna’s picture

This appears to work quite well. I'm going to test it further, and I'd like some feedback from Dave, but I like what I see.

DamienMcKenna’s picture

Status:Reviewed & tested by the community» Needs review

Please test out this alternative to #23 that skips the custom logic if #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view() has been applied (please! please! please!).

couturier’s picture

@DamienMcKenna I'm not sure what you are asking. Do you want Dave to review the #23 patch? I do not see any alternative to the patch in #23. Or, maybe you mean the patch in #23 plus your new patch here? I can try that.

DamienMcKenna’s picture

StatusFileSize
new780 bytes
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/metatag/metatag.module.
[ View ]

Doh, forgot to attach the file.

couturier’s picture

Status:Needs review» Reviewed & tested by the community

Yes, this patch in #31 works for me to set unique taxonomy term page titles (separate from Global settings) when used together with your new patch under "Overriding meta tags fall back to parent default tag value".

remkovdz’s picture

For me only #9 is working, and all the others are not. Thanks still!

DamienMcKenna’s picture

Status:Reviewed & tested by the community» Fixed

I've committed the patch from #31, thank you again marcelovani for your help. If there are any issues with meta tags still not working please review one of the issues related to the display system being used (Display Suite, Views, Panels, etc) or open a new issue.

DamienMcKenna’s picture

FYI, a change notice for one of the two hooks added: http://drupal.org/node/1808870

waveer’s picture

Status:Needs work» Needs review
Issue tags:-D7 stable release blocker

Status:Fixed» Needs work

The last submitted patch, metatag-n1700160-29.patch, failed testing.

waveer’s picture

Status:Needs review» Fixed
Issue tags:+D7 stable release blocker, +metatag, +taxonomy term page title set by metatag
StatusFileSize
new8.43 KB

i test the code according to the #32

the patch is a little troublesome to use
so i upload my modified metatag.module file

it has two modify
1. add add line 445-455
2. modify function metatag_page_build() line 861

我测试了32楼的代码,可以正常使用

patch看着有点麻烦
不想麻烦的,可以直接看我上传的metatag.module
改了两个地方
1 是 添加 行445-455
2 修改默认的 function metatag_page_build() 行861

DamienMcKenna’s picture

@waveer: Or you could just download the latest -dev codebase ;-)

waveer’s picture

thank you.
dev is better in drupal :-)

DamienMcKenna’s picture

Status:Fixed» Closed (fixed)

Last night saw the release of 7.x-1.0-beta1, so I'm closing all these "fixed" issues in the interest of tidying up the issue queue. Thank you all for your help getting us to this point!

DamienMcKenna’s picture

csdco’s picture

I'm using D7.17 and the latest dev release of Metatag but am seeing no meta tags printed on my taxonomy term pages. The tags are in $vars['page']->content['metatags'] but they're simply not being printed. All of my nodes are getting them printed properly. Should I be expecting this to work with 7.17 and 7.x-1.x-dev?

DamienMcKenna’s picture

@csdco: Sounds like a theming problem, please check e.g. #1310780: Metatags not working on overwritten templates.

csdco’s picture

That issue is interesting – following the advice there, I've thrown

<?php
render
($vars['page']['content']['metatags']);
?>

into template_preprocess_html() and the metatags are now printing. Still not getting the revised title, however. This makes me think that my issue is related to both this issue and 1310780. Metatags are not being rendered for taxonomy terms, including the title tag.

couturier’s picture

Does this patch need to be removed from Meta Tag now with the release of Drupal 7.17 on November 7, 2012?

DamienMcKenna’s picture

@couturier: The code in beta2 will identify whether the custom logic is necessary, so you're good to go.

remkovdz’s picture

Beta2 works great for me, thanks a lot.

couturier’s picture

Smart, Damien. Thanks for the forethought in beta2.

couturier’s picture

Issue summary:View changes

Added link to #1363476.