Is there a preferred approach modifying values?
I need to modify a value when a node loads, but must use other values from the node. The code below causes recursion errors.
function zzzmodule_entity_load(array $entities, $entity_type_id) {
foreach ($entities as $entity) {
if ($entity_type_id === "node" && $entity->hasField('other_field')) {
$t = $entity->title->value;
$o = $entity->other_field->value;
if (empty($o)) {
$o2 = json_encode($t);
$entity->set('other_field', $o2);
$entity->save();
}
}
}
}