How to know add/edit page in hook_form_alter?
In D8 you can get the operation of an entity form with the form object:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_state-&gt;getFormObject()-&gt;getOperation() == 'edit') {
    $page = 'edit';
  }
}