Parameter-Specific State Providers for Hierarchical CRUDs
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 42/100
調査の方向性
まず AdminUrlGenerator と ActionFactory を追跡し、必須のルートパラメータ、特に entityId がどのように解決されるかを確認してから、AdminRoute と AdminContext の統合を調べます。階層型ルートにおける index、detail、new、edit リンクの動作を比較します。provider がエンティティ以外のパラメータを提供でき、値が欠落している場合は既存の例外動作が維持され、標準の CRUD リンクが親コンテキストを保持できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
1. The Core Problem: Mandatory Parameter Persistence
EasyAdmin's AdminUrlGenerator is hardcoded to prioritize entityId. When a developer defines a hierarchical route like this:
#[AdminRoute(path: '/{parentId}/sub-resource/{entityId}')]
class MyCrudController extends AbstractCrudController
{
...
}
the following occurs:
- The Generator Error: When rendering links on the
indexordetailpages, the generator sees{parentId}in the route but has no source to fetch it from. - The Twig Crash: This results in a
MissingMandatoryParametersExceptionduring the rendering of standard action buttons (Edit, Delete, etc.). - The Lifecycle Gap: Even if the URL is manually hacked together, the "Parent" context is lost when moving between
index,new, andeditactions.
2. Proposed Solution: StateProviderInterface
I propose a single, focused interface. Its job is to resolve a specific value for a given parameter name based on the current context (the Request or the specific Entity being rendered in a row).
interface StateProviderInterface
{
/**
* @param string $paramName The placeholder name (e.g., 'parentId')
* @param AdminContext $context The current admin request context
* @return mixed The value to be injected into the route (int, string, or object e.g Uuid::v4())
*/
public function resolve(string $paramName, AdminContext $context): mixed;
}
3. Registration via #[AdminRoute]
The provider is linked directly to the controller via the existing AdminRoute attribute. This creates a clear contract: "If you use this route, use this provider to fill its placeholders (with the exception of entityId)."
#[AdminRoute(
path: '/admin/{parentId}/category/{entityId}',
provider: CategoryStateProvider::class
)]
class CategoryCrudController extends AbstractCrudController
{
// ...
}
Usage Example
class CategoryStateProvider implements StateProviderInterface
{
public function resolve(string $paramName, AdminContext $context): mixed
{
if ($paramName === 'parentId') {
return $context->getEntity()->getInstance()->getParent()->getId();
}
return null; // This should fallback to the default exception for mandatory parameter
}
}
4. How this Resolves the "Top-Level" Logic
A. Bulletproof URL Generation
When the ActionFactory generates a link for an EDIT action:
- It identifies that the route requires
{parentId}. - It calls the
StateProvider::resolve('parentId', $context). - The provider returns a value to fill the parentId (e.g.,
$entityDto->getInstance()->getParent()->getId()). - The URL survives: The generator now has all required data to build a valid Symfony route.
B. Implicit Parent Association
Because the AdminContext now tracks the resolved parentId, standard CRUD methods become aware of the hierarchy:
createEntity(): Can automatically pullparentIdfrom the context to assign the owner.createIndexQueryBuilder(): Can automatically filter the list so users only see children of the currentparentId.
5. Why this "Top-Level" Fix?
Instead of forcing developers to override every single action to manually inject a parentId, this solution fixes the Data Source for the AdminUrlGenerator.
By providing a single entity/value for a given parameter name, we allow EasyAdmin to handle Nested Resources and Multi-tenancy out of the box. It transforms EasyAdmin from a flat-file manager into a true hierarchical CMS.
Comparison: Current vs. Proposed
| Feature | Current State | With StateProvider |
|---|---|---|
| Route Requirement | Only entityId is auto-filled. |
parentId (or any name) is auto-filled. |
| Implementation | Overriding 4-5 core methods. | One Interface + Attribute. |
| Reliability | Twig crashes on custom routes. | Twig renders valid links dynamically. |
| Logic Location | Scattered throughout Controller. | Centralized in the Provider. |
- 主要言語
- PHP
- スター
- 4.3k
- フォーク
- 1.1k
- 平均マージ
- 2日 9時間
- マージ済み PR(30日)
- 52
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
EasyCorp/EasyAdminBundle のほかの issue
-
bug design
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
EasyCorp/EasyAdminBundle#7958 ·
メンテナーはふだん 2 日以内に返信
-
design feature
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
EasyCorp/EasyAdminBundle#7930 ·
メンテナーはふだん 2 日以内に返信
-
design
難易度 2/5 1時間未満 初心者へのやさしさ 88/100
EasyCorp/EasyAdminBundle#7879 ·
メンテナーはふだん 2 日以内に返信
-
design
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
EasyCorp/EasyAdminBundle#7875 ·
メンテナーはふだん 2 日以内に返信
-
#[AdminRoute]: the requirements of an action silently replace the ones of the class対応中かも @anthonyhacart が 2 日前に担当しました。 オープンfeature
難易度 3/5 半日 初心者へのやさしさ 30/100
EasyCorp/EasyAdminBundle#7956 ·
メンテナーはふだん 2 日以内に返信
EasyCorp/EasyAdminBundle の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
taskforcesh/bullmq#5238 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects it対応中かも @bfs2021 が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Automattic/jetpack#55517 ·
メンテナーはふだん 1 日以内に返信
-
Major
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PrestaShop/ps_onepagecheckout#245 ·
メンテナーはふだん 1 日以内に返信
-
wpvc
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
10up/ElasticPress#4420 ·
メンテナーはふだん 1 日以内に返信