You are here

protected function TimeRangeFormatter::viewValue in Time Field For Drupal 8.x / 9.x 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/TimeRangeFormatter.php \Drupal\time_field\Plugin\Field\FieldFormatter\TimeRangeFormatter::viewValue()

Generate the output appropriate for one field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: One field item.

Return value

string The textual output generated.

1 call to TimeRangeFormatter::viewValue()
TimeRangeFormatter::viewElements in src/Plugin/Field/FieldFormatter/TimeRangeFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/TimeRangeFormatter.php, line 33

Class

TimeRangeFormatter
Plugin implementation of the 'time_formatter' formatter.

Namespace

Drupal\time_field\Plugin\Field\FieldFormatter

Code

protected function viewValue(FieldItemInterface $item) {

  // The text value has no text format assigned to it, so the user input
  // should equal the output, including newlines.
  $from = Time::createFromTimestamp($item->from);
  $to = Time::createFromTimestamp($item->to);
  $time_format = $this
    ->getSetting('time_format');
  $timerange_format = $this
    ->getSetting('timerange_format');
  $timerange_format = str_replace('start', $from
    ->format($time_format), $timerange_format);
  $timerange_format = str_replace('end', $to
    ->format($time_format), $timerange_format);
  return $timerange_format;
}