Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Entity repository

228 sites Security covered Drupal 8–11 Entity ecosystem
View on drupal.org

This module provides a system to create custom repositories for entities, allowing for simplified querying and data retrieval. You can extend base repository classes to define specific queries for your content types or other entities.

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']]]

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Oct 2025
Latest release
10 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Slowing

Releases

Version Type Core Release date
2.0.5 Stable 8–11 Oct 21, 2025