Getting the node object in hook_form_FORM_ID_alter Follow up to this question  but I don't have enough reputation to ask clarification in a comment.

I am porting a contributed module to Drupal 8.
The sugested code on the above mentioned CR and post is not working:

$node = $form_state-&gt;getFormObject()-&gt;getEntity();


Nothing is loaded into the $node variable.

My PHPStorm IDE gives a warning for getEntity():
Method 'getEntity' not found in class Drupal\Core\Form\FormInterface less... 
Referenced method is not found in subject class.

It is also not presenting this method for code completion.

In the use cause I am referencing:

use Drupal\Core\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
use Drupal\Core\Render\Element;
PhpStorm doesn't know as the type of form object is dynamic but it's fine.

If you want to make it happy, wrap it in a condition like:

if ($form_state-&gt;getFormObject() instanceof EntityForm) {
  ...
}


Either way, it should definitely work if you implement the correct form alter. If you don't, you should end up with a fatal error not just without a node object.

You need to share your exact code if you want a more specific answer, that's all I can tell you.