Skip to content

Drupal: Datum als Mikroformat

von dennis
/**
 * Implements hook_theme_registry_alter().
 * @see: http://drupal.stackexchange.com/questions/76972/override-theme-for-date-field-output
 */
function hook_theme_registry_alter(&$theme_registry) {
 
    if (isset($theme_registry['date_display_range'])) {
        $theme_registry['date_display_range']['function'] = 'theme_custom_date_display_range';
    }
    if (isset($theme_registry['date_display_single'])) {
        $theme_registry['date_display_single']['function'] = 'theme_custom_date_display_single';
    }
}
 
/**
 * Returns HTML for a date element formatted as a range.
 * @see: http://drupal.stackexchange.com/questions/76972/override-theme-for-date-field-output
 */
function theme_custom_date_display_range($variables) {
 
    return t('!start-date - !end-date', array(
        '!start-date' => '<span class="date-display-start dtstart"' . drupal_attributes($variables['attributes_start']) . '>'.str_replace(' ','&nbsp;',$variables['date1']).'</span>',
        '!end-date' => '<span class="date-display-end dtend"' . drupal_attributes($variables['attributes_end']) . '>'.str_replace(' ','&nbsp;',$variables['date2'].$variables['timezone']).'</span>',
    ));
}
 
/**
 * Returns HTML for a date element formatted as single.
 */
function theme_custom_date_display_single($variables) {
 
    return '<span class="date-display-single dtstart"'.drupal_attributes($variables['attributes']) . '>'.str_replace(' ','&nbsp;',$variables['date'].$variables['timezone']).'</span>';
}

Aus → Drupal

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS