I am using the following code, but it doesn’t set the field value as I would expect.
use DrupalCoreEntityEntityInterface; /** * Implements hook_ENTITY_TYPE_update(). */ function mymodule_node_update(EntityInterface $entity) { if ($entity->getType() == "article") { $entity->set('field_set_color', ["red","green"]); } }
Why doesn’t this code set the field value?