Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm currently migrating a site from Drupal 7 to Drupal 8.
Geofield has a "geofield_latlon" MigrateProcessPlugin, but it doesn't have anything that allows to migrate boundaries information.
How can I migrate boundaries information? Or is there an elegant way to import boundaries information from a csv?
This is a rather crucial aspect of my Drupal site.
Comment | File | Size | Author |
---|---|---|---|
#5 | geofield-migrate-process-wkt-directly-3074552-5.patch | 1.63 KB | glbr |
Comments
Comment #2
stopopol CreditAttribution: stopopol commentedComment #3
stopopol CreditAttribution: stopopol commentedComment #4
stopopol CreditAttribution: stopopol commentedOK. I've had a closer look at the existing MigrateProcessPlugin and I think it should work to add another one that allows to migrate any WKT.
In /src/Plugin/migrate/process you could copy the GeofieldLatLon.php and then in the transform function you could take the $value and check if it's valid WKT (e.g. https://stackoverflow.com/questions/9985484/php-validate-wkt-values) and if yes, just return $this->$value.
A MigrateProcessPlugin like this would allow much easier mass import of any geometry, not just points.
However, this is just an idea. I'm hardly familiar with the geofield module and would like to hear other ideas or input first.
Comment #5
glbr CreditAttribution: glbr as a volunteer commentedI found this issue after going through the same thinking while trying to import boundaries from a CSV. This is not just a D7/D8 issue.
Being able to directly migrate/import WKT would be useful in many cases. Lat/Lon imports could be done using such a process plugin in combination with a concat process step. Only having lat/lon is very restricting (although I recognize it covers the standard case many people).
I'm attaching a patch that implements the basic idea outlined by @stopopol in #4, except that it doesn't validate the WKT before returning it. In my case, I had a CSV with about 1000 WKT entries that I knew were all valid.
This creates a process plugin called geofield_wkt. For example, with a field type (based on Geofield) called field_boundary and a CSV column named WKT, use it in your config.yml as:
Comment #6
itamair CreditAttribution: itamair commentedComment #8
itamair CreditAttribution: itamair commentedthanks @stopopol. Committed into dev, will be part of the next geofield module release ...
Comment #10
m.stentaI don't mean to revive an old issue, but I just looked into using this plugin and noticed that it isn't actually doing anything.
The
GeofieldWKT
class pulls in thegeofield.wkt_generator
service via dependency injection but doesn't use it anywhere.The
transform()
method just returns the value, so it is essentially the same as theget
plugin.It sounds like @stopopol originally recommended performing some WKT validation:
Notably, if you set
validate: true
in the migration'sdestination
config,$entity->validate()
will be called and invalid WKT will throw an error. This is the proper way to handle validation, I think.With all that in mind, I don't think this
geofield_wkt
plugin provides any additional value over the coreget
plugin. Should we consider deprecating it and removing it in the next major release?Comment #11
itamair CreditAttribution: itamair commentedthanks @m.stenta
definitely right you are ...
geofield.wkt_generator service is needed in the geofield_latlon @MigrateProcessPlugin but not in the geofield_wkt one.
The following (just performed) commit accomplishes what you suggest in the 8.x-1.x branch:
https://git.drupalcode.org/project/geofield/-/commit/77e70c1b0ba74478984...
It will be part of the next Geofield 8.x release.
Comment #12
m.stentaMakes sense thanks for responding so quickly @itamair. If you would like any help with deprecating it I'd be happy to start a separate issue for that. Also fine to leave as is. :-)
Comment #13
itamair CreditAttribution: itamair commentedHi @m.stenta … I cannot (I am not sure I can) get what you mean in “deprecating” it …
The geofield.wkt_generator service still is used (needed) elsewhere.
What needs to be deprecate?
What is further needed on this? (also with an additional issue …?)
Comment #14
m.stentaOh sorry for the misunderstanding.
I meant we could consider deprecating the
geofield_wkt
migrate process plugin. It doesn't perform any transformation of source values. It just takes the value and returns it.In other words, these are equivalent:
The latter uses Drupal core's
get
plugin, which just takes the source value as-is and inserts it into the field. So thegeofield_wkt
plugin is redundant.But there's also no harm in keeping it as a placeholder, in case any additional logic needs to be added in the future.
Comment #15
itamair CreditAttribution: itamair commentedAh! got it @m.stenta ...
Thanks for the detailed explanation. Sometime I loose detailed track of what it is going on all over these Geofield stack of modules.
What you say makes perfect sense, but let's keep it as example @MigrateProcessPlugin and not harmful placeholder for Geofield.
I provided this new commit:
https://git.drupalcode.org/project/geofield/-/commit/483958ae703f02f46cb...
where I simply added all your warning into the @MigrateProcessPlugin description itself.
Comment #16
m.stentaThat's great - thanks @itamair for your dedicated maintenance!