这篇文章上次修改于 367 天前,可能其部分内容已经发生变化,如有疑问可询问作者。 > drupal的批量删除api,entity_delete_multiple,已经被删除 1. 请使用新的api ``` bash $bookManager = \Drupal::service('book.manager'); $entity = \Drupal::entityTypeManager()->getStorage('node'); $context['message'] = t('Deleting %title', ['%title' => $queue->title]); $query = $entity->getQuery(); //todo 如果pid不为空,按pid查,否则,按title查 $id = $query ->condition('type', 'book') ->condition('title', $queue->title) ->execute(); // Load multiples or single item load($id) https://drupalbook.org/drupal/9111-working-entity-fields-programmatically $books = $entity->loadMultiple($id); if (!empty($books)) { foreach ($books as $book) { if ($bookManager->loadBookLink($book->id())) { $bookManager->deleteFromBook($book->id()); } } $entity->delete($books); } ```
没有评论