You are here

public static function BlocksController::deleteDeletedBlocks in Structure Sync 8

Same name and namespace in other branches
  1. 2.x src/Controller/BlocksController.php \Drupal\structure_sync\Controller\BlocksController::deleteDeletedBlocks()

Function to delete the custom blocks that should be removed in this import.

1 call to BlocksController::deleteDeletedBlocks()
BlocksController::importBlocks in src/Controller/BlocksController.php
Function to import custom blocks.

File

src/Controller/BlocksController.php, line 231

Class

BlocksController
Controller for syncing custom blocks.

Namespace

Drupal\structure_sync\Controller

Code

public static function deleteDeletedBlocks($blocks, &$context) {
  $uuidsInConfig = [];
  foreach ($blocks as $block) {
    $uuidsInConfig[] = $block['uuid'];
  }
  if (!empty($uuidsInConfig)) {
    $query = StructureSyncHelper::getEntityQuery('block_content');
    $query
      ->condition('uuid', $uuidsInConfig, 'NOT IN');
    $ids = $query
      ->execute();
    $controller = StructureSyncHelper::getEntityManager()
      ->getStorage('block_content');
    $entities = $controller
      ->loadMultiple($ids);
    $controller
      ->delete($entities);
  }
  if (array_key_exists('drush', $context) && $context['drush'] === TRUE) {
    drush_log('Deleted custom blocks that were not in config', 'ok');
  }
  StructureSyncHelper::logMessage('Deleted custom blocks that were not in config');
}