4

I currently have a calendar of events and each event has multiple repeating dates. Now when i display them it shows all those repeating dates in a long list. How would i theme this to show only if there are more than 3 dates to display":

Has multiple dates in the coming month

I was thinking of doing this via tpl's, but what should i name my tpl as to override this output?

enter image description here

  • I don't understand your question can you re-word it? – No Sssweat Mar 29 '14 at 13:18
  • What modules are you using for this? – Felix Eve Apr 2 '14 at 14:13
  • Where it says event date. i want it to show only "Has multiple dates" instead of showing that long list. as you can see its not exactly a pleasant look with all those dates listed. – Patoshi パトシ Apr 2 '14 at 16:42
0

You need a new custom Formatter for this. Some proposed solutions are listed below (with an order of importance):

...

You can use Devel to inspect your field structure.

  • No answer for almost a week and then we both answer within 60 seconds of each other! – Felix Eve Apr 3 '14 at 10:50
  • @FelixEve I came here from a tweet... – TheodorosPloumis Apr 3 '14 at 19:10
0

Using template_preprocess_field seems to do the trick. You can either put this in your themes template.php or in a custom module.

function YOUR_THEME_preprocess_field(&$variables) {

    $most_repeating_dates_to_show = 5; // set limit of how many repeating dates is acceptable to show

    if($variables['element']['#field_name'] == 'field_date') { // Put your actual field name where it says "field_date"

        $num_repeats = count($variables['items']); // get count of how many repeating dates there are

        if($num_repeats > $most_repeating_dates_to_show) {

            $nid = $variables['element']['#object']->nid; // get the nid of the parent node

            // set the title of the link to show how many repeating dates there are
            $link_options = array(
                'attributes' => array(
                    'title' => t('See all :num repeating dates', array(':num' => $num_repeats))
                )
            );

            $link = l('Has multiple dates', 'node/'.$nid.'/repeats', $link_options);

            $variables['items'] = array(0 => array('#markup' => $link)); // here we overwrite the whole array of items so only our link will show

        }

    }

}

I've added a bit of extra functionality turning your text "Has multiple dates" into a link that links to the full list of repeating dates.

0

What i did was modify hook_date_display_single() as seen below. I had it detect todays date then compare it to the repeating dates and if they are past todays date grey it out and do a strikethrough. I also had it remove the YEAR using preg_replace(). I did that so it wouldn't show up for that specific date format. Its a quick and dirty fix, but obviously it can be polished up.

/**
 * Returns HTML for a date element formatted as a single date.
 */
function THEMENAME_date_display_single($variables) {
  $date = $variables['date'];
  $noyr_date = preg_replace('/\.[0-9][0-9][0-9][0-9]/', '', $variables['date']);
  $timezone = $variables['timezone'];
  $attributes = $variables['attributes'];

if(((time()-(60*60*24)) > strtotime($date)) && (strtotime($date) != 0)) {
  // Wrap the result with the attributes.
  return '<span class="date-display-single"' . drupal_attributes($attributes) . '><del>' . $noyr_date . $timezone . '</del></span>';
} else {
  return '<span class="date-display-single"' . drupal_attributes($attributes) . '>' . $noyr_date . $timezone . '</span>';
}
}

The output of that looks like this as compared to the original on the original question:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.