"New entry" menu ignores `Entry::EVENT_DEFINE_ENTRY_TYPES`, so a filtered type leads to a 400
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start in CpAsset::_entryTypes() and compare how it builds the menu type list with EntriesController::actionCreate(), which checks getAvailableEntryTypes(). Reproduce with the supplied event listener filtering out type b, then trace how Craft.EntrySelectInput uses the same list. Done when filtered types are absent from both create controls and choosing an offered type no longer leads to this 400.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Entry::EVENT_DEFINE_ENTRY_TYPES (added in 3.6 for #7136) lets a site narrow the entry types available for an entry. EntriesController::actionCreate() respects it: it looks up the ?type= handle in $entry->getAvailableEntryTypes() and throws BadRequestHttpException("Invalid entry type handle: …") when the handle isn't there.
The "New entry" menu on the entries index doesn't respect it. The menu's types come from Craft.publishableSections, which CpAsset::_entryTypes() builds from $section->getEntryTypes(), so the event never runs. Any type a site filters out is still offered in the menu, and choosing it gives a 400 error page. Craft.EntrySelectInput reads the same list for an Entries field's create button, so it probably has the same problem.
This affects any restriction the event is used for, including the permission and per-site restrictions #7136 was raised for.
A possible fix: in CpAsset::_entryTypes(), make a new Entry with sectionId (and siteId) set and use getAvailableEntryTypes(), the same as actionCreate() already does, so the menu and the create action agree. Listeners would then see an entry with no ID and no parent, which they can already be given through actionCreate().
Steps to reproduce
- Make a section with two entry types,
aandb. - Register a listener that removes
b:Event::on(Entry::class, Entry::EVENT_DEFINE_ENTRY_TYPES, function(DefineEntryTypesEvent $event) { $event->entryTypes = array_values(array_filter( $event->entryTypes, fn(EntryType $type) => $type->handle !== 'b', )); }); - Go to Entries, select the section, open the "New entry" menu and choose
b.
Expected behavior
The "New entry" menu only offers the types the event leaves, the same as the entry type switcher and actionCreate().
Actual behavior
The menu offers b, and choosing it gives a 400: "Invalid entry type handle: b".
- Craft CMS version: 5.11.5.1
- PHP version: 8.4
- Operating system and version: DDEV (Debian) on macOS
- Database type and version: MySQL 8.4
- Image driver and version: n/a
- Installed plugins and versions: None needed. The listener is in a module.
- Lingua principale
- PHP
- Stelle
- 3.6k
- Fork
- 712
- Merge medio
- 13h 20m
- PR unite (30g)
- 357
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun 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 craftcms/cms
-
bug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
craftcms/cms#20205 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedApertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
craftcms/cms#20203 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[5.x]: Moving an asset with “Replace it” throws TypeError: volumeUid must be of type string, null givenForse già presa @i-just l’ha presa 7 giorni fa. Apertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
craftcms/cms#20128 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[5.x]: Passing `withProvisionalDrafts` on a Matrix field throws `array_intersect()` TypeErrorForse già presa @brandonkelly l’ha presa 1 giorno fa. Apertabug repo:cms
craftcms/cms#20308 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug repo:cms
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
craftcms/cms#20204 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di craftcms/cms
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
agentic bug complete-verify
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MagnaCapax/PMSS#1234 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
yiisoft/yii2-docker#193 ·
-
dependencies javascript Status: Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
json-schema-org/website#2628 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno