Last active
August 29, 2015 14:24
-
-
Save infojunkie/9f8e66432270437f3776 to your computer and use it in GitHub Desktop.
Drupal theme tokens
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
name = Token Theme | |
description = Create tokens for theme settings. | |
core = 7.x |
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 | |
/** | |
* Implementation of hook_token_info(). | |
*/ | |
function token_theme_token_info() { | |
$theme = variable_get('theme_default'); | |
theme_get_setting('default_logo', $theme); | |
$theme_settings = &drupal_static('theme_get_setting', array()); | |
$type = array( | |
'name' => t('Theme'), | |
'description' => t('Tokens related to current theme.'), | |
); | |
$tokens = array(); | |
foreach ($theme_settings[$theme] as $key => $value) { | |
$tokens[$key] = array( | |
'name' => $key, | |
'description' => t('The value of theme setting !setting.', array('!setting' => $key)), | |
); | |
} | |
return array( | |
'types' => array('theme' => $type), | |
'tokens' => array('theme' => $tokens), | |
); | |
} | |
/** | |
* Implementation of hook_tokens(). | |
*/ | |
function token_theme_tokens($type, $tokens, array $data = array(), array $options = array()) { | |
if ($type !== 'theme') return array(); | |
$theme = variable_get('theme_default'); | |
theme_get_setting('default_logo', $theme); | |
$theme_settings = &drupal_static('theme_get_setting', array()); | |
$replacements = array(); | |
foreach ($tokens as $name => $original) { | |
if (array_key_exists($name, $theme_settings[$theme])) { | |
$value = $theme_settings[$theme][$name]; | |
// Logos etc. have a scheme://target path and need to be converted to URLs. | |
$url = file_create_url($value); | |
$replacements[$original] = $url ? $url : $value; | |
} | |
} | |
return $replacements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment