You are here

public function HMSService::factor_map in HMS Field 8

Returns the factor map of the format options.

Note: We cannot go further then weeks in this setup. A month implies that we know how many seconds a month is. Problem here is that a month can be 28(29), 30 or 31 days. Same goes for C (century) Y (year) Q (quarter). Only solution is that we have a value relative to a date.

Use HOOK_hms_factor_alter($factors) to do your own magic.

Parameters

boolean $return_full:

Return value

array

Overrides HMSServiceInterface::factor_map

3 calls to HMSService::factor_map()
HMSService::formatted_to_seconds in src/HMSService.php
Returns number of seconds from a formatted string.
HMSService::normalize_format in src/HMSService.php
Helper to normalize format.
HMSService::seconds_to_formatted in src/HMSService.php
Returns a formatted string form the number of seconds.

File

src/HMSService.php, line 41

Class

HMSService
Provides a service to handle various hms related functionality.

Namespace

Drupal\hms_field

Code

public function factor_map($return_full = FALSE) {
  $factor = drupal_static(__FUNCTION__);
  if (empty($factor)) {
    $factor = [
      'w' => [
        'factor value' => 604800,
        'label single' => 'week',
        'label multiple' => 'weeks',
      ],
      'd' => [
        'factor value' => 86400,
        'label single' => 'day',
        'label multiple' => 'days',
      ],
      'h' => [
        'factor value' => 3600,
        'label single' => 'hour',
        'label multiple' => 'hours',
      ],
      'm' => [
        'factor value' => 60,
        'label single' => 'minute',
        'label multiple' => 'minutes',
      ],
      's' => [
        'factor value' => 1,
        'label single' => 'second',
        'label multiple' => 'seconds',
      ],
    ];
    \Drupal::moduleHandler()
      ->alter('hms_factor', $factor);
  }
  if ($return_full) {
    return $factor;
  }

  // We only return the factor value here.
  // for historical reasons we also check if value is an array.
  $return = [];
  foreach ($factor as $key => $val) {
    $value = is_array($val) ? $val['factor value'] : $val;
    $return[$key] = $value;
  }
  return $return;
}