function PathFieldItemList::delete

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. 8.9.x core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::delete()
  3. 10 core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::delete()

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.