By dpi on
Change record status:
Draft (View all draft change records)
Project:
Issue links:
Description:
\Drupal\block_content\BlockContentInterface::getInstances and \Drupal\block_content\Entity\BlockContent::getInstances declare an unnecessary dependency to Block.
The functionality of this method has been replaced by the functionality provided by \Drupal\block_content\BlockUsage\BlockContentBlockUsageInterface service. This service is only present when Block is installed.
Sample usage:
$blockContent = BlockContent::load(...);
/** @var \Drupal\block_content\BlockUsage\BlockContentBlockUsageInterface $blockContentBlockUsage */
$blockContentBlockUsage = \Drupal::service(BlockContentBlockUsageInterface::class);
$usage = $blockContentBlockUsage->getUsage($blockContent);
// Get the Block config using the $blockContent:
foreach ($usage as $block) {
$block->delete();
}
// Count the Block config using the $blockContent:
$affected = \count($usage);
Impacts:
Module developers