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 trying to create a node with an addressfield, and to do so I needed to add the following to Drupal7::expandEntityFields().
elseif ('addressfield' === $info['module']) {
foreach ($value as $key => $data) {
$new_entity->{$param}[LANGUAGE_NONE][0][$key] = $data;
}
}
This way I can pass in
$node->field_address = array(
'organisation_name' => 'TestCorp',
'country' => 'AU',
'thoroughfare' => '1 St George Tce',
'premise' => 'Perth',
'locality' => 'Perth',
'administrative_area' => 'WA',
'postal_code' => '6000',
);
and have it save the field.
I realise this area of the code will be refactored at some point, so don't forget poor old addressfield!.
Comment | File | Size | Author |
---|---|---|---|
#3 | drupalextension-subcontexts-not-loading-2111271-2.patch | 671 bytes | samhassell |
Comments
Comment #1
jhedstromIf you set the data structure
in your FeatureContext does it work?
Comment #2
samhassell CreditAttribution: samhassell commentedThat was the first thing I tried, as that is how you would do it for node_save(). expandEntityFields() doesn't seem to like this, it just wants a string, so you can do stuff like
Then there is special handing for dates, you pass
for them.
Here's the code controlling this:
So you can see that it builds the [LANGUAGE_NONE][$i] for us, but doesn't consider fields with more than one element in their array.
Comment #3
samhassell CreditAttribution: samhassell commentedHere's a more generic version of the above patch.
Still can't see how this is supported without the patch.
Cheers.
Comment #4
jhedstromCommitted in 7b91493. Thanks!
Comment #5
samhassell CreditAttribution: samhassell commentedThanks for the named commit!