Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Group fieldtype does not apply entry validation replacements ({id}, {collection}, {site})

未关闭
#15,513 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #15541 来自 @eastagiletracker —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
laravel, php
领域
backend

调研方向

从 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
  1. Fresh Statamic 6 site.
  2. 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})'
  1. Create an entry, set details.code to alpha, save.
  2. 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

statamic/cms 的其他 Issue

查看 statamic/cms 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。