protected function DurationHumanDisplayFormatter::getTimePeriod in Duration Field 8
Returns a human-friendly value for a given time period key.
Parameters
string $type: The type of the humann readable value to retrieve.
int $value: The amount for that time period.
Return value
string The translateable human-friendly count of the given type
1 call to DurationHumanDisplayFormatter::getTimePeriod()
- DurationHumanDisplayFormatter::viewElements in src/Plugin/ Field/ FieldFormatter/ DurationHumanDisplayFormatter.php 
- Builds a renderable array for a field value.
File
- src/Plugin/ Field/ FieldFormatter/ DurationHumanDisplayFormatter.php, line 275 
Class
- DurationHumanDisplayFormatter
- Provides a formatter for the duration field type.
Namespace
Drupal\duration_field\Plugin\Field\FieldFormatterCode
protected function getTimePeriod($type, $value) {
  $text_length = $this
    ->getSetting('text_length');
  if ($type == 'year') {
    if ($text_length == 'full') {
      return $this
        ->formatPlural($value, '1 year', '@count years');
    }
    else {
      return $this
        ->formatPlural($value, '1 yr', '@count yr');
    }
  }
  elseif ($type == 'month') {
    if ($text_length == 'full') {
      return $this
        ->formatPlural($value, '1 months', '@count months');
    }
    else {
      return $this
        ->formatPlural($value, '1 mo', '@count mo');
    }
  }
  elseif ($type == 'day') {
    return $this
      ->formatPlural($value, '1 day', '@count days');
  }
  elseif ($type == 'hour') {
    if ($text_length == 'full') {
      return $this
        ->formatPlural($value, '1 hour', '@count hours');
    }
    else {
      return $this
        ->formatPlural($value, '1 hr', '@count hr');
    }
  }
  elseif ($type == 'minute') {
    if ($text_length == 'full') {
      return $this
        ->formatPlural($value, '1 minute', '@count minutes');
    }
    else {
      return $this
        ->formatPlural($value, '1 min', '@count min');
    }
  }
  elseif ($type == 'second') {
    if ($text_length == 'full') {
      return $this
        ->formatPlural($value, '1 second', '@count seconds');
    }
    else {
      return $this
        ->formatPlural($value, '1 s', '@count s');
    }
  }
}