You are here

private function DurationWidget::getGranularity in Duration Field 8

Get the granularlity of field elements for the widget to display.

Return value

string A comma-separate string containing keys of duration elements to be shown

2 calls to DurationWidget::getGranularity()
DurationWidget::formElement in src/Plugin/Field/FieldWidget/DurationWidget.php
Returns the form for a single field widget.
DurationWidget::settingsForm in src/Plugin/Field/FieldWidget/DurationWidget.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/DurationWidget.php, line 140

Class

DurationWidget
Creates a default widget to output a duration field.

Namespace

Drupal\duration_field\Plugin\Field\FieldWidget

Code

private function getGranularity() {
  $granularity = $this
    ->getFieldSetting('granularity');
  $time_elements = [
    'year' => 'y',
    'month' => 'm',
    'day' => 'd',
    'hour' => 'h',
    'minute' => 'i',
    'second' => 's',
  ];
  $granularity_elements = [];
  foreach ($time_elements as $key => $time_element) {
    if ($granularity[$key]) {
      $granularity_elements[] = $time_element;
    }
  }
  return implode(':', $granularity_elements);
}