Skip to content

Allow extending fields to share methods - #709

Merged
giuscris merged 1 commit into
2.xfrom
feature/fields-extend
Jun 21, 2025
Merged

Allow extending fields to share methods#709
giuscris merged 1 commit into
2.xfrom
feature/fields-extend

Conversation

@giuscris

Copy link
Copy Markdown
Member

No description provided.

@giuscris giuscris added this to the 2.0.0 milestone Jun 21, 2025
@giuscris
giuscris requested a review from Copilot June 21, 2025 22:23
@giuscris giuscris self-assigned this Jun 21, 2025
@giuscris giuscris added the enhancement New feature or request label Jun 21, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors field rendering and validation by replacing legacy property access (using get()) with dedicated method calls, and it introduces support for extending fields via shared methods. Key changes include switching method calls (e.g. options(), minLength(), etc.), updating error validation messages, and adding an extension‐merging mechanism in the FieldFactory.

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.

File Description
panel/views/fields/*.php Refactored field attribute access to use dedicated methods (e.g., options(), rows()).
formwork/fields/*.php & FieldFactory.php Updated field configuration to support method extensions through an “extend” key.
Comments suppressed due to low confidence (2)

formwork/src/Fields/FieldFactory.php:37

  • The extension merging loop does not currently guard against potential circular extension configurations. Adding a safeguard to detect and break out of circular dependencies would prevent potential infinite loops.
        while ($extend !== $type) {

throw new ValidationException(sprintf('The value of field "%s" of type "%s" must be less than or equal to %d', $field->name(), $field->type(), $field->get('max')));
}

if ($field->has('step') && ($value - $field->get('min', 0)) % $field->step() !== 0) {

Copilot AI Jun 21, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] For consistency with the new API, consider replacing $field->get('min', 0) with $field->min() if such a method exists, ensuring uniform usage throughout the code.

Suggested change
if ($field->has('step') && ($value - $field->get('min', 0)) % $field->step() !== 0) {
if ($field->has('step') && ($value - $field->min()) % $field->step() !== 0) {

Copilot uses AI. Check for mistakes.
@giuscris
giuscris merged commit 5f3fb3a into 2.x Jun 21, 2025
@giuscris
giuscris deleted the feature/fields-extend branch June 21, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants