public function LayoutBuilderInlineBlockStubCleanup::onStubsCleanup in Acquia Content Hub 8.2
By default, we delete all stubs.
If LB inline block is created. LB inline block creation logic duplicates blocks and ACH ends up referencing the wrong revision. We delete the orphaned block.
Wrong reference is only a problem when the original entity has a recursive dependency (AcquiaContentHubEvents::IMPORT_FAILURE gets dispatched) and is being saved at the first time.
Parameters
\Drupal\acquia_contenthub\Event\CleanUpStubsEvent $event: The cleanup stubs $event.
See also
\Drupal\acquia_contenthub\EventSubscriber\CleanupStubs\DefaultStubCleanup
\Drupal\acquia_contenthub\StubTracker::cleanUp
File
- src/
EventSubscriber/ CleanupStubs/ LayoutBuilderInlineBlockStubCleanup.php, line 77
Class
- LayoutBuilderInlineBlockStubCleanup
- Cleans up LB block stubs after import.
Namespace
Drupal\acquia_contenthub\EventSubscriber\CleanupStubsCode
public function onStubsCleanup(CleanUpStubsEvent $event) {
if ($event
->getEntity()
->getEntityTypeId() !== 'block_content') {
return;
}
if (!$this->database
->schema()
->tableExists('inline_block_usage')) {
// If table not exist Layout Builder not installed.
return;
}
/** @var \Drupal\block_content\BlockContentInterface $block */
$block = $event
->getEntity();
$query = $this->database
->select('inline_block_usage', 't')
->fields('t', [
'block_content_id',
])
->condition('block_content_id', $block
->id());
$count = $query
->countQuery()
->execute()
->fetchField();
// If inline block reference exists, then stop propagation and delete
// duplicate.
if ($count) {
$this
->deleteDuplicatedBlockEntity($block);
$event
->stopPropagation();
}
}