How to add data programatically?

Created on 18 April 2016, over 8 years ago
Updated 24 February 2024, 9 months ago

Hi,
I am creating nodes with Geofield programatically:

$node = Node::create([      
                'type' => 'request',
                'title' => 'Assistance request from ' . $phone,                 
                'body' => [ 
                'value' => '',
                'format' => 'basic_html'
                ],          
                'field_agent_assigned' => [reset($agent_user)],
                'field_phone_number' => [$phone],
'field_geofield' => array('lat' => $request->get('lat'), 'lon' => $request->get('lon')), 
                'uid' => $user->id(),                                                    
                ]);                                                                      
             

Is there a way to pass the lat/lon coordinates programmatically? I don't see anything in the documentation and the way I have tried doesn't work.

Thanks!

💬 Support request
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇿Czech Republic meba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands ekes

    The comment #7 is correct, and really if these are calculated it should result in them being calculated before the entity save when using the short $entity->field->value method for setting.

    I've opened a new issue, rather than re-opening this rather old one, also as it's a bit more involved. It includes that it is recalculating it when it needn't be, and with a failing test in a branch here 🐛 Computed values Active

Production build 0.71.5 2024