Skip to content

Commit

Permalink
Merge pull request #2 from osu-wams/DRUP8-1092
Browse files Browse the repository at this point in the history
Add update hook to remove the Wide Card Block type.
  • Loading branch information
emerham authored Aug 19, 2022
2 parents c7292bf + fa1897c commit d34e99e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions osu_block_types.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ use Drupal\Core\Config\FileStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
* Remove OSU Wide Card block type.
*/
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();
}
}
}
}
// 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.');
}

/**
* Update OSU Card Display.
*/
Expand Down

0 comments on commit d34e99e

Please sign in to comment.