How to load an entity definition? I need to load an entity definition to add a constraint and test it, I found that this is possible with the following code:

$manager = \Drupal::entityDefinitionUpdateManager();
$entity_definition = $manager-&gt;getEntityType('node');
$entity_definition-&gt;addConstraint(‘name’);


But I wonder if this is the correct way or if exists another.
The only case where you want to work with entityDefinitionUpdateManager() in update and post update hooks, to update an entity type definition on existing installations to the one defined on the annotation.

To add a constraint to an entity type that's not yours use hook_entity_type_alter()