📜  Drupal 9 entity.repository 通过 UUID 加载实体 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:12.740000             🧑  作者: Mango

代码示例1
use Symfony\Component\HttpKernel\Exception\HttpException;

$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.');
}