public function SmartdateFieldBuilder::build in Smart Date 3.3.x
Same name and namespace in other branches
- 3.4.x src/Plugin/diff/Field/SmartdateFieldBuilder.php \Drupal\smart_date\Plugin\diff\Field\SmartdateFieldBuilder::build()
File
- src/
Plugin/ diff/ Field/ SmartdateFieldBuilder.php, line 29
Class
- SmartdateFieldBuilder
- Plugin to diff text fields.
Namespace
Drupal\smart_date\Plugin\diff\FieldCode
public function build(FieldItemListInterface $field_items) {
$result = [];
$format = \Drupal::entityTypeManager()
->getStorage('smart_date_format')
->load($this->configuration['format']);
// Every item from $field_items is of type FieldItemInterface.
foreach ($field_items as $field_key => $field_item) {
$values = $field_item
->getValue();
if (!isset($values['value'])) {
continue;
}
if (!isset($values['end_value'])) {
if (isset($values['duration']) && $values['duration'] > 0) {
$values['end_value'] = $values['value'] + $values['duration'] * 60;
}
else {
$values['end_value'] = $values['value'];
}
}
$date_value = static::formatSmartDate($values['value'], $values['end_value'], $format
->getOptions(), NULL, 'string');
$result[$field_key][] = $this
->t('Date: @date_value', [
'@date_value' => $date_value,
]);
}
return $result;
}