You are here

class AddressExport in Entity Export CSV 8

Defines an Address field type export plugin.

Plugin annotation


@FieldTypeExport(
  id = "address_export",
  label = @Translation("Address export"),
  description = @Translation("Address export"),
  weight = 0,
  field_type = {
    "address",
  },
  entity_type = {},
  bundle = {},
  field_name = {},
  exclusive = FALSE,
)

Hierarchy

Expanded class hierarchy of AddressExport

File

src/Plugin/FieldTypeExport/AddressExport.php, line 26

Namespace

Drupal\entity_export_csv\Plugin\FieldTypeExport
View source
class AddressExport extends FieldTypeExportBase {

  /**
   * {@inheritdoc}
   */
  public function getSummary() {
    return [
      'message' => [
        '#markup' => $this
          ->t('Address field type exporter.'),
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function massageExportPropertyValue(FieldItemInterface $field_item, $property_name, FieldDefinitionInterface $field_definition, $options = []) {
    return parent::massageExportPropertyValue($field_item, $property_name, $field_definition, $options);
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldProperties(FieldDefinitionInterface $definition) {
    $properties = parent::getFieldProperties($definition);
    $properties = array_reverse($properties);
    $properties = $this
      ->moveKeyBefore($properties, 'address_line2', 'address_line1');
    $properties = $this
      ->moveKeyBefore($properties, 'administrative_area', 'sorting_code');
    $properties = $this
      ->moveKeyBefore($properties, 'locality', 'postal_code');
    $this->properties = $properties;
    return $this->properties;
  }

  /**
   * Utility function to move an element before another in an array.
   *
   * @param array $array
   *   The array to change.
   * @param string $find
   *   The key of the element before we want mode before the $move.
   * @param string $move
   *   The key of the element we want to move before $find.
   *
   * @return array
   *   The array sorted.
   */
  protected function moveKeyBefore(array $array, $find, $move) {
    if (!isset($array[$find], $array[$move])) {
      return $array;
    }
    $element = [
      $move => $array[$move],
    ];
    $start = array_splice($array, 0, array_search($find, array_keys($array)));
    unset($start[$move]);
    return $start + $element + $array;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AddressExport::getFieldProperties public function Gets the field's properties. Overrides FieldTypeExportBase::getFieldProperties
AddressExport::getSummary public function
AddressExport::massageExportPropertyValue public function Massage the field item property value to CSV value. Overrides FieldTypeExportBase::massageExportPropertyValue
AddressExport::moveKeyBefore protected function Utility function to move an element before another in an array.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
FieldTypeExportBase::$configFactory protected property The config factory service.
FieldTypeExportBase::$dateFormatter protected property Drupal\Core\Datetime\DateFormatterInterface definition.
FieldTypeExportBase::$entityFieldManager protected property Drupal\Core\Entity\EntityFieldManagerInterface definition.
FieldTypeExportBase::$entityRepository protected property Drupal\Core\Entity\EntityRepositoryInterface definition.
FieldTypeExportBase::$entityTypeManager protected property Drupal\Core\Entity\EntityTypeManagerInterface definition.
FieldTypeExportBase::$languageManager protected property The language manager service.
FieldTypeExportBase::$moduleHandler protected property Drupal\Core\Extension\ModuleHandlerInterface definition.
FieldTypeExportBase::$properties protected property The field properties.
FieldTypeExportBase::allowExportMultipleProperties protected function Default method to allow to export multiple properties.
FieldTypeExportBase::buildConfigurationForm public function Build the configuration form. Overrides FieldTypeExportInterface::buildConfigurationForm 4
FieldTypeExportBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
FieldTypeExportBase::defaultConfiguration public function
FieldTypeExportBase::export public function Export the value of a field. Overrides FieldTypeExportInterface::export
FieldTypeExportBase::fieldDefinitionIsMultiple protected function Is the field is multiple ?
FieldTypeExportBase::getColumns public function Get the columns to generate during the export. Overrides FieldTypeExportInterface::getColumns
FieldTypeExportBase::getConfiguration public function
FieldTypeExportBase::getDescription public function Retrieves the generator description. Overrides FieldTypeExportInterface::getDescription
FieldTypeExportBase::getFormatExportOptions protected function Get the format options to export. 7
FieldTypeExportBase::getHeaderLabel public function Get the header label for a field. Overrides FieldTypeExportInterface::getHeaderLabel
FieldTypeExportBase::getHeaderOptions protected function Get the header export options.
FieldTypeExportBase::getHeaders public function Get the header columns for a field. Overrides FieldTypeExportInterface::getHeaders
FieldTypeExportBase::getLabel public function Retrieves the label. Overrides FieldTypeExportInterface::getLabel
FieldTypeExportBase::getMainPropertyName protected function Get the main property name of a field.
FieldTypeExportBase::getMaxColumns protected function Get the max columns for multiple fields.
FieldTypeExportBase::getPropertiesSelected protected function Get the field properties selected.
FieldTypeExportBase::getPropertyColumnSeparator protected function Get the property separator selected.
FieldTypeExportBase::getPropertyColumnSeparatorOptions protected function Get the property separator options.
FieldTypeExportBase::getPropertyExportOptions protected function Get the properties options to export.
FieldTypeExportBase::getPropertyLabel protected function Get the property header label.
FieldTypeExportBase::getSeparatorsOptions protected function Get the separator options when exporting in a single column.
FieldTypeExportBase::import public function Import a value into a field. Overrides FieldTypeExportInterface::import
FieldTypeExportBase::propertiesInSeparateColumns protected function Should properties be exported in separated columns ?
FieldTypeExportBase::setConfiguration public function
FieldTypeExportBase::summary public function Provides a human readable summary of the plugin's configuration. Overrides FieldTypeExportInterface::summary
FieldTypeExportBase::validateConfigurationForm public function Validates a configuration form for this plugin. Overrides FieldTypeExportInterface::validateConfigurationForm
FieldTypeExportBase::__construct public function LogGeneratorBase constructor. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.