Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#15,513 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #15541 di @eastagiletracker — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
laravel, php
Ambito
backend

Direzione di ricerca

Parti da src/Fieldtypes/Group.php e confronta Group::extraRules() con i metodi equivalenti in src/Fieldtypes/Grid.php e src/Fieldtypes/Replicator.php, che già usano il trait AddsEntryValidationReplacements e chiamano addEntryValidationReplacements(). Aggiungi il trait e la chiamata a Group, quindi rispecchia la copertura dei test esistente di Grid/Replicator per la sostituzione di {id}/{collection}/{site} (cerca i test che fanno riferimento a entry validation replacements) per confermare che le regole basate su classi annidate vengano risolte anziché diventare null. Nota: un PR collegato (#15541) è stato chiuso senza merge — controlla la sua discussione prima di iniziare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
PHP
Stelle
4.9k
Fork
647
Merge medio
1g 9h
PR unite (30g)
102

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di statamic/cms

Tutte le issue di statamic/cms

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.