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.

Files: 
CommentFileSizeAuthor
#3 1122804-forum-metatag-fix.patch4.37 KBbago
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in 1122804-forum-metatag-fix_1.patch.
[ View ]
#3 forum.zip55.6 KBbago

Comments

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.

StatusFileSize
new55.6 KB
new4.37 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in 1122804-forum-metatag-fix_1.patch.
[ View ]

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)

<?php
 
// 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).

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.

@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".

@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.

@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]

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.

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

<?php
/**
* 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();
    }
  }
}
?>

Thanks VVVi, worked like a charm.