Group fieldtype does not apply entry validation replacements ({id}, {collection}, {site})
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
- #15541 @eastagiletracker による — マージされずにクローズ
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 70/100
調査の方向性
まず src/Fieldtypes/Group.php から始め、Group::extraRules() を src/Fieldtypes/Grid.php および src/Fieldtypes/Replicator.php の同等のメソッドと比較してください。これらは既に AddsEntryValidationReplacements トレイトを使用し、addEntryValidationReplacements() を呼び出しています。Group にそのトレイトと呼び出しを追加し、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日 9時間
- マージ済み PR(30日)
- 102
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
statamic/cms のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
assets
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 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
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 4 日以内に返信
-
Перевод устарел
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
bug
難易度 2/5 半日 初心者へのやさしさ 76/100
m3ue/m3u-editor#1604 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
femiwiki/docker-mediawiki#1497 ·
メンテナーはふだん 1 日以内に返信