block_post_update_fix_negate_in_conditions

block_post_update_fix_negate_in_conditions()

Fix invalid 'negate' values in block visibility conditions.

File

core/modules/block/block.post_update.php, line 89
Post update functions for Block.

Code

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();
    }
  }
}
doc_Drupal
2016-10-29 08:47:54
Comments
Leave a Comment

Please login to continue.