Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Drupal 9 entity.repository load entity by UUID

use SymfonyComponentHttpKernelExceptionHttpException;

$node_uuid = 'UUID STRING HERE';
try {
  $node = Drupal::service('entity.repository')->loadEntityByUuid('node', $node_uuid);
  $nid = $node->id();
  unset($node);

} catch (Exception $e) {
  throw new HttpException(400, 'Node UUID does not match one in the system.');
}
 
PREVIOUS NEXT
Tagged: #Drupal #load #entity #UUID
ADD COMMENT
Topic
Name
4+1 =