Problem/Motivation

Both BlockForm::submitForm() and EntityForm::save() save the entity.

Condition plugins with valid schemas are only correctly handled because BlockForm *saved the block twice*. Once explicitly in ::submitForm(), once in its parent ::save().
The flow was:

  1. condition is checked for default state, failed due to type mismatch
  2. saved in submitForm()
  3. values casted to correct type by Config::castValue
  4. condition is checked for default state, correctly removed
  5. saved in save()

Proposed resolution

In order to properly compare the values without saving the entity twice, the values must be cast before being compared.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-2815829

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
FileSize
736 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 2815829-block-2.patch, failed testing.

tim.plunkett’s picture

Issue summary: View changes
tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
18.57 KB

Reposting the proposed fix from the other issue.

tim.plunkett’s picture

Reroll.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

godotislate’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
tim.plunkett’s picture

Version: 9.3.x-dev » 9.4.x-dev
Assigned: Unassigned » tim.plunkett

Rerolling this

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll

Switched to MR.

paulocs’s picture

godotislate’s picture

Status: Needs review » Needs work
tim.plunkett’s picture

Status: Needs work » Needs review

Great review @godotislate, thanks! I think the MR is much cleaner now.

And thanks for verifying @paulocs, that's a relief.

godotislate’s picture

Status: Needs review » Needs work

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

godotislate’s picture

Status: Needs work » Needs review

@tim.plunkett Sorry, missed your last comment from months ago.

I retried with both Drupal 9.4.8 and 10.1.x-dev with Moderation Dashboard 2.1.1, and I don't see the error anymore. All other functionality seems to work correctly.

Setting back to Needs Review to kick off CI.

ETA. Looks like there'll need to be a new MR against 10.1.

godotislate’s picture

Created new MR against 10.1 and tests passed. I'd say RTBC, but I guess it's technically my MR now.

bryanmanalo’s picture

https://git.drupalcode.org/project/drupal/-/merge_requests/1456.patch I tried using this patch for 9.4.7 (and 9.4.8), but patch does not complete.

Attaching a screenshot.

Maybe I am misunderstanding how to use the new way to get patches? https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Testing https://git.drupalcode.org/project/drupal/-/merge_requests/2905

Checked that the tests fail without the fix and passes with the full MR.

Didn't see any merge conflicts (didn't rebase)

xjm’s picture

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Left a few nitpicks and some questions on the MR. Thanks!

@smustgrave, how did you check that the test fails without the fix? If you did so locally, I'd paste your shell output to receive credit for that testing.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

godotislate’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Saving credit for @xjm for the review of MR 2905

Left some small changes on MR

Think a last step would be a CR for the new trait and it's usage.

godotislate’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Removing tag.

Taking a look at the CR and it reads very well. Listing the methods is perfect I think.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

This is a surprising solution for a couple of reasons. We're adding a validateConfiguration() method to LazyPluginCollection and saying it needs to be called before saving but this is not really a validation. What should this method do if it gets invalid configuration? We're also adding a ConditionPluginCollection::getName() method that just seems odd. It's only there to provide a name for config schema to work. This change doesn't feel right but I've not really got an idea on how to fix this properly. The code in \Drupal\Core\Condition\ConditionPluginCollection::getConfiguration() that removes configuration if it matches the default doesn't really work the way the configuration system expects.

I guess I think the fix needs to happen on the form level as the incorrectly typed values are coming from there. This fix is currently implemented for all config entities in ConfigEntityBase::preSave().

There are two ways this makes things inconsistent:
1. Condition plugin config data is casted in ConfigEntityBase::preSave() rather than in \Drupal\Core\Config\Entity\ConfigEntityStorage::doSave()
2. Config plugins casting ignores the affects of trusting configuration data.

As said I'm not sure what the correct thing to do here is.

godotislate’s picture

@alexpott
Updated the MR to do the casting at the form level (in submitConfigurationForm in ConditionPluginBase). Is this along this lines of what you were looking for?

godotislate’s picture

Updated MR to address reviews and rebased for merge conflict.

flitt1’s picture

Rewrite for Drupal 9.5.x.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thank you @flitt1 but hiding #42, don't believe this will be backported and don't want it to be reviewed over the MR.

Believe feedback has been addressed. Only one i'm unsure is the point @xjm pointed out about the scheme change.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Discussed this issue with @bircher and both of us have concerns about leveraging config schema in the plugin system to cast a plugin's configuration. This is because there's no guarantee that the a plugin config is going to be saved in the configuration system.

We were both wondering whether or not we could change the comparison from === to == in \Drupal\Core\Condition\ConditionPluginCollection::getConfiguration() since we couldn't work out a situation where loose comparison would be a problem. Especially due to changes in PHP 8 type juggling.

alexpott credited bircher.

alexpott’s picture

godotislate’s picture

@alexpott
Updated MR and reverted everything that had to do with casting.

Also, made this change and added tests.

We were both wondering whether or not we could change the comparison from === to == in \Drupal\Core\Condition\ConditionPluginCollection::getConfiguration() since we couldn't work out a situation where loose comparison would be a problem. Especially due to changes in PHP 8 type juggling.

alexpott’s picture

@godotislate the changes look beautiful. It's lovely that this has become much simpler and the comment you added to ConditionPluginManager::getConfiguration() is fantastic. Eagerly waiting for this to be RTBC :)

alexpott’s picture

Adding contribution credit.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Went through the MR again and Thumbs upped threads I believe are resolved. Only 2 I didn't were the ones from @xjm.

Thanks for adding the comment if ($default_config == $instance_config) without reading the comment in #44 it was super clear why that decision was made.

LGTM

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

One piece of feedback. Also there are 17 other unresolved threads that *were* resolved. @godotislate as the MR author, you can mark those as resolved.

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community

@alexpott pushed back on explicit test coverage for double-saving, but the last commit fixes things nicely enough

alexpott’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 24b8523c4a7 to 11.x and 1ea22bd454b to 10.2.x and 78b55658d95 to 10.1.x. Thanks!

  • alexpott committed 24b8523c on 11.x
    Issue #2815829 by godotislate, tim.plunkett, smustgrave, alexpott, xjm,...

  • alexpott committed 1ea22bd4 on 10.2.x
    Issue #2815829 by godotislate, tim.plunkett, smustgrave, alexpott, xjm,...

  • alexpott committed 78b55658 on 10.1.x
    Issue #2815829 by godotislate, tim.plunkett, smustgrave, alexpott, xjm,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.