Last active
December 16, 2015 16:09
-
-
Save kevinchampion/5461164 to your computer and use it in GitHub Desktop.
language handling best practice
This file contains hidden or 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
/** | |
* 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'] == "<front>") { | |
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)); | |
} | |
} | |
} | |
} |
This file contains hidden or 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
/** | |
* 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'] == "<front>") { | |
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)); | |
} | |
} | |
} | |
} |
This file contains hidden or 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
/** | |
* 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'] == "<front>") { | |
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 | |
) | |
); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is line #15 of lang.php best practice for handling languages? Why?
Is line #15 of lang2.php wrong? Why?