You are here

private function SmartDateTrait::addRangeClasses in Smart Date 3.2.x

Same name and namespace in other branches
  1. 3.0.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
  2. 3.1.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
  3. 3.3.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
  4. 3.4.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()

Add spans provides classes to allow the dates and times to be styled.

Parameters

array $instance: The render array of the formatted date range.

3 calls to SmartDateTrait::addRangeClasses()
SmartDateDailyRangeFormatter::viewElements in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateDailyRangeFormatter.php
SmartDateRecurrenceFormatter::viewElements in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php
SmartDateTrait::viewElements in src/SmartDateTrait.php

File

src/SmartDateTrait.php, line 128

Class

SmartDateTrait
Provides friendly methods for smart date range.

Namespace

Drupal\smart_date

Code

private function addRangeClasses(array &$instance) {
  if (isset($instance['start']) && isset($instance['start']['date']) && $instance['start']['date']) {
    $instance['start']['date']['#prefix'] = '<span class="smart-date--date">';
    $instance['start']['date']['#suffix'] = '</span>';
  }
  if (isset($instance['start']) && isset($instance['start']['time']) && $instance['start']['time']) {
    $instance['start']['time']['#prefix'] = '<span class="smart-date--time">';
    $instance['start']['time']['#suffix'] = '</span>';
  }
  if (isset($instance['end']) && isset($instance['end']['date']) && $instance['end']['date']) {
    $instance['end']['date']['#suffix'] = '</span>';
    if (isset($instance['start']) && isset($instance['start']['date']) && $instance['start']['date']) {

      // Range, so put span around the full range.
      $instance['start']['date']['#suffix'] = '';
    }
    else {
      $instance['end']['date']['#prefix'] = '<span class="smart-date--date">';
    }
  }
  if (isset($instance['end']) && isset($instance['end']['time']) && $instance['end']['time']) {
    $instance['end']['time']['#suffix'] = '</span>';
    if (isset($instance['start']) && isset($instance['start']['time']) && $instance['start']['time']) {

      // Range, so put span around the full range.
      $instance['start']['time']['#suffix'] = '';
    }
    else {
      $instance['end']['time']['#prefix'] = '<span class="smart-date--time">';
    }
  }
}