Parameter-Specific State Providers for Hierarchical CRUDs
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
Direzione di ricerca
Inizia tracciando AdminUrlGenerator e ActionFactory per capire come vengono risolti i parametri di route obbligatori, in particolare entityId, quindi esamina l’integrazione di AdminRoute e AdminContext. Confronta il comportamento dei link index, detail, new ed edit per le route gerarchiche. Il lavoro è completo quando un provider può fornire parametri non relativi a un’entità, i valori mancanti mantengono il comportamento di eccezione esistente e i link CRUD standard preservano il contesto padre.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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. |
- Lingua principale
- PHP
- Stelle
- 4.3k
- Fork
- 1.1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 52
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di EasyCorp/EasyAdminBundle
-
bug design
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
EasyCorp/EasyAdminBundle#7958 ·
I maintainer di solito rispondono entro 2 giorni
-
design feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
EasyCorp/EasyAdminBundle#7930 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 88/100
EasyCorp/EasyAdminBundle#7879 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
EasyCorp/EasyAdminBundle#7875 ·
I maintainer di solito rispondono entro 2 giorni
-
#[AdminRoute]: the requirements of an action silently replace the ones of the classForse già presa @anthonyhacart l’ha presa 2 giorni fa. Apertafeature
Difficoltà 3/5 Mezza giornata Idoneità per principianti 30/100
EasyCorp/EasyAdminBundle#7956 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di EasyCorp/EasyAdminBundle
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
taskforcesh/bullmq#5238 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itForse già presa @bfs2021 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Automattic/jetpack#55517 ·
I maintainer di solito rispondono entro 1 giorno
-
Address edit modal: what the customer types before the fields load is reset to the saved valueApertaMajor
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
PrestaShop/ps_onepagecheckout#245 ·
I maintainer di solito rispondono entro 1 giorno
-
wpvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
10up/ElasticPress#4420 ·
I maintainer di solito rispondono entro 1 giorno