Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

entity_repository

263 sites Security covered
View on drupal.org

Provides a basic API for queries. This module won't do much by itself.
Extend the base classes and create your own repository classes.

Usage

e.g. when creating a repository for the news content type.

Create a service

news.repository.news:
  class: Drupal\news\Repository\NewsRepository
  parent: entity_repository.repository.node

Create a repository class

The property $bundles limits the results to the given bundles. The base
NodeRepository class contains a lot of queries by default like findAll().


namespace Drupal\news\Repository;

use Drupal\entity_repository\Repository\NodeRepository;

/**
 * Class NewsRepository.
 *
 * @package Drupal\news\Repository
 */
class NewsRepository extends NodeRepository {

  protected $bundles = ['news'];

  /**
   * {@inheritdoc}
   */
  public function findByTags(array $tags = [], int $pager = NULL, $sort = NULL) : array {
    $query = $this->getBaseQuery();

    if (!empty($tags)) {
      $query->condition('field_news_tags', $tags, 'IN');
    }

    if ($pager) {
      $query->pager($pager);
    }

    if ($sort) {
      $query->sort($sort['field'], $sort['dir'], $this->getLangCode());
    }

    return $this->getResults($query);
  }

}

<h3>Use the repository class</h3>
<?php
$nodes = \Drupal::service('news.repository.news')->findAll();

Create a repository without a custom class

When you don't need custom queries, you can create a repository without without creating an empty repository class.
You can add a new service and call the setBundles or setVocabularies for taxonomy terms on the base class.

news.repository.news:
  class: Drupal\entity_repository\Repository\NodeRepository
  arguments:
    - '@database'
    - '@entity_type.manager'
    - '@language_manager'
  calls:
    - [setBundles, [['news']]]

Activity

Total releases
1
First release
Oct 2025
Latest release
5 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
2.0.5 Stable Oct 21, 2025