All nodes of one content type in my project need to get automatically flagged (by the Flags module) when created.
I'm aware that there is probably a way to accomplish this using Rules module, but I'm attempting to build my first-ever custom module to do it, because a) I don't think I'm going to need Rules for anything else in this project and b) want to get my feet wet on making custom modules. (I've got a basic 'hello world' module working.)
A support request in the Flag module seems to provide a simple way to automatically flag nodes, but it looks to me like it would do this to nodes of all content types.
https://www.drupal.org/project/flag/issues/3030288
For convenience here's the code there, for a flag called bookmark...
function your_module_node_insert(Drupal\Core\Entity\EntityInterface $entity){
$flag = \Drupal::entityTypeManager()->getStorage('flag')->load('bookmark');
\Drupal::service('flag')->flag($flag, $entity);
}
The api page for this hook doesn't seem to tell me what I need to know. (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_ENTITY_TYPE_insert/9.0.x)
Questions: Is this even the right hook for this need? If so, how might I restrict it to a specific content type?