You are here

public function EntityBlockItem::delete in Entityblock 8

Defines custom delete behavior for field values.

This method is called during the process of deleting an entity, just before values are deleted from storage.

Overrides FieldItemBase::delete

File

src/Plugin/Field/FieldType/EntityBlockItem.php, line 98
Contains \Drupal\entityblock\Plugin\Field\FieldType\EntityBlockItem.

Class

EntityBlockItem
Plugin implementation of the 'EntityBlock' field type.

Namespace

Drupal\entityblock\Plugin\Field\FieldType

Code

public function delete() {
  $ids = \Drupal::entityQuery('block')
    ->condition('plugin', 'entityblock_block:' . $this
    ->getFieldDefinition()
    ->getFieldStorageDefinition()
    ->uuid() . '|' . $this
    ->getEntity()
    ->uuid(), 'STARTS_WITH')
    ->execute();
  $block_storage = \Drupal::entityTypeManager()
    ->getStorage('block');
  $blocks = $block_storage
    ->loadMultiple($ids);
  $block_storage
    ->delete($blocks);
}