How to know add/edit page in hook_form_alter? I want to know whether form is add/edit in hook_form_alter. In Drupal 7 we can get all these in hook_form_alter.

I tried like this in D7:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  // Check pages(s) , don't use $_GET.
    if (strpos($form['#action'], '/add/') !== FALSE) {
      $page = 'add';
    }
    if (strpos($form['#action'], '/edit') !== FALSE) {
      $page = 'edit';
    }
}


Here I am getting add/edit in D7. Whereas in D8 I am not getting any it in $form['#actions']. And i don't want to use $_GET.
Is there any way to check 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';
  }
}