You are here

trait SmartDateRecurTrait in Smart Date 3.2.x

Same name and namespace in other branches
  1. 3.1.x modules/smart_date_recur/src/SmartDateRecurTrait.php \Drupal\smart_date_recur\SmartDateRecurTrait
  2. 3.3.x modules/smart_date_recur/src/SmartDateRecurTrait.php \Drupal\smart_date_recur\SmartDateRecurTrait
  3. 3.4.x modules/smart_date_recur/src/SmartDateRecurTrait.php \Drupal\smart_date_recur\SmartDateRecurTrait

Provides friendly methods for smart date range.

Hierarchy

2 files declare their use of SmartDateRecurTrait
SmartDateDailyRangeFormatter.php in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateDailyRangeFormatter.php
SmartDateRecurrenceFormatter.php in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php

File

modules/smart_date_recur/src/SmartDateRecurTrait.php, line 8

Namespace

Drupal\smart_date_recur
View source
trait SmartDateRecurTrait {

  /**
   * Helper function to massage an array for inclusion in output.
   */
  private function massageForOutput($output, array $settings, $add_classes = NULL) {
    if (!$add_classes) {
      $add_classes = $this
        ->getSetting('add_classes');
    }
    if ($settings['date_first']) {

      // Time should be first so reverse the array.
      ksort($output);
    }
    $temp_array['start'] = $output;
    if ($add_classes) {
      $this
        ->addRangeClasses($temp_array);
    }
    return $temp_array['start'];
  }

  /**
   * Helper function to create a collapsed display of events within a day.
   */
  private function formatWithinDay(array $instances, array $settings) {
    $settings_notime = $this
      ->settingsFormatNoTime($settings);
    $settings_nodate = $this
      ->settingsFormatNoDate($settings);
    $settings_notz = $this
      ->settingsFormatNoTz($settings_nodate);
    $output = [];
    foreach ($instances as $time_set) {
      $this_output = [];
      $time_output = [];
      $last_time = array_pop($time_set);
      foreach ($time_set as $key => $instance) {
        $time_output[$key] = static::formatSmartDate($instance->value, $instance->end_value, $settings_notz, $instance->timezone);
        $time_output[$key]['#suffix'] = ', ';
      }
      $time_output[] = static::formatSmartDate($last_time->value, $last_time->end_value, $settings_nodate, $last_time->timezone);
      $this_output['time'] = $time_output;
      $this_output['join'] = [
        '#markup' => $settings['join'],
      ];
      $this_output['date']['#markup'] = static::formatSmartDate($last_time->value, $last_time->value, $settings_notime, $last_time->timezone, 'string');
      $this_output['#attributes']['class'] = [
        'smart-date--daily-times',
      ];
      $this_output['#type'] = 'container';
      $output[] = $this
        ->massageForOutput($this_output, $settings);
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SmartDateRecurTrait::formatWithinDay private function Helper function to create a collapsed display of events within a day.
SmartDateRecurTrait::massageForOutput private function Helper function to massage an array for inclusion in output.