diff --git a/CHANGELOG.md b/CHANGELOG.md index 7074cfead4e..9f6b32af834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Fixed a “Invalid URL” JavaScript error in the control panel. ([#19041](https://github.com/craftcms/cms/pull/19041)) - Fixed a bug where queue job progress labels weren’t getting translated. - Fixed a bug where the control panel sidebar and Queue Manager were showing completed jobs. +- Relocated `CraftCms\Cms\Element\Validation\Events\ValidationRulesResolving` to `CraftCms\Cms\Validation\Events\ValidationRulesResolving` to reflect its broader applicability to components and rulesets. +- Relaxed the allowed types in the `ValidationRulesResolving` event to include any implementation `ValidatesWithRuleset` or a `Illuminate\Http\Request` object. +- Renamed `CraftCms\Cms\Validation\Events\ValidationRulesResolving::$component` to `$subject` +- Added `CraftCms\Cms\Validation\Events\ValidationRulesResolving::$ruleset` ## 6.0.0-alpha.6 - 2026-06-03 diff --git a/packages/craftcms-cp/src/styles/shared/tokens.css b/packages/craftcms-cp/src/styles/shared/tokens.css index 4634cb988b2..8338d1a75dd 100644 --- a/packages/craftcms-cp/src/styles/shared/tokens.css +++ b/packages/craftcms-cp/src/styles/shared/tokens.css @@ -107,7 +107,7 @@ --c-status-disabled-text: var(--color-slate-600); --c-status-disabled-border: var(--color-slate-600); -/** + /** Static colors */ --c-color-static-success-fill: var(--color-static-emerald-200); diff --git a/src/Element/Validation/Events/ValidationRulesResolving.php b/src/Validation/Events/ValidationRulesResolving.php similarity index 54% rename from src/Element/Validation/Events/ValidationRulesResolving.php rename to src/Validation/Events/ValidationRulesResolving.php index 5ee825e02e0..afba746ae41 100644 --- a/src/Element/Validation/Events/ValidationRulesResolving.php +++ b/src/Validation/Events/ValidationRulesResolving.php @@ -2,26 +2,50 @@ declare(strict_types=1); -namespace CraftCms\Cms\Element\Validation\Events; +namespace CraftCms\Cms\Validation\Events; -use CraftCms\Cms\Validation\Contracts\Validatable; +use CraftCms\Cms\Validation\Ruleset; +use CraftCms\RulesetValidation\Contracts\ValidatesWithRuleset; use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Http\Request; /** - * Event dispatched when an element's validation rules are being defined. + * Event dispatched when validation rules are being defined. * - * Plugins can listen to this event to add custom validation rules. + * Plugins can listen to this event to add custom validation rules: + * + * ```php + * use CraftCms\Cms\Validation\Events\ValidationRulesResolving; + * use CraftCms\Cms\Entry\Elements\Entry; + * + * Event::listen(function (ValidationRulesResolving $event) { + * // Suppose we’re only interested in entries: + * if (! $event->subject instanceof Entry) { + * return; + * } + * + * // Ignore nested entries: + * if ($event->subject->ownerId !== null) { + * return; + * } + * + * // Enforce short slugs: + * $event->addRule('slug', 'max:40'); + * }); + * ``` */ class ValidationRulesResolving { use Dispatchable; /** - * @param Validatable $component The component being validated + * @param ValidatesWithRuleset|Request $subject The object being validated + * @param Ruleset $ruleset The ruleset that produced the attached {@see $rules} * @param array> $rules The current validation rules */ public function __construct( - public readonly Validatable $component, + public readonly ValidatesWithRuleset|Request $subject, + public readonly Ruleset $ruleset, public array $rules, ) {} diff --git a/src/Validation/Ruleset.php b/src/Validation/Ruleset.php index 32aaf85f5d2..544c0e1958b 100644 --- a/src/Validation/Ruleset.php +++ b/src/Validation/Ruleset.php @@ -4,8 +4,8 @@ namespace CraftCms\Cms\Validation; -use CraftCms\Cms\Element\Validation\Events\ValidationRulesResolving; use CraftCms\Cms\Validation\Contracts\Validatable; +use CraftCms\Cms\Validation\Events\ValidationRulesResolving; use Illuminate\Validation\Validator; use Override; @@ -33,7 +33,7 @@ protected function validationRules(): array { $rules = parent::validationRules(); - event($event = new ValidationRulesResolving($this->subject, $rules)); + event($event = new ValidationRulesResolving($this->resolveSubject(), $this, $rules)); return $event->rules; }