Skip to content
Snippets Groups Projects
Commit ed3701d3 authored by Dave Reid's avatar Dave Reid Committed by Ken Rickard
Browse files

Feature #1300596. Provide additional domain tokens.

parent 33fe84be
No related branches found
Tags 7.x-3.0-rc3
No related merge requests found
......@@ -47,11 +47,21 @@ function domain_token_info() {
'name' => t('Domain URL'),
'description' => t('The domain\'s URL, lower-cased and with only alphanumeric characters.'),
);
$info['tokens']['domain']['hostname'] = array(
'name' => t('Domain hostname'),
'description' => t('The domain hostname.'),
);
$info['tokens']['domain']['subdomain'] = array(
'name' => t('Subdomain'),
'description' => t('The subdomain, lower-cased and with only alphanumeric characters. Only works with *.example.com formats'),
);
$info['tokens']['node']['domain'] = array(
'name' => t('Domain information'),
'description' => t('The domain associated with this content.'),
'type' => 'domain',
);
return $info;
}
......@@ -61,7 +71,7 @@ function domain_token_info() {
function domain_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array();
// Base token handling.
if ($type == 'domain' && !empty($data['domain'])) {
$domain = $data['domain'];
......@@ -97,16 +107,39 @@ function domain_tokens($type, $tokens, array $data = array(), array $options = a
$subdomain = domain_url_encode($subdomain);
$replacements[$original] = $sanitize ? check_plain($subdomain) : $subdomain;
break;
case 'hostname':
$subdomain = $domain['subdomain'];
$replacements[$original] = $sanitize ? check_plain($subdomain) : $subdomain;
break;
}
}
}
if ($type == 'current-domain') {
// Node tokens.
if ($type == 'node' && !empty($data['node'])) {
$domain = domain_get_node_match($data['node']->nid);
$node = $data['node'];
// Check for valid domain data.
$domain = domain_get_node_match($node->nid);
if ($domain == -1) {
return;
}
// Loop through the tokens to not waste cycles.
foreach ($tokens as $name => $original) {
if ($name == 'domain') {
$replacements[$original] = $sanitize ? check_plain($domain['subdomain']) : $domain['subdomain'];
}
}
if ($domain_tokens = token_find_with_prefix($tokens, 'domain')) {
$replacements += token_generate('domain', $domain_tokens, array('domain' => $domain), $options);
}
}
// Current domain tokens.
elseif ($type == 'current-domain') {
$current_domain = domain_get_domain();
$replacements += token_generate('domain', $tokens, array('domain' => $current_domain), $options);
}
if ($type == 'default-domain') {
// Default domain tokens.
elseif ($type == 'default-domain') {
$default_domain = domain_default(FALSE);
$replacements += token_generate('domain', $tokens, array('domain' => $default_domain), $options);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment