Last active
August 29, 2015 14:02
-
-
Save petebarnett/f281eed632e1e2dc1edf to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Implements hook_theme(). | |
*/ | |
function ds_extras_tokens_theme() { | |
// Declare our own theme hook, to add to the | |
// theme_hook_suggestions for 'field' | |
return array( | |
'theme_ds_field_expert_tokens' => array( | |
'render element' => 'element', | |
'function' => 'theme_ds_field_expert_tokens', | |
) | |
); | |
} | |
/** | |
* Implements hook_theme_registry_alter(). | |
*/ | |
function ds_extras_tokens_theme_registry_alter(&$theme_registry) { | |
// Add our preprocess function, which handles adding theme hook suggestions | |
$theme_registry['field']['preprocess functions'][] = 'ds_extras_tokens_preprocess_field'; | |
} | |
/** | |
* Theme preprocess function for 'field'. | |
* @see ds_extras_tokens_theme_registry_alter() | |
*/ | |
function ds_extras_tokens_preprocess_field(&$vars) { | |
// We are only overriding theme function when the "Expert" DS Extras template is used | |
if (isset($vars['ds-config']) && $vars['ds-config']['func'] == 'theme_ds_field_expert') { | |
$vars['theme_hook_suggestions'][0] = 'theme_ds_field_expert_tokens'; | |
} | |
} | |
/** | |
* Theme function for field | |
*/ | |
function theme_ds_field_expert_tokens($vars) { | |
// Do our thing | |
$vars['label'] = token_replace($vars['label'], array($vars['element']['#entity_type'] => $vars['element']['#object'])); | |
// Hand over to the DS theme function | |
return theme('theme_ds_field_expert', $vars); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment