Last active
April 22, 2017 15:20
-
-
Save olafgrabienski/cfc07b395e44daf76968145428b7b733 to your computer and use it in GitHub Desktop.
Custom date token for Backdrop CMS event content type URL alias pattern
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 = Custom Date Tokens | |
description = Adds custom tokens for date fields. | |
package = Custom | |
version = BACKDROP_VERSION | |
type = module | |
backdrop = 1.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 | |
/** | |
* @file | |
* Provides custom tokens for building URL aliases using date fields. | |
*/ | |
/** | |
* Implements hook_token_info(). | |
*/ | |
function custom_date_tokens_token_info() { | |
$info['tokens']['node']['field-date-custom'] = array( | |
'name' => t('Event Custom Date Format'), | |
'description' => t('Custom date field value for events, format: Y-M-D.'), | |
); | |
return $info; | |
} | |
/** | |
* Implements hook_tokens(). | |
*/ | |
function custom_date_tokens_tokens($type, $tokens, array $data = array(), array $options = array()) { | |
$replacements = array(); | |
if ($type == 'node' && !empty($data['node'])) { | |
$node = $data['node']; | |
foreach ($tokens as $name => $original) { | |
switch ($name) { | |
case 'field-date-custom': | |
$time = strtotime($node->field_event_date['und'][0]['value']); | |
$newformat = date('Y-m-d',$time); | |
$replacements[$original] = $newformat; | |
break; | |
} | |
} | |
} | |
return $replacements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment