You are here

protected function AddressExport::moveKeyBefore in Entity Export CSV 8

Utility function to move an element before another in an array.

Parameters

array $array: The array to change.

string $find: The key of the element before we want mode before the $move.

string $move: The key of the element we want to move before $find.

Return value

array The array sorted.

1 call to AddressExport::moveKeyBefore()
AddressExport::getFieldProperties in src/Plugin/FieldTypeExport/AddressExport.php
Gets the field's properties.

File

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

Class

AddressExport
Defines an Address field type export plugin.

Namespace

Drupal\entity_export_csv\Plugin\FieldTypeExport

Code

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;
}