protected function SmartDateTrait::addRangeClasses in Smart Date 3.4.x
Same name and namespace in other branches
- 3.0.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
- 3.1.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
- 3.2.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addRangeClasses()
- 3.3.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 179
Class
- SmartDateTrait
- Provides friendly methods for smart date range.
Namespace
Drupal\smart_dateCode
protected function addRangeClasses(array &$instance) {
// Array to define where wrapper parts should be skipped, for a range.
$skip = [];
// If a time range within a day, make a single wrapper around the times.
if ((isset($instance['start']['date']) xor isset($instance['end']['date'])) && isset($instance['start']['time'], $instance['end']['time'])) {
$skip['start']['time']['#suffix'] = TRUE;
$skip['end']['time']['#prefix'] = TRUE;
}
elseif (isset($instance['start']['date'], $instance['end']['date']) && (!isset($instance['start']['time']) || !isset($instance['end']['time']))) {
$skip['start']['date']['#suffix'] = TRUE;
$skip['end']['date']['#prefix'] = TRUE;
}
// Wrap all parts by default.
foreach ([
'start',
'end',
] as $part) {
foreach ([
'date',
'time',
] as $subpart) {
if (isset($instance[$part][$subpart]) && $instance[$part][$subpart]) {
if (!isset($skip[$part][$subpart]['#prefix'])) {
$instance[$part][$subpart]['#prefix'] = '<span class="smart-date--' . $subpart . '">';
}
if (!isset($skip[$part][$subpart]['#suffix'])) {
$instance[$part][$subpart]['#suffix'] = '</span>';
}
}
}
}
}