ListExport.php in Entity Export CSV 8
File
src/Plugin/FieldTypeExport/ListExport.php
View source
<?php
namespace Drupal\entity_export_csv\Plugin\FieldTypeExport;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\entity_export_csv\Plugin\FieldTypeExportBase;
use Drupal\Core\Field\FieldItemInterface;
class ListExport extends FieldTypeExportBase {
public function getSummary() {
return [
'message' => [
'#markup' => $this
->t('List field type exporter.'),
],
];
}
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();
}
$format = $configuration['format'];
if ($format === 'list_label') {
$value = $field_item
->get($property_name)
->getValue();
$allowed_values = $field_definition
->getFieldStorageDefinition()
->getSetting('allowed_values');
return isset($allowed_values[$value]) ? $allowed_values[$value] : $value;
}
return $field_item
->get($property_name)
->getValue();
}
protected function getFormatExportOptions(FieldDefinitionInterface $field_definition) {
$options = parent::getFormatExportOptions($field_definition);
$options['list_label'] = $this
->t('Label');
return $options;
}
}