Commit 6489345f authored by catch's avatar catch

Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do not...

Issue #2811519 by tim.plunkett, dbourrion, cilefen, futurmat: Blocks do not appear after being placed with the Rules module enabled (or other missing schemata for Condition plugins)
parent 547ace58
......@@ -84,3 +84,36 @@ function block_post_update_disabled_region_update() {
/**
* @} End of "addtogroup updates-8.0.0-beta".
*/
/**
* @addtogroup updates-8.2.x
* @{
*/
/**
* Fix invalid 'negate' values in block visibility conditions.
*/
function block_post_update_fix_negate_in_conditions() {
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
/** @var \Drupal\block\BlockInterface[] $blocks */
$blocks = $block_storage->loadMultiple();
foreach ($blocks as $block) {
$block_needs_saving = FALSE;
// Check each visibility condition for an invalid negate value, and fix it.
foreach ($block->getVisibilityConditions() as $condition_id => $condition) {
$configuration = $condition->getConfiguration();
if (array_key_exists('negate', $configuration) && !is_bool($configuration['negate'])) {
$configuration['negate'] = (bool) $configuration['negate'];
$condition->setConfiguration($configuration);
$block_needs_saving = TRUE;
}
}
if ($block_needs_saving) {
$block->save();
}
}
}
/**
* @} End of "addtogroup updates-8.2.x".
*/
......@@ -323,7 +323,7 @@ protected function validateVisibility(array $form, FormStateInterface $form_stat
// However, certain form elements may return it as 0/1. Cast here to
// ensure the data is in the expected type.
if (array_key_exists('negate', $values)) {
$values['negate'] = (bool) $values['negate'];
$form_state->setValue(['visibility', $condition_id, 'negate'], (bool) $values['negate']);
}
// Allow the condition to validate the form.
......
<?php
namespace Drupal\block\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for block with conditions missing context.
*
* @see https://www.drupal.org/node/2811519
*
* @group Update
*/
class BlockConditionMissingSchemaUpdateTest extends UpdatePathTestBase {
/**
* This test does not have a failed update but the configuration has missing
* schema so can not do the full post update testing offered by
* UpdatePathTestBase.
*
* @var bool
*
* @see \Drupal\system\Tests\Update\UpdatePathTestBase::runUpdates()
*/
protected $checkFailedUpdates = FALSE;
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../tests/fixtures/update/drupal-8.block-test-enabled-missing-schema.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
$this->drupalGet('<front>');
// If the block is fixed by block_post_update_fix_negate_in_conditions()
// then it will be visible.
$this->assertText('Test missing schema on conditions');
}
}
uuid: 1a6c0f14-78dc-4ede-bade-b8ce83881453
langcode: en
status: true
dependencies:
module:
- block_test
- system
theme:
- bartik
id: missing_schema
theme: bartik
region: sidebar_first
weight: 0
provider: null
plugin: system_branding_block
settings:
id: system_branding_block
label: 'Test missing schema on conditions'
provider: system
label_display: visible
use_site_logo: true
use_site_name: true
use_site_slogan: true
visibility:
missing_schema:
id: missing_schema
negate: 0
context_mapping: { }
<?php
/**
* @file
* Partial database to mimic the installation of the block_test module.
*/
use Drupal\Core\Database\Database;
use Symfony\Component\Yaml\Yaml;
$connection = Database::getConnection();
// Set the schema version.
$connection->insert('key_value')
->fields([
'collection' => 'system.schema',
'name' => 'block_test',
'value' => 'i:8000;',
])
->execute();
// Update core.extension.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['block_test'] = 8000;
$connection->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
// Install the block configuration.
$config = file_get_contents(__DIR__ . '/block.block.missing_schema.yml');
$config = Yaml::parse($config);
$connection->insert('config')
->fields(['data', 'name', 'collection'])
->values([
'name' => 'block.block.missing_schema',
'data' => serialize($config),
'collection' => '',
])
->execute();
<?php
namespace Drupal\block_test\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
/**
* Provides a 'missing_schema' condition.
*
* @Condition(
* id = "missing_schema",
* label = @Translation("Missing schema"),
* )
*/
class MissingSchema extends ConditionPluginBase {
/**
* {@inheritdoc}
*/
public function evaluate() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function summary() {
return 'Summary';
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment