class DateRangeExport in Entity Export CSV 8
Defines a Date range field type export plugin.
Plugin annotation
@FieldTypeExport(
id = "daterange_export",
label = @Translation("Date range export"),
description = @Translation("Date range export"),
weight = 0,
field_type = {
"daterange",
},
entity_type = {},
bundle = {},
field_name = {},
exclusive = FALSE,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\entity_export_csv\Plugin\FieldTypeExportBase implements ContainerFactoryPluginInterface, FieldTypeExportInterface uses DependencySerializationTrait, DependencyTrait, StringTranslationTrait
- class \Drupal\entity_export_csv\Plugin\FieldTypeExport\DateRangeExport
- class \Drupal\entity_export_csv\Plugin\FieldTypeExportBase implements ContainerFactoryPluginInterface, FieldTypeExportInterface uses DependencySerializationTrait, DependencyTrait, StringTranslationTrait
Expanded class hierarchy of DateRangeExport
File
- src/
Plugin/ FieldTypeExport/ DateRangeExport.php, line 29
Namespace
Drupal\entity_export_csv\Plugin\FieldTypeExportView source
class DateRangeExport extends FieldTypeExportBase {
/**
* An array of date_format entity keyed by format and langcode.
*
* @var array
*/
protected $dateFormats = [];
/**
* {@inheritdoc}
*/
public function getSummary() {
return [
'message' => [
'#markup' => $this
->t('Datetime field type exporter.'),
],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FieldDefinitionInterface $field_definition) {
$configuration = $this
->getConfiguration();
$build = parent::buildConfigurationForm($form, $form_state, $field_definition);
$build['custom_date_format'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom date format'),
'#description' => $this
->t('See <a href="http://php.net/manual/function.date.php" target="_blank">the documentation for PHP date formats</a>.'),
'#default_value' => !empty($configuration['custom_date_format']) ? $configuration['custom_date_format'] : '',
];
$build['custom_date_format']['#states']['visible'][] = [
':input[name="fields[' . $field_definition
->getName() . '][form][options][format]"]' => [
'value' => 'custom',
],
];
return $build;
}
/**
* {@inheritdoc}
*/
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();
}
/**
* {@inheritdoc}
*/
protected function getFormatExportOptions(FieldDefinitionInterface $field_definition) {
$options = parent::getFormatExportOptions($field_definition);
$date_formats = [];
foreach ($this->entityTypeManager
->getStorage('date_format')
->loadMultiple() as $machine_name => $value) {
$date_formats[$machine_name] = $this
->t('@name format: @date', [
'@name' => $value
->label(),
'@date' => $this->dateFormatter
->format(REQUEST_TIME, $machine_name),
]);
}
$date_formats['custom'] = $this
->t('Custom');
return $options + $date_formats;
}
/**
* Loads the given format pattern for the given langcode.
*
* @param string $format
* The machine name of the date format.
* @param string $langcode
* The langcode of the language to use.
*
* @return \Drupal\Core\Datetime\DateFormatInterface|null
* The configuration entity for the date format in the given language for
* non-custom formats, NULL otherwise.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected function getDateFormat($format, $langcode) {
if (!isset($this->dateFormats[$format][$langcode])) {
$original_language = $this->languageManager
->getConfigOverrideLanguage();
$this->languageManager
->setConfigOverrideLanguage(new Language([
'id' => $langcode,
]));
$this->dateFormats[$format][$langcode] = $this->entityTypeManager
->getStorage('date_format')
->load($format);
$this->languageManager
->setConfigOverrideLanguage($original_language);
}
return $this->dateFormats[$format][$langcode];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateRangeExport:: |
protected | property | An array of date_format entity keyed by format and langcode. | |
DateRangeExport:: |
public | function |
Build the configuration form. Overrides FieldTypeExportBase:: |
|
DateRangeExport:: |
protected | function | Loads the given format pattern for the given langcode. | |
DateRangeExport:: |
protected | function |
Get the format options to export. Overrides FieldTypeExportBase:: |
|
DateRangeExport:: |
public | function | ||
DateRangeExport:: |
public | function |
Massage the field item property value to CSV value. Overrides FieldTypeExportBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
FieldTypeExportBase:: |
protected | property | The config factory service. | |
FieldTypeExportBase:: |
protected | property | Drupal\Core\Datetime\DateFormatterInterface definition. | |
FieldTypeExportBase:: |
protected | property | Drupal\Core\Entity\EntityFieldManagerInterface definition. | |
FieldTypeExportBase:: |
protected | property | Drupal\Core\Entity\EntityRepositoryInterface definition. | |
FieldTypeExportBase:: |
protected | property | Drupal\Core\Entity\EntityTypeManagerInterface definition. | |
FieldTypeExportBase:: |
protected | property | The language manager service. | |
FieldTypeExportBase:: |
protected | property | Drupal\Core\Extension\ModuleHandlerInterface definition. | |
FieldTypeExportBase:: |
protected | property | The field properties. | |
FieldTypeExportBase:: |
protected | function | Default method to allow to export multiple properties. | |
FieldTypeExportBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
FieldTypeExportBase:: |
public | function | ||
FieldTypeExportBase:: |
public | function |
Export the value of a field. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
protected | function | Is the field is multiple ? | |
FieldTypeExportBase:: |
public | function |
Get the columns to generate during the export. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
public | function | ||
FieldTypeExportBase:: |
public | function |
Retrieves the generator description. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
public | function |
Gets the field's properties. Overrides FieldTypeExportInterface:: |
1 |
FieldTypeExportBase:: |
public | function |
Get the header label for a field. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
protected | function | Get the header export options. | |
FieldTypeExportBase:: |
public | function |
Get the header columns for a field. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
public | function |
Retrieves the label. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
protected | function | Get the main property name of a field. | |
FieldTypeExportBase:: |
protected | function | Get the max columns for multiple fields. | |
FieldTypeExportBase:: |
protected | function | Get the field properties selected. | |
FieldTypeExportBase:: |
protected | function | Get the property separator selected. | |
FieldTypeExportBase:: |
protected | function | Get the property separator options. | |
FieldTypeExportBase:: |
protected | function | Get the properties options to export. | |
FieldTypeExportBase:: |
protected | function | Get the property header label. | |
FieldTypeExportBase:: |
protected | function | Get the separator options when exporting in a single column. | |
FieldTypeExportBase:: |
public | function |
Import a value into a field. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
protected | function | Should properties be exported in separated columns ? | |
FieldTypeExportBase:: |
public | function | ||
FieldTypeExportBase:: |
public | function |
Provides a human readable summary of the plugin's configuration. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
public | function |
Validates a configuration form for this plugin. Overrides FieldTypeExportInterface:: |
|
FieldTypeExportBase:: |
public | function |
LogGeneratorBase constructor. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |