In hook_form_alter(), how can I access the entity that is being flagged? In hook_form_alter(), I want to load the entity being flagged so that I can do some processing based on the field values of that entity.
However, I can't find an entity object using kint($form).  I know it must be there somewhere because the flag is correctly attached to the entity.
function MYMODULE_form_flagging_MYFLAG_add_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  kint($form);
  kint($form_state);
  // Where is the flagged entity object id?
}

On the flagging object, after the flagged has been saved, the entity id can be accessed like this:
    $flagged_entity_id = $flagging-&gt;get('entity_id')-&gt;value;

However, in hook_form_alter(), when the flag has not yet been saved for the first time, I can't find the entity_id in $form.
I thought it might be in $form_state, but I got a NULL result for $form_state-&gt;get('entity_id').
Ok, thanks to leymannx and No Sssweat, I think I finally understand how to get the entity from a form.
To get the entity being flagged inside a flag, this is what I had to do:
function MYMODULE_form_flagging_MYFLAG_add_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
      $flagging_entity = $form_state-&gt;getFormObject()-&gt;getEntity();
      $flagged_entity_id = $flagging_entity-&gt;get('entity_id')-&gt;value;
}