Group fieldtype does not apply entry validation replacements ({id}, {collection}, {site})
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #15541 của @eastagiletracker — đã đóng, không merge
Đá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
- 70/100
Hướng nghiên cứu
Bắt đầu tại src/Fieldtypes/Group.php và so sánh Group::extraRules() với các phương thức tương đương trong src/Fieldtypes/Grid.php và src/Fieldtypes/Replicator.php, vốn đã dùng trait AddsEntryValidationReplacements và gọi addEntryValidationReplacements(). Thêm trait và lời gọi vào Group, sau đó lặp lại phạm vi kiểm thử hiện có của Grid/Replicator cho việc thay thế {id}/{collection}/{site} (tìm các test tham chiếu đến entry validation replacements) để xác nhận rằng các rule dựa trên class lồng nhau được phân giải thay vì trở thành null. Lưu ý: một PR liên quan (#15541) đã bị đóng mà không merge — hãy xem thảo luận của nó trước khi bắt đầu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
Class-based validation rules that use {id}, {collection}, or {site} placeholders receive null when the field lives inside a Group fieldtype. Saving the same entry then treats the current entry as a duplicate of itself (for uniqueness-style rules).
This is the same class of bug as #10065, which was fixed for Replicator and Grid in #10255 by adding AddsEntryValidationReplacements. Group was never given that trait.
Expected: nested class-based rules inside a Group get the same replacements EntriesController@update already passes at the top level (id, collection, site).
Actual: Group::extraRules() builds a fresh validator with only {this} prefix context. Unmatched placeholders become the literal null in Validator::parseClassBasedRule(), so e.g. new \Statamic\Rules\UniqueEntryValue({collection}, {id}, {site}) is constructed as new UniqueEntryValue(null, null, null).
Still present on master as of v6.34.0 (src/Fieldtypes/Group.php has no AddsEntryValidationReplacements; Grid and Replicator do).
How to reproduce
- Fresh Statamic 6 site.
- On any collection blueprint, add a Group with a nested text field that uses the documented unique-entry rule:
-
handle: details
field:
type: group
display: Details
fields:
-
handle: code
field:
type: text
display: Code
validate:
- 'new \Statamic\Rules\UniqueEntryValue({collection}, {id}, {site})'
- Create an entry, set
details.codetoalpha, save. - Re-open that same entry, change any other field (or change nothing), save again.
Result: uniqueness validation fails against the entry being edited, because {id} was not substituted so the except argument is null.
The same null substitution happens for any new \Some\Rule({id}) inside a Group, not only UniqueEntryValue.
Why: Group::extraRules():
$rules = $this
->fields()
->addValues((array) $this->field->value())
->validator()
->withContext([
'prefix' => $this->field->validationContext('prefix'),
])
->rules();
Grid/Replicator call addEntryValidationReplacements() on that nested validator. Group does not.
PR #11931 only fixed {this} prefixing for Group children inside Replicator/Grid; it did not pass {id} / {collection} / {site}.
Suggested fix: use AddsEntryValidationReplacements on Statamic\Fieldtypes\Group and call addEntryValidationReplacements($this->field, $validator) in extraRules(), matching Grid/Replicator.
Logs
No application exception. Validation error is the uniqueness / custom-rule failure with {id} unresolved.
Environment
Sanitized (no project URL, addons, or app name). Reproduced against Statamic v6.33.0; code still missing the trait on master / v6.34.0.
Environment
Laravel Version: 13.32.0
PHP Version: 8.4
Environment: local
Debug Mode: ENABLED
Statamic
Version: 6.33.0 PRO
Installation
Fresh statamic/statamic site via CLI
Additional details
Related: #10065, #10255, #11931.
Happy to open a PR that adds the trait to Group plus a test mirroring the Grid/Replicator replacement coverage, if that helps.
- Ngôn ngữ chính
- PHP
- Star
- 4.9k
- Fork
- 647
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 102
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 statamic/cms
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
assets
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Make native filesystem directory permissions configurable to support shared POSIX ACL accessĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
accessibility
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
antlers
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
sync-en
Độ 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
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Перевод устарел
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
bug
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
m3ue/m3u-editor#1604 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
femiwiki/docker-mediawiki#1497 ·
Maintainer thường phản hồi trong vòng 1 ngày