public function DateRangeExport::massageExportPropertyValue in Entity Export CSV 8
Massage the field item property value to CSV value.
Parameters
\Drupal\Core\Field\FieldItemInterface $field_item: The field item.
string $property_name: The property name.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
array $options: An array of optional options.
Return value
mixed The CSV value.
Overrides FieldTypeExportBase::massageExportPropertyValue
File
- src/
Plugin/ FieldTypeExport/ DateRangeExport.php, line 72
Class
- DateRangeExport
- Defines a Date range field type export plugin.
Namespace
Drupal\entity_export_csv\Plugin\FieldTypeExportCode
public function massageExportPropertyValue(FieldItemInterface $field_item, $property_name, FieldDefinitionInterface $field_definition, $options = []) {
if ($field_item
->isEmpty()) {
return NULL;
}
$configuration = $this
->getConfiguration();
if (empty($configuration['format'])) {
return $field_item
->get($property_name)
->getValue();
}
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$timezone = NULL;
$format = NULL;
$settings = [
'langcode' => $langcode,
];
$date_format_id = $configuration['format'];
$custom_date_format = !empty($configuration['custom_date_format']) ? $configuration['custom_date_format'] : '';
// If an RFC2822 date format is requested, then the month and day have to
// be in English. @see http://www.faqs.org/rfcs/rfc2822.html
if ($date_format_id === 'custom' && $custom_date_format === 'r') {
$langcode = 'en';
$settings['langcode'] = $langcode;
}
if (!empty($custom_date_format) && $date_format_id === 'custom') {
$format = $custom_date_format;
}
else {
if ($date_format = $this
->getDateFormat($date_format_id, $langcode)) {
$format = $date_format
->getPattern();
}
}
$date = NULL;
if ($property_name === 'value') {
$date = $field_item->start_date;
}
elseif ($property_name === 'end_value') {
$date = $field_item->end_date;
}
if ($date instanceof DrupalDateTime && $format) {
return $date
->format($format, $settings);
}
// Fallback to the raw value.
return $field_item
->get($property_name)
->getValue();
}