Group fieldtype does not apply entry validation replacements ({id}, {collection}, {site})
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #15541 来自 @eastagiletracker —— 已关闭,未合并
评估
调研方向
从 src/Fieldtypes/Group.php 入手,将 Group::extraRules() 与 src/Fieldtypes/Grid.php 和 src/Fieldtypes/Replicator.php 中的等效方法进行比较,这两个文件已经使用 AddsEntryValidationReplacements trait 并调用了 addEntryValidationReplacements()。为 Group 添加该 trait 和调用,然后参照 Grid/Replicator 现有的针对 {id}/{collection}/{site} 替换的测试覆盖(查找引用 entry validation replacements 的测试),以确认嵌套的基于类的规则会被解析而不是变成 null。注意:有一个关联的 PR (#15541) 已被关闭且未合并——开始前请查看其讨论。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- PHP
- 星标
- 4.9k
- 派生
- 647
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 103
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
statamic/cms 的其他 Issue
-
preferences
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
There's a default crop when cropping images可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭assets
难度 2/5 1-3 小时 新手友好度 65/100
statamic/cms#15567 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
accessibility
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
antlers
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
landsman/adminer-desktop#120 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
-
L: java:gradle L: java:maven L: ruby:bundler T: bug 🐞
难度 2/5 1-3 小时 新手友好度 76/100
dependabot/dependabot-core#16547 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
glpi-project/glpi#25922 ·
维护者通常 1 天内回复