Idea for V3 of entity_repository

Created on 16 June 2021, over 3 years ago
Updated 12 July 2024, 5 months ago

Idea for V3 of entity_repository:

Convert the services to plugins and introduce an EntityRepositoryManager class.

$blog_articles_repository = $this->repositoryManager->getRepository('node', 'blog_article');
$blog_articles = blog_articles_repository->findAll();

Plugins would look something like:

<?php

namespace Drupal\my_custom_blog_article_module\src\Plugin\EntityRepository;

use Drupal\entity_repository\BaseNodeRepository;

/**
 * @entityRepository(
 *   entity_type = "node",
 *   bundle = "blog_article",
 * )
 */
class BlogArticleRepository extends BaseNodeRepository {
  
  public function findByCategory(int $id) {
    return $this->findBy(['field_blog_category' => $id]);
  }

}

When you call the repositoryManager->getRepository('node', 'blog_article') and no plugin is provided, fallback to the default class BaseNodeRepository so ->findAll(), ->findBy still works and you only have to add plugins to add custom queries.

🌱 Plan
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium JeroenT 🇧🇪

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.71.5 2024