Active
Project:
Location
Version:
7.x-3.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Jan 2014 at 18:11 UTC
Updated:
3 Aug 2016 at 22:32 UTC
Jump to comment: Most recent
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 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 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?