You are here

public static function ConvertNodes::sortUserInput in Convert Nodes 8

1 call to ConvertNodes::sortUserInput()
ConvertNodesForm::convertNodes in src/Form/ConvertNodesForm.php

File

src/ConvertNodes.php, line 113

Class

ConvertNodes
ConvertNodes.

Namespace

Drupal\convert_nodes

Code

public static function sortUserInput($userInput, $fields_new_to, $fields_from) {

  // Get user input and set up vars.
  $map_fields = [];
  $update_fields = [];

  // Remove stuff we don't need.
  $unset_data = [
    'op',
    'form_build_id',
    'form_token',
    'form_id',
  ];
  foreach ($userInput as $from => $to) {
    if (in_array($from, $unset_data)) {
      continue;
    }
    if ($from == $to) {
      $update_fields[] = $from;
    }
    elseif (in_array($from, $fields_new_to) && !in_array($from, $userInput)) {
      $map_fields['create_new'][] = [
        'field' => $from,
        'value' => $to,
      ];
    }
    else {
      $map_fields[$from] = [
        'field' => $to,
        'from_label' => $fields_from[$from]
          ->getLabel(),
        // This will come in later.
        'value' => [],
      ];
    }
  }
  return [
    'map_fields' => $map_fields,
    'update_fields' => $update_fields,
  ];
}