任務是刪除滿足某些指定條件的實體。我該怎麼做 ?在某些條件下刪除實體Drupal 8
$current_user = \Drupal::currentUser()->id();
$storage = \Drupal::entityManager()->getStorage('context');
$query = $storage->getQuery()->condition('user_id', $current_user);
$query = $storage->getQuery()->delete();
$query->condition('user_id', $current_user);
$query->condition('key_text', $key);
$query->execute();
但代碼返回:致命錯誤:調用未定義的方法Drupal的\核心\ CONFIG \實體\查詢\查詢::刪除()
儘管這段代碼是受歡迎的,並且可能會提供一些幫助,但如果它包含* how *和* why *的解釋](// meta.stackexchange.com/q/114762)這解決了這個問題。請記住,你正在爲將來的讀者回答這個問題,而不僅僅是現在問的人!請編輯您的答案以添加解釋,並指出適用的限制和假設。 –