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.
Normally, if you want to programmatically set a field value on an entity, you can just use a snippet like the following...
<?php
$wrapper = entity_metadata_wrapper($entity_type, $entity_id);
$wrapper{$field_name}->set($field_value);
?>
However, this doesn't work for location fields and results in an "unknown data property" error, because the field doesn't even exist on the entity wrapper. The following code will print all of the fields on the entity except location fields.
<?php
$wrapper = entity_metadata_wrapper($entity_type, $entity_id);
dpm($wrapper->getPropertyInfo());
?>
I'm not the first person to run into this:
http://drupal.stackexchange.com/questions/59195/how-do-i-write-to-locati...
Comments
Comment #1
jakeschlachter CreditAttribution: jakeschlachter commentedThis actually works the way you expect, but only if you first enable the location_entity module.
I wasted a lot of time learning that. I'm updating this bug report to instead request that this behavior be moved into the main location module so it will be available by default. I believe this is more consistent with the principle of Least Surprise.
For anyone else struggling with this, check out the referenced stackexchange question.
Comment #2
michielkenis CreditAttribution: michielkenis as a volunteer commentedI'ld like to bump this issue and confirm the location_entity module is required in order to get this to work!
Thanks jakeschlachter for the info!
Comment #3
Chris CharltonOdd, I have the Location Entity contrib module enabled but I cannot see the location field/array at all yet even when I use the following code below. Thoughts?