Skip to content

feat: add configurable unique rule modifier for section edit action#95

Merged
ManukMinasyan merged 1 commit into3.xfrom
feat/section-unique-rule-modifier
Feb 27, 2026
Merged

feat: add configurable unique rule modifier for section edit action#95
ManukMinasyan merged 1 commit into3.xfrom
feat/section-unique-rule-modifier

Conversation

@ManukMinasyan
Copy link
Collaborator

Allow applications to register a custom unique rule modifier via resolveUniqueRuleModifierUsing() to scope section name/code uniqueness validation during edit, preventing false "already taken" errors.

Allow applications to register a custom unique rule modifier via
resolveUniqueRuleModifierUsing() to scope section name/code uniqueness
validation during edit, preventing false "already taken" errors.
Copilot AI review requested due to automatic review settings February 27, 2026 19:13
@ManukMinasyan ManukMinasyan merged commit bd0c9a2 into 3.x Feb 27, 2026
2 of 3 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an application-configurable hook to modify the section edit action’s uniqueness validation rule, enabling custom scoping to avoid false “already taken” errors when editing sections.

Changes:

  • Introduces a static resolver (resolveUniqueRuleModifierUsing) to provide a per-section unique-rule modifier.
  • Applies the resolved modifier to SectionForm before building the edit action schema.
  • Refactors edit action schema construction to reuse a configured SectionForm instance.

Comment on lines +78 to +86
$sectionForm = SectionForm::entityType($this->entityType);

if (self::$uniqueRuleModifierResolver) {
$modifier = (self::$uniqueRuleModifierResolver)($this->section);

if ($modifier) {
$sectionForm->modifyUniqueRuleUsing($modifier);
}
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior is introduced here (a resolver that can alter the unique-rule used by the edit action), but there’s no test asserting it’s applied and affects validation outcomes. Please add a feature test around callAction('edit', ...) that registers resolveUniqueRuleModifierUsing() and verifies the resulting unique validation is scoped as intended (and that the resolver is cleared/reset between tests).

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +84
if ($modifier) {
$sectionForm->modifyUniqueRuleUsing($modifier);
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the resolver is user-provided, it can accidentally return a non-Closure value; in that case this will currently fail with a TypeError when calling modifyUniqueRuleUsing(). Consider validating the return value explicitly (e.g. apply only when it’s an instance of Closure, and throw a clearer InvalidArgumentException when a non-null, non-closure value is returned) to make misconfiguration easier to diagnose.

Suggested change
if ($modifier) {
$sectionForm->modifyUniqueRuleUsing($modifier);
if ($modifier instanceof Closure) {
$sectionForm->modifyUniqueRuleUsing($modifier);
} elseif ($modifier !== null) {
throw new \InvalidArgumentException(sprintf(
'The unique rule modifier resolver for [%s] must return a Closure or null, [%s] returned.',
static::class,
get_debug_type($modifier),
));

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +33
/** @var ?Closure(CustomFieldSection): ?Closure */
private static ?Closure $uniqueRuleModifierResolver = null;
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHPDoc for $uniqueRuleModifierResolver is too vague (and doesn’t match the closure-shape style used elsewhere, e.g. SectionForm::$modifyUniqueRuleUsing). Since this resolver is expected to return the callback passed into SectionForm::modifyUniqueRuleUsing(), the doc should spell out the nested closure signature (e.g. Closure(CustomFieldSection): (Closure(Unique, Get): Unique)|null) so consumers and static analysis know what to return.

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +42
public static function resolveUniqueRuleModifierUsing(?Closure $callback): void
{
self::$uniqueRuleModifierResolver = $callback;
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing this configuration hook on a Livewire component (ManageCustomFieldSection::resolveUniqueRuleModifierUsing()) makes the package API harder to discover and ties configuration to UI implementation details. Consider moving this registration to a central configuration surface (e.g. CustomFields or SectionForm) and having the Livewire action read it from there, so apps don’t need to reference a Livewire class just to adjust validation scope.

Copilot uses AI. Check for mistakes.
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.

2 participants