function PathFieldItemList::delete

Overrides FieldItemList::delete

File

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

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.
  $entity = $this->getEntity();
  $langcode_list = [
    $entity->language()
      ->getId(),
  ];
  // The default translation may also have language-neutral aliases.
  if ($entity->isDefaultTranslation()) {
    $langcode_list[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
  }
  $path_alias_storage = \Drupal::entityTypeManager()->getStorage('path_alias');
  $entities = $path_alias_storage->loadByProperties([
    'path' => '/' . $entity->toUrl()
      ->getInternalPath(),
    'langcode' => $langcode_list,
  ]);
  $path_alias_storage->delete($entities);
}

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