You are here

public function PathFieldItemList::delete in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::delete()
  2. 10 core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::delete()

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 FieldItemList::delete

File

core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php, line 57

Class

PathFieldItemList
Represents a configurable entity path field.

Namespace

Drupal\path\Plugin\Field\FieldType

Code

public function delete() {

  // Delete all aliases associated with this entity in the current language.
  $entity = $this
    ->getEntity();
  $path_alias_storage = \Drupal::entityTypeManager()
    ->getStorage('path_alias');
  $entities = $path_alias_storage
    ->loadByProperties([
    'path' => '/' . $entity
      ->toUrl()
      ->getInternalPath(),
    'langcode' => $entity
      ->language()
      ->getId(),
  ]);
  $path_alias_storage
    ->delete($entities);
}