i have created Event entity, and I have custom page.

I want to load ALL Entity rows and then use it in my template.

This is the way everyone is prsenting, but i don't know how can i get NID value

$events = \Drupal::entityTypeManager()->getStorage('event')->load($nid);

Using Symfony i could do this like:

$events = $this->getDoctrine()->getRepository(Event::class)->findAll();

This is the solution

$storage = Drupal::entityTypeManager()->getStorage('event');

$nids = Drupal::entityQuery('event')->execute();
//Load all nids
$events = $storage->loadMultiple($nids);
//You can also use
$events = $storage->loadMultiple();
  • 3
    An empty loadMultiple() loads all entities by default: $events = $storage->loadMultiple(); – 4k4 Feb 25 '18 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.