"New entry" menu ignores `Entry::EVENT_DEFINE_ENTRY_TYPES`, so a filtered type leads to a 400
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 3.6k
- Fork
- 714
- Merge trung bình
- 13 giờ 9 phút
- Pull request đã merge (30 ngày)
- 378
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của craftcms/cms
-
bug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
craftcms/cms#20205 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedĐang mởbug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
craftcms/cms#20203 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[5.x]: MCP returns `[]` for CKEditor field valuesCó thể đã có người làm @i-just đã nhận 2 ngày trước. Đang mởrepo:cms
craftcms/cms#20404 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Entry edit page takes ~0.4s longer to first paint for every Matrix blockCó thể đã có người làm @riasvdv đã nhận 2 ngày trước. Đang mởbug repo:cms
craftcms/cms#20401 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Custom entry source with a single-section condition shows another source's entriesCó thể đã có người làm @brandonkelly đã nhận 2 ngày trước. Đang mởbug
craftcms/cms#20388 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Include flows spanning the full report time windowCó thể đã có người làm @somethingwithproof đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Cacti/plugin_flowview#306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
crazy-goat/workerman-bundle#1189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Captured slideshow pass overwrites the route path, aborting compose with a rebind() TypeErrorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Automattic/blocks-engine#5003 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
from-cloud mythic tracked
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
MythicalLTD/FeatherPanel#459 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày