I created a custom field but I don't know how to set a value. I can read values with
$entity->get('field_myfield')->getValue()[0]['data']
The field consists of several elements: value
, data
, api_key
I'm loading the entity and would like to set the values of the field programatically, I tried:
$entity->set('field_myfield', ['data' => 'some data'], 'value' => 'some value');
This doesn't work.
getValue()
in the first line, which you could, after modifying it, use in the second line to set the field.$entity->get('field_myfield')->getValue()
, this is what the second parameter of set() should look like.$data = $entity->field_my_field->data;
or$entity->field_my_field->data = 'some_data';