You are here

public static function ConvertBundles::getToFields in Convert Bundles 8

1 call to ConvertBundles::getToFields()
ConvertBundlesForm::buildForm in src/Form/ConvertBundlesForm.php
Form constructor.

File

src/ConvertBundles.php, line 78

Class

ConvertBundles
ConvertBundles.

Namespace

Drupal\convert_bundles

Code

public static function getToFields($fields_to) {
  $fields_to_names = [];
  $fields_to_types = [];

  // Add some extra options for the form.
  $fields_to_names['remove'] = 'remove';
  $fields_to_names['append_to_body'] = 'append_to_body';

  // Get the to fields in an array.
  foreach ($fields_to as $field) {
    if ($field
      ->getFieldStorageDefinition()
      ->isBaseField() == FALSE) {

      // Because might be target_id.
      $val_name = $field
        ->getFieldStorageDefinition()
        ->getMainPropertyName();

      // Because some data types are more complex.
      $data_type = '';
      $type = $field
        ->getType();
      if (empty($field
        ->getFieldStorageDefinition()
        ->getPropertyDefinition($val_name))) {
        $data_type = $type;
      }
      else {
        $data_type = $field
          ->getFieldStorageDefinition()
          ->getPropertyDefinition($val_name)
          ->getDataType();
      }
      $fields_to_names[$field
        ->getName()] = '[' . $field
        ->getName() . '] ' . (is_object($field
        ->getLabel()) ? $field
        ->getLabel()
        ->render() : $field
        ->getLabel());
      $fields_to_types[$field
        ->getName()] = $data_type;
    }
  }
  return [
    'fields_to_names' => $fields_to_names,
    'fields_to_types' => $fields_to_types,
  ];
}