drupal-8drupal-preprocess

How do I query Drupal 8 Media by type?


I've created a Media type called "ad_gallery" can I can't seem to pull in all the entries while preprocessing.

I'm trying

\Drupal::entityQuery('media')->condition('type','ad_gallery')->execute();

And it's saying:

Drupal\Core\Entity\Query\QueryException: 'type' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable()

Is there a different way to query these than there is nodes?


Solution

  • You should use bundle instead of type.

    Something like this will do the trick:

    \Drupal::entityQuery('media')->condition('bundle', 'ad_gallery')->execute();