I'm trying to create a hook to flag a node when it is created automatically. This is the general approach I'm following.
<?phpfunction hook\_node\_insert($node) { $flag\_service = \Drupal::service('flag'); $flag\_entity = $flag\_service->getFlagById('flag\_machine\_name'); $flag\_service->flag($flag\_entity, $node); $node->save();}?>
However this is not working as expected. Is there some other step that needs to happen?