DurationRawValueFormatter.php in Duration Field 8
File
src/Plugin/Field/FieldFormatter/DurationRawValueFormatter.php
View source
<?php
namespace Drupal\duration_field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class DurationRawValueFormatter extends FormatterBase {
public function settingsSummary() {
$summary = [];
$summary[] = $this
->t('Displays the value in <a href=":link">duration format</a>', [
':link' => 'http://en.wikipedia.org/wiki/Iso8601#Durations',
]);
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
$element[$delta] = [
'#markup' => $item->value,
];
}
return $element;
}
}