Last active
August 29, 2015 14:10
-
-
Save mareksotak/d7384c3dd391040c5059 to your computer and use it in GitHub Desktop.
FB Commons - making the Like button look like link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* These functions should be in template.php of your theme | |
* Just replace commons_origins with your theme name | |
*/ | |
/** | |
* Implements hook_preprocess_rate_template_commons_like(). | |
*/ | |
function commons_origins_preprocess_rate_template_commons_like(&$variables, $hook) { | |
// Roll the content into a renderable array to make the template simpler. | |
$link_text = $variables['links'][0]['text']; | |
// replace default Like text with Unlike if user voted | |
if (isset($variables['results']['user_vote'])) { | |
$link_text = t('Unlike'); | |
} | |
$variables['content'] = array( | |
'link' => array( | |
'#theme' => 'rate_button__commons_like', | |
'#text' => $link_text, | |
'#href' => $variables['links'][0]['href'], | |
'#class' => 'rate-commons-like-btn', | |
) | |
); | |
} | |
/** | |
* Overrides hook_rate_button() for commons_like. | |
*/ | |
function commons_origins_rate_button__commons_like($variables) { | |
$text = $variables['text']; | |
$href = $variables['href']; | |
$class = ''; | |
static $id = 0; | |
$id++; | |
$classes = 'rate-button'; | |
if ($class) { | |
$classes .= ' ' . $class; | |
} | |
if (empty($href)) { | |
// Widget is disabled or closed. | |
return '<span class="' . $classes . '" id="rate-button-' . $id . '">' . | |
'<span class="">' . ucfirst(check_plain($text)) . '</span>' . | |
'</span>'; | |
} | |
else { | |
return '<a class="' . $classes . '" id="rate-button-' . $id . '" rel="nofollow" href="' . htmlentities($href) . '" title="' . check_plain($text) . '">' . | |
'<span class="">' . ucfirst(check_plain($text)) . '</span>' . | |
'</a>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In line 49 there is no need for an else here. If the condition in the if is true then it will return out of the function. You can just write it like