Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Fix SQL custom field default value validation #39355

Conversation

joomdonation
Copy link
Contributor

Pull Request for Issue #29565.

Summary of Changes

Some of our List base custom fields like SQL uses OptionsRule https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Form/Rule/OptionsRule.php to validate it's data. This rule requires a valid $form object to validate data in case the options for the field not defined in XML but dynamic defined (for example, from database) via getOptions method of the field type

This PR changes logic of checkDefaultValue method in FieldModel class to handle default value properly for these kind of custom fields. It is a bug fix, but I decided to implement the change to 4.3 branch so that we have more time for reviewing and testing the change. I also includes the change from PR #39354 (for 4.2 branch) so to avoid merge conflict.

Ping @laoneo for checking this change.

Testing Instructions

  1. Use Joomla 4.3
  2. Follow instructions at SQL field default value validation always fails #29565 , confirm the issue
  3. Apply patch, confirm the issue fixed.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

$element = simplexml_import_dom($node->firstChild);
$value = $data['default_value'];

if ($data['type'] === 'checkboxes') {
Copy link
Member

Choose a reason for hiding this comment

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

Is there no other way, instead of hardcoding here a reference to the checkbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open for suggestion but I don't see any better way here. It's ugly, but it fixes the issue and allow us to specify multiple default values for this checkboxes custom field type

Copy link
Member

Choose a reason for hiding this comment

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

I would use an event here, so the plugin itself can do the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you help with that? I haven't understood our new event system good enough yet, so I am not confident that I could implement it in right way.

@Hackwar Hackwar added the Small A PR which only has a small change label Feb 26, 2023
@Hackwar Hackwar added the bug label Apr 7, 2023
@HLeithner HLeithner changed the base branch from 4.3-dev to 4.4-dev September 30, 2023 22:44
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 4.4-dev.

@joomdonation joomdonation deleted the fix_sql_custom_field_default_value branch February 24, 2024 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug PR-4.4-dev Small A PR which only has a small change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants