You are here

function webform_update_8108 in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.install.update.inc \webform_update_8108()

Issue #2944515: Report proper dependencies of a webform block.

File

includes/webform.install.update.inc, line 2004
Archived Webform update hooks.

Code

function webform_update_8108() {

  /** @var \Drupal\block\Entity\Block $block */
  foreach (\Drupal::entityTypeManager()
    ->getStorage('block')
    ->loadMultiple() as $block) {
    if ($block
      ->getPluginId() === 'webform_block') {
      $webform_id = $block
        ->getPlugin()
        ->getConfiguration()['webform_id'];
      if (\Drupal::entityTypeManager()
        ->getStorage('webform')
        ->load($webform_id)) {
        $block
          ->save();
      }
      else {

        // The webform does not exist. There is no point to keep this block.
        $block
          ->delete();
      }
    }
  }
}