$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
$user = \Drupal\user\Entity\User::create(); $user->setUsername('newuser'); $user->setPassword('password'); $user->setEmail('newuser@example.com'); $user->save();
$comment = \Drupal\comment\Entity\Comment::load($cid); $comment->set('comment_body', [ 'value' => 'New comment text', 'format' => 'plain_text', ]); $comment->save();This code retrieves a comment entity object by its ID, updates its body text, and saves the changes to the database. Overall, the entityTypeManager in Drupal is a powerful tool for working with entities in PHP code.