From 4a881e7f9cf567590906af8fba683198f70ac994 Mon Sep 17 00:00:00 2001 From: Matthew Brabham Date: Mon, 22 Aug 2022 11:19:57 -0700 Subject: [PATCH] Update hook to check if the card type is null. --- osu_block_types.install | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/osu_block_types.install b/osu_block_types.install index 9f63171..9da6c0b 100644 --- a/osu_block_types.install +++ b/osu_block_types.install @@ -11,27 +11,29 @@ use Drupal\field\Entity\FieldStorageConfig; function osu_block_types_update_9003(&$sandbox) { // Load the block type config info. $osu_wide_card = BlockContentType::load('osu_wide_card'); - // Get the UUID of the block type so we can use it to delete any copy. - $osu_wide_card_uuid = $osu_wide_card->get('uuid'); - // Loop over all view displays and remove out custom block type. - $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); - foreach ($storage->loadMultiple() as $display) { - foreach ($display->getSections() as $section) { - foreach ($section->getComponents() as $component) { - // Custom views block - // $to_delete_plugin_id = 'views_block:my_news-block_1'; - // Custom block - // $to_delete_plugin_id = 'block_content:fb4ad848-0f3c-4296-a6ba-1a9da886335b'; - $to_delete_plugin_id = "block_content:${osu_wide_card_uuid}"; - if ($component->getPluginId() == $to_delete_plugin_id) { - $section->removeComponent($component->getUuid()); - $display->save(); + // Get the UUID of the block type, so we can use it to delete any copy. + if (!is_null($osu_wide_card)) { + $osu_wide_card_uuid = $osu_wide_card->get('uuid'); + // Loop over all view displays and remove out custom block type. + $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); + foreach ($storage->loadMultiple() as $display) { + foreach ($display->getSections() as $section) { + foreach ($section->getComponents() as $component) { + // Custom views block + // $to_delete_plugin_id = 'views_block:my_news-block_1'; + // Custom block + // $to_delete_plugin_id = 'block_content:fb4ad848-0f3c-4296-a6ba-1a9da886335b'; + $to_delete_plugin_id = "block_content:${osu_wide_card_uuid}"; + if ($component->getPluginId() == $to_delete_plugin_id) { + $section->removeComponent($component->getUuid()); + $display->save(); + } } } } + // Finally delete the block type. + $osu_wide_card->delete(); } - // Finally delete the block type. - $osu_wide_card->delete(); return t('OSU Wide Card block type removed, you might need to remove layout overrides manually.'); }