use Drupal\Core\Entity\EntityManagerInterface; class MyClass { protected $entityManager; public function __construct(EntityManagerInterface $entity_manager) { $this->entityManager = $entity_manager; } public function doSomething() { $node = $this->entityManager->getStorage('node')->load(1); $title = $node->getTitle(); // Do something with the node title... } }
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\node\Entity\Node; class MyClass { protected $entityManager; public function __construct(EntityManagerInterface $entity_manager) { $this->entityManager = $entity_manager; } public function createNode($title, $body) { $node = Node::create([ 'type' => 'article', 'title' => $title, 'body' => [ 'value' => $body, 'format' => 'plain_text', ], ]); $node->save(); } }This example demonstrates how to use the entityManager to create a new node entity with specified title and body values. The entityManager belongs to the Drupal\Core\Entity component/library.