Skip to content

[6.x] Pass validation replacements when storing and updating terms - #15352

Open
duncanmcclean wants to merge 1 commit into
6.xfrom
term-validation-replacements
Open

[6.x] Pass validation replacements when storing and updating terms#15352
duncanmcclean wants to merge 1 commit into
6.xfrom
term-validation-replacements

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where a term blueprint using the new \Statamic\Rules\UniqueTermValue({taxonomy}, {id}, {site}) rule would always fail validation with "This value has already been taken" when saving an existing term.

Statamic already enforces slug uniqueness itself in TermsController, with the real taxonomy, term ID and site passed to the rule. However, you might want to use the rule yourself on a custom field, and the {taxonomy}, {id} and {site} placeholders are the documented way to do that. Those placeholders are swapped in via withReplacements(), which TermsController@update and store never called, so they all resolved to null. With no except value, the rule matched the term being edited and failed. EntriesController and UsersController already pass their own replacements.

This PR fixes it by having TermsController@update and store build their validators via $fields->validator()->withRules([...])->withReplacements([...]), passing id, taxonomy and site on update, and taxonomy and site on store.

Fixes #10078

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with saving when editing a term if the slug is unique

1 participant