0

I have a drupal 6 site I wish to migrate to drupal 8.

My configuration includes:

migrate_plus.migration.upgrade_d6_node_complete_club.yml

# ...
class: Drupal\node\Plugin\migrate\D6NodeTranslation
field_plugin_method: null
cck_plugin_method: null
# ...
source:
  plugin: d6_node_complete
  node_type: club
# ...
process:
  # ...
  field_latitude:
    -
      plugin: get
      source: field_latitude
  field_longitude:
    -
      plugin: get
      source: field_longitude
# ...

When I run drush migrate:import, the club content is correctly migrated.

I wish the drupal 8 club content to include a geofield.

Following https://www.drupal.org/node/2866147, I modified the configuration to be:

# ...
process:
  # ...
  field_latitude:
    -
      plugin: get
      source: field_latitude
  field_longitude:
    -
      plugin: get
      source: field_longitude
  field_geofield:
      plugin: geofield_latlon
      source:
        - field_latitude
        - field_longitude
# ...

I manually added (using the web ui) a new field_geofield to the drupal 8 club content-type. Then I did drush migrate:rollback upgrade_d6_node_complete_club and drush migrate:import upgrade_d6_node_complete_club.

However, the drupal 8 club new geofield always just has latitude:longitude coordinates of 1:1.


I looked at web/modules/contrib/geofield/src/Plugin/migrate/process/GeofieldLatLon.php and saw:

  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $value = array_map('floatval', $value);
    list($lat, $lon) = $value;

I added a var_dump($value) at the top. It shows that with the process YAML as above, transform() receives $value like:

array(2) {
  [0]=>
  array(1) {
    [0]=>
    array(2) {
      ["value"]=>
      string(9) "50.854334"
      ["delta"]=>
      string(1) "0"
    }
  }
  [1]=>
  array(1) {
    [0]=>
    array(2) {
      ["value"]=>
      string(9) "-0.553837"
      ["delta"]=>
      string(1) "0"
    }
  }
}

I don't need the geofield_latlon plugin anywhere else for the migration, so I could just prefix transform() with:

$value = array_map(function($k){return $k[0]['value'];}, $value);

Is there a way to adjust just the YAML, without having to write any code, so that geofield_latlon receives its data in the correct format?

I feel that using something like the extract plugin ought to be possible but am having difficulty finding any good description of the semantics of migrate YML config files.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.