// Declare user entity type. $entity_type = 'user'; // Create a new user entity object. $user = \Drupal::entityTypeManager()->getStorage($entity_type)->create(); $user->set('name', 'johndoe'); $user->set('mail', 'johndoe@example.com'); $user->set('status', TRUE); // Save the new user entity. $user->save();
// Declare node entity type. $entity_type = 'node'; // Load a node entity object. $node = \Drupal::entityTypeManager()->getStorage($entity_type)->load(1); // Update the node entity properties. $node->set('title', 'New Title'); $node->set('body', 'New content for the node.'); // Save the updated node entity. $node->save();
// Declare taxonomy term entity type. $entity_type = 'taxonomy_term'; // Load a taxonomy term entity object. $term = \Drupal::entityTypeManager()->getStorage($entity_type)->load(2); // Delete the taxonomy term entity. $term->delete();Overall, the typedDataManager is a powerful tool for developers who work with Drupal entities. It provides an easy and reliable way to manage entity data in a type-safe manner, which can reduce the risk of data-related bugs and errors.