-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Add validation replacements to replicator and grid field types (#…
…10255) Co-authored-by: Florian Brinkmann <[email protected]> Co-authored-by: Jason Varga <[email protected]>
- Loading branch information
1 parent
278ca3c
commit 313b2a6
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Statamic\Fieldtypes; | ||
|
||
use Statamic\Entries\Entry; | ||
use Statamic\Fields\Field; | ||
use Statamic\Fields\Validator; | ||
|
||
/** | ||
* TODO | ||
* This allows Grid/Replicator/Bard fields to add validation replacements. | ||
* It adds the same replacements that get added in EntriesController@update. | ||
* Ideally those would get passed down into the field automatically somehow, | ||
* so this can be considered a workaround until that happens. | ||
*/ | ||
trait AddsEntryValidationReplacements | ||
{ | ||
protected function addEntryValidationReplacements(Field $field, Validator $rules): Validator | ||
{ | ||
$fieldParent = $field->parent(); | ||
|
||
if (! $fieldParent instanceof Entry) { | ||
return $rules; | ||
} | ||
|
||
return $rules->withReplacements([ | ||
'id' => $fieldParent->id(), | ||
'collection' => $fieldParent->collection()->handle(), | ||
'site' => $fieldParent->locale(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters