I created a module that receives the node ID from the form. On form validation, it needs to verify a node with that node ID exists.
How can I verify it?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
You can pass the nid to \Drupal\node\Entity\Node::load(). It will return an object if it exists, NULL if it doesn't.
If you don't want to load the entire node then you can use entity query:
$values = \Drupal::entityQuery('node')->condition('nid', $id)->execute(); $node_exists = !empty($values);
This will be much more efficient because it only asks for the ids and not all the node fields.