Hi,

I've been trying to get this module working with my advanced forum and I am having no luck.

The description is always the 'Global' description. Is there a way to set the description meta tag from the taxonomy description?

Cheers,

Paul.

CommentFileSizeAuthor
#3 1122804-forum-metatag-fix.patch4.37 KBbago
#3 forum.zip55.6 KBbago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Title: Meta tags not working with advanced forum? » Support forum pages until forums supports hook_entity_view()
Version: 7.x-1.0-alpha6 » 7.x-1.x-dev

Right now there's a core bug (#1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views) that means forum pages don't run the hooks necessary to load the necessary meta tags. Similar to taxonomy term pages (#1700160: Support taxonomy term pages until taxonomy supports hook_entity_view()), we need a work-around for this.

DamienMcKenna’s picture

bago’s picture

As I wrote in #1122804: Drupal core issue blockers I also tried to simply work around the forum issues in metatag module with no success, so I ended branching the forum. I don't know if there is a best practice for this, but maybe the best thing would be to create a forum project on drupal.org and put there the fixed forum module so that people that needs it fixed on D7 can simply download the module and it will take precedence on the core module)...

Here is what I did:
1- backported #1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views to D7 (returning a render array, too, and not the latest D7 patch available there).
(1bis- cloned the forum module in sites/all/modules so to be able to patch it without patching core.)
2- added this code forum_page() (similar to what taxonomy_term_page does)

  // Invoking taxonomy_term_view let metatag to intercept we are on a taxonomy page and inject metatags.
  if ($forum_term->tid) {
    taxonomy_term_view($forum_term, 'full');
  }

This way my forum pages are succesfully using titles and metas defined in metatag for the forum taxonomy.

The patch I attach is for the forum module and is based on 148145-forum-page-cleanup-d7.patch (comment #55 from #1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views).

I also attach a zip of my patched forum module: just install it as a simple module or simply put it somewhere (sites/all/modules) and then visit your admin/modules page and save (D7 will automatically switch from core forum to this patched one).

DamienMcKenna’s picture

Status: Active » Needs review

@bago: The best approach for the changes necessary for Forum would be to work up a patch for #1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views and post it there.

Status: Needs review » Needs work

The last submitted patch, 1122804-forum-metatag-fix.patch, failed testing.

bago’s picture

@Damien: yes, I understand. Unfortunately they already wrote that this kind of fixes won't be backported to D7, so what is needed is to work on D8 forum to have it refactored to call the right hooks. Unfortunately I never used D8 and I don't know this stuff enough to propose a patch for D8 supporting all the right hooks. I just wanted to share my "solution" for D7. Maybe that core modules should be simply removed from core if no one is able to update them to make them use the Drupal api the "right way".

DamienMcKenna’s picture

@bago: Nobody said in that issue that the fix would not be backported and the "needs backport to D7" tag has not been removed, so fret not. Please post your patch to that issue (after changing the issue to 7.x-dev instead of 8.x-dev), we'll see what can be done from there.

bago’s picture

@Damien: my patch is based on #148145: "Forums" title is not localized and I see "sun" removing the D7/D6 backport and commenting this: http://drupal.org/node/148145#comment-6984432 (I don't know how much "sun" is authoritative in this choice)
That's why I don't think that proposing a similar patch to #1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views would pass. BTW I will try to find some time and post some comment there, so we'll see ;-) [DONE]

DamienMcKenna’s picture

Status: Needs work » Active

@bago: Sun removed the backport tags from that issue as there was another way of achieving the same results; this issue is a continuation of #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view() which was accepted. Thanks for posting the patch.

VVVi’s picture

Just add the next code in your module and metatags will be shown for your advanced forum:

/**
* Implementation of hook_page_alter()
*/
function YOUR_MODULE_page_alter(&$page) {
  // Fix the bug in the metatag module - show metatags for forums
  if (arg(0) == 'forum' && is_numeric(arg(1))) {
    $term = taxonomy_term_load(intval(arg(1)));
    if ($term !== FALSE) {
      metatag_entity_view($term, 'taxonomy_term', 'full', NULL);
      $page['content']['metatags'] = metatag_page_get_metatags();
    }
  }

}
2pha’s picture

Thanks VVVi, worked like a charm.

DamienMcKenna’s picture

Component: Miscellaneous » Code
Category: Support request » Feature request
Priority: Major » Normal
Issue summary: View changes
Issue tags: -D7 stable release blocker

Will follow-up with this after 1.0.

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 1122804-forum-metatag-fix.patch, failed testing.

DamienMcKenna’s picture

@iosx: The patch above is for Drupal core, not the Metatag module, so the patches will always fail. bago uploaded his patch to #1122808: hook_entity_view and hook_taxonomy_term_view() are not implemented on forum term views, so I suggest starting there, or coming up with a separate work-around for Metatag.

chike’s picture

I am using Drupal 10 and this issue still persists. Metatag settings for taxonomy terms are still ignored by forum pages.

Also I want to ask on the side, when the taxonomy term page /taxonomy/term/1 exists side by side the forum url /forum/1 of which both urls are pointing to the same resource, how does this impact SEO? And what should go in the Canonical URL in Metatag?