Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I has content translated with i18n module. With this translation, every translated node have diferent 'nid' value, but I need to unify the likes count of the facebook button.
I created a function in order to acomplish this. Basically, I get the source node from the tyranslation set and alter the src parameter that fblikebutton.tpl.php uses in order to render the facebook like button. I don't think that this must be included in the module, but I post here if it can be help someone.
function MYTHEME_preprocess_fblikebutton(&$variables) {
//Get the site URL to make string changes
$site_URL = $_SERVER['HTTP_HOST'];
//Modify the url string to obtain a language independent URL
$url_temp = str_replace('http://' . $site_URL, "", $variables['url']);
$url_temp = substr($url_temp, 4); //Delete the first 4 characters "/es/" corresponding to language
//get the normal drupal path like "node/12"
$font = drupal_lookup_path('source', $url_temp);
if (substr($font, 0, 4) == 'node') { //is node??
$node_ID = substr($font, 5); //extract the node ID
$current_node = node_load($node_ID);
//Get the translation original node to unify the like links
$base_node = $current_node->tnid;
$base_node = node_load($base_node);
$node_language = $base_node->language;
$alias = drupal_get_path_alias('node/'.$current_node->tnid, $node_language);
$variables['url'] = 'http://'.$site_URL.'/'.$node_language.'/'.$alias;
$url = 'http://'.$site_URL.'/'.$node_language.'/'.$alias;
}
//redefine this two variables in order to reconstruct the variables['src']
$show_faces = $variables['show_faces'] ? 'true' : 'false';
$language = ($variables['language']) ? '&locale=' . $variables['language'] : '';
$variables['src'] = htmlentities(sprintf('href=%s&layout=%s&show_faces=%s&width=%s&font=%s&height=%s&action=%s&colorscheme=%s%s&send=false',
$url,
$variables['layout'],
$show_faces,
$variables['width'],
$variables['font'],
$variables['height'],
$variables['action'],
$variables['color_scheme'],
$language
));
}
Comments
Comment #1
lliss CreditAttribution: lliss commentedInteresting. I can supply this with the module maybe in the readme as a reference for others.
Comment #2
lliss CreditAttribution: lliss commentedComment #2.0
lliss CreditAttribution: lliss commentedchange the name function to be more general