You are here

protected function SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions in Smart Date 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  2. 3.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  3. 3.0.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  4. 3.1.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  5. 3.2.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  6. 3.3.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
  7. 3.4.x src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php \Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()

Get an array of available Smart Date format options.

Return value

string[] An array of Smart Date Format machine names keyed to Smart Date Format names, suitable for use in an #options array.

1 call to SmartDateDefaultFormatter::getAvailableSmartDateFormatOptions()
SmartDateDefaultFormatter::settingsForm in src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/SmartDateDefaultFormatter.php, line 106

Class

SmartDateDefaultFormatter
Plugin implementation of the 'Default' formatter for 'smartdate' fields.

Namespace

Drupal\smart_date\Plugin\Field\FieldFormatter

Code

protected function getAvailableSmartDateFormatOptions() {
  $formatOptions = [];
  $smartDateFormats = \Drupal::entityTypeManager()
    ->getStorage('smart_date_format')
    ->loadMultiple();
  foreach ($smartDateFormats as $type => $format) {
    if ($format instanceof SmartDateFormat) {
      $formatted = static::formatSmartDate(time(), time() + 3600, $format
        ->getOptions(), NULL, 'string');
      $formatOptions[$type] = $format
        ->label() . ' (' . $formatted . ')';
    }
  }
  return $formatOptions;
}