Skip to content

Instantly share code, notes, and snippets.

@kevinchampion
Last active December 16, 2015 16:09
Show Gist options
  • Save kevinchampion/5461164 to your computer and use it in GitHub Desktop.
Save kevinchampion/5461164 to your computer and use it in GitHub Desktop.
language handling best practice
/**
* Link field has issue with rendering the <front> option. Lets give it a bit
* of help
* @param $variables preprocess variables
* @param $hook
*/
function openedu_linkblock_preprocess_field(&$vars, $hook) {
global $language;
$lang = $language->language;
// If link field...
if($vars['element']['#field_type'] == "link_field") {
$field_name = $vars['element']['#field_name'];
foreach($vars['element']['#object']->{$field_name}[$lang] as $k => $v) {
if($v['url'] == "&lt;front&gt;") {
if(isset($v['attributes']['target']) && $v['attributes']['target'] == "user") {
unset($v["attributes"]['target']);
}
$vars['items'][$k]["#markup"] = l($v['title'], "<front>", array('attributes' => $v['attributes'], 'html' => TRUE, 'language' => $language));
}
}
}
}
/**
* Link field has issue with rendering the <front> option. Lets give it a bit
* of help
* @param $variables preprocess variables
* @param $hook
*/
function openedu_linkblock_preprocess_field(&$vars, $hook) {
global $language;
$lang = $language->language;
// If link field...
if($vars['element']['#field_type'] == "link_field") {
$field_name = $vars['element']['#field_name'];
foreach($vars['element']['#object']->{$field_name}[$vars['element']['#object']->language] as $k => $v) {
if($v['url'] == "&lt;front&gt;") {
if(isset($v['attributes']['target']) && $v['attributes']['target'] == "user") {
unset($v["attributes"]['target']);
}
$vars['items'][$k]["#markup"] = l($v['title'], "<front>", array('attributes' => $v['attributes'], 'html' => TRUE, 'language' => $language));
}
}
}
}
/**
* Link field has issue with rendering the <front> option. Lets give it a bit
* of help
* @param $variables preprocess variables
* @param $hook
*/
function linkblock_preprocess_field(&$vars, $hook) {
// If link field...
if ($vars['element']['#field_type'] == "link_field") {
$field_name = $vars['element']['#field_name'];
foreach ($vars['element']['#object']->{$field_name} as $lang => $value) {
foreach ($value as $k => $v) {
if ($v['url'] == "&lt;front&gt;") {
if (isset($v['attributes']['target']) && $v['attributes']['target'] == "user") {
unset($v["attributes"]['target']);
}
$vars['items'][$k]["#markup"] = l($v['title'], "<front>", array(
'attributes' => $v['attributes'],
'html' => TRUE,
'language' => $lang
)
);
}
}
}
}
}
@kevinchampion
Copy link
Author

Is line #15 of lang.php best practice for handling languages? Why?

Is line #15 of lang2.php wrong? Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment