Problem/Motivation

In order to know whether a Condition plugin has been configured, the submitted values are compared to its default state. If they match exactly, it is consider to be not configured, and is removed.
The Form API will submit Boolean values as 1 or 0 instead of TRUE or FALSE, which breaks this comparison.
Before #2537732: PluginFormInterface must have access to the complete $form_state (introduce SubFormState for embedded forms), there was a specific hack in BlockForm for the 'negate' property that all conditions share. This hack was not updated in that patch, and ceased to function.
Therefore, all condition plugins without valid schema would not be correctly removed, and would be consulted during access checks for blocks.
This caused any blocks configured (while a module like Rules was enabled) to stop displaying.

Furthermore, condition plugins with valid schemas were 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()

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

Proposed resolution

Move some of the config system into a trait, and use it directly.
The hastily named \Drupal\Core\Config\ConfigValueCaster is now used by both \Drupal\Core\Config\StorableConfigBase and \Drupal\Core\Condition\ConditionPluginCollection.

Remaining tasks

N/A

User interface changes

Blocks will now work regardless of whether condition plugins have a valid schema or not.

API changes

N/A

Data model changes

N/A

Original report

Hi
I'm putting some blocks in my structure, but nothing comes out.
Please find joined a snapshot of the Structure/Blocks zone, showing the blocks I'd like to add ;
and a snapshot of the rendered page, with... nothing appearing.

Any idea ?

Comments

dbourrion created an issue. See original summary.

cilefen’s picture

Title: No blocks ? » Blocks do not appear after being placed

Hi @dbourrion:

What is the enabled theme?

Are there any errors in Drupal's log or the PHP log?

alexd73’s picture

I have the some problem.
syslog is empty. Old blocks (located before) displayed.

veleno’s picture

I have the same problem.
I'm not able anymore to see new placed blocks in the layout, I can move the existing ones but cannot see any new added one. I've just upgraded to Drupal 8.2 then I've enabled the new "Place Blocks" module and later uninstalled it. I do not know if it is related to "Place Blocks" or not.
I also noted that, after adding a new block in admin/structure/block and saving the block config, I'm redirected to admin/structure/block/library/mytheme and not back to admin/structure/block.
I have the same result when using Bartik as theme and I have no error in the drupal log and in the system php log.

Regards
Oto Tortorella

dbourrion’s picture

Same as previous

cilefen’s picture

Priority: Normal » Major

This qualifies as major.

futurmat’s picture

I have the same issue here.

cilefen’s picture

Priority: Major » Critical

@catch and I discussed this. More information is needed from the affected sites but we think this should be critical based on reports.

futurmat’s picture

Happy to provide further information and ready to test solutions!

alexd73’s picture

@cilefen it seems to me odd that in the appearance of a lot of weird themes http://i.imgur.com/U1QKDeg.png
and in visable section very match new tabs http://i.imgur.com/OjHT9Ke.png

I can give you access to the site and ssh. If need, my email alexd73@gmail.com

xjm’s picture

Does this only occur after installing the Place Block module? If the module is uninstalled, can the blocks be placed again?

futurmat’s picture

I just have the two themes that came with the installation. However, I also have a long list underneath "Visibility". Since this is the first time I used Drupal 8 I thought that's the way it's supposed to be?!
Only local images are allowed.
I don't have the Place Block module installed.

cilefen’s picture

@alexd73 It seems you have $settings['extension_discovery_scan_tests'] = TRUE.

cilefen’s picture

Re #13: Those extended conditions are from the Rules module.

cilefen’s picture

Does every affected site have Rules enabled?

cilefen’s picture

With Rules installed, placed blocks do not appear, and pre-Rules placed blocks disappear after being saved with Rules enabled, as they take on Rules visibility conditions.

futurmat’s picture

In fact - Rules seemed to cause this problem. I uninstalled rules and can place blocks now!

giuliovale’s picture

The problem is still present also with Place Block Module uninstalled

cilefen’s picture

This problem does not exist in 8.1.10 but does in 8.2.0.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Debugging this.

tim.plunkett’s picture

veleno’s picture

Rules creates the problem, I confirm that uninstalling it solves.

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new700 bytes

In \Drupal\Core\Condition\ConditionPluginCollection::getConfiguration(), we compare the $default_config to the $instance_config.
This was failing for all rules conditions, for two reasons.

One, rules provides NO config schema for it's plugins. Core does for all its own, see node.schema.yml line 108, which corresponds to \Drupal\node\Plugin\Condition\NodeType.

Two, \Drupal\block\BlockForm::validateVisibility() used to massage the 'negate' value the ensure the type is correct. This code was not updated in the SubFormState issue above.

This still needs tests, and Rules should add schema, but this fix works and is correct.

tim.plunkett’s picture

StatusFileSize
new1.94 KB

Here's an update path.

catch’s picture

Status: Needs review » Needs work

This looks reasonable, but yeah let's add test coverage.

Also discussed this issue with @xjm and @alexpott and we think it's worth putting out an early 8.2.1 for, probably early next week.

tim.plunkett’s picture

This is only solving a single special case. Any other Boolean config values in conditions will cause this same problem.
Working on a general solution.

xjm’s picture

Title: Blocks do not appear after being placed » Blocks do not appear after being placed with the Rules module enabled
xjm’s picture

Title: Blocks do not appear after being placed with the Rules module enabled » Blocks do not appear after being placed with the Rules module enabled (or other missing schemata for Condition plugins)
tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new2.19 KB
new18.36 KB

This is an entirely new approach, so no interdiff.

tim.plunkett’s picture

StatusFileSize
new20.55 KB

Last PASS patch didn't actually include the test in the FAIL patch.

tim.plunkett’s picture

Issue summary: View changes
Issue tags: -Needs tests

The last submitted patch, 31: 2811519-block-31-FAIL.patch, failed testing.

tim.plunkett’s picture

Wow, the specific browser test I added is completely unnecessary. Adding a schema-less condition plugin to block_test.module broke a ton of tests!

alexpott’s picture

I'm not entirely suer about using sub pieces of schema in the way introduced in this patch.

+++ b/core/lib/Drupal/Core/Config/ConfigValueCaster.php
@@ -9,117 +9,47 @@
+  protected function initSchemaWrapper($data) {
+    $typed_config_manager = $this->typedConfigManager();
+    $definition = $typed_config_manager->getDefinition($this->getName());

If we pass name into here then we can get rid of the abstract getName() which will remove the oddity of getName on the condition plugin returning a config name.

tim.plunkett’s picture

StatusFileSize
new850 bytes
new1.51 KB

Going back to the quick-fix in #25, plus tests. The config stuff was a bit heavy-handed.

alexpott’s picture

@tim.plunkett - we can open a follow up to discuss further fall out and a better fix. Maybe the config changes are the right way but I wouldn't want to rush that. Or maybe a better way will occur to us.

The last submitted patch, 37: 2811519-block-37-FAIL.patch, failed testing.

tim.plunkett’s picture

The test failures in #2815829: Adding or editing a block through the UI saves the entity twice imply that a bigger fix is needed anyway, we can work on it there.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

The fix in #37 will resolve the immediate issues and #40 outlines the existing followup. I think we are good to go here.

  • catch committed ed3202c on 8.3.x
    Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do...

  • catch committed da907ca on 8.2.x
    Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

catch’s picture

Status: Fixed » Needs work

That patch didn't include the upgrade path from #26.

  • alexpott committed 547ace5 on 8.3.x
    Revert "Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat:...

  • alexpott committed 0b11616 on 8.2.x
    Revert "Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat:...
alexpott’s picture

After discussion with @catch, @cilefen and @xjm we decided to revert this and wait for upgrade path tests.

alexpott’s picture

Also sorry everyone for the premature rtbc in #41 I should have spotted the missing upgrade path.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new4.86 KB
new4.99 KB
new7.03 KB

The patch adds the missing update path and provides a simple test that adds a block with missing schema and the incorrect config prior to running updates and runs them.

dbourrion’s picture

Hi
Thanks for all that stuff
Disabling Rules fixed the prob for me for the moment.
D.

The last submitted patch, 50: 2811519-50.test-only.patch, failed testing.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

The fix may be mine, but the update path tests are all @alexpott, so I'm RTBCing the patch.

  • catch committed 6489345 on 8.3.x
    Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do...

  • catch committed ea275ec on 8.2.x
    Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the update path test.

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

Status: Fixed » Closed (fixed)

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

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
websiteworkspace’s picture

As of D8.6.4, this problem still exists.

I installed and enabled the rules module.

I changed a block configuration to specify block display on additional pages.

That block no longer appeared anywhere and no amount of attempting to adjust the block settings fixed the problem that the block would not appear anyway. Changing the block settings to appear on every page did not fix the problem.

--

Attempting to uninstall the D8 rules module then demands that all blocks touched by the rules module be deleted by the D8 rules module uninstall. Thus, uninstalling the D8 rules module then creates catastrophic configuration and content loss for the affected D8 site.

--

This is a critical problem.
It seems that the D8 rules module is not only unusable, the D8 rules module causes catastrophic configuration and content loss.

--

p.s. this critical problem required a rollback to the D8 site's previous day's automated daily backup (a very bad scenario)

jonathan1055’s picture

Hi websiteworkspace,
If you do have this problem, you may need to create a new issue in the Rules issue queue, and reference it back to this one, because not many people will be seeing this issue now that it it closed.
Jonathan