CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Problem with Drupal "prefix" based language detection, and "metatag" module
Pages: [1]

Author Topic: Problem with Drupal "prefix" based language detection, and "metatag" module  (Read 1086 times)

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Problem with Drupal "prefix" based language detection, and "metatag" module
January 08, 2015, 06:39:48 am
I found that if the "metatag" module is enabled in Drupal (useful for Facebook "og" metatag when users share pages), on a multilingual site that uses prefix-based language detection (ex: /en/civicrm/contribute[...]), Drupal gets confused with the title of pages (the title shown in the titlebar of the browser, i.e. the <title> element).

The problem is in civicrm/drupal/civicrm.module:

Code: [Select]
/**
 * Implementation of hook civicrm_metatag_page_cache_cid_parts_alter
 * Append the query string to the key under which the page title is cached to prevent cross-contamination
 * from urls such as civicrm/contribute/transact
 *
 * If metadata module is not installed this function will not fire
 * @param array $cid_parts
 */
function civicrm_metatag_page_cache_cid_parts_alter(&$cid_parts) {
  if (substr($cid_parts['path'], 0, 7) == 'civicrm') {
    $cid_parts['path'] .=  '/' . md5(implode('_',$_GET));
  }
}

This assumes that the path does not have a language prefix (en/fr/...).

I worked around it for now by using:

Code: [Select]
function civicrm_metatag_page_cache_cid_parts_alter(&$cid_parts) {
  if (substr($cid_parts['path'], 3, 7) == 'civicrm' || substr($cid_parts['path'], 0, 7) == 'civicrm') {
    $cid_parts['path'] .=  '/' . md5(implode('_',$_GET));
  }
}

However, this assumes that the language prefix is maximum 2 characters. A better solution is probably just to use "strpos()" to check whether "civicrm" is in the path.

Any thoughts?
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Problem with Drupal "prefix" based language detection, and "metatag" module
January 08, 2015, 06:44:02 am
That sounds reasonable.
Try asking your question on the new CiviCRM help site.

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Problem with Drupal "prefix" based language detection, and "metatag" module
March 02, 2015, 10:23:25 am
I'm not sure if that message was SEO spam, but it reminded me to send a pull-request for this issue in 4.6:

https://issues.civicrm.org/jira/browse/CRM-16039
https://github.com/civicrm/civicrm-drupal/pull/248
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Problem with Drupal "prefix" based language detection, and "metatag" module

This forum was archived on 2017-11-26.