2017-08-08 4 views
0

私は、インストール時にコンテンツタイプを作成するカスタムモジュールを持っています。そのコンテンツタイプを使用してコンテンツを作成した場合、そのコンテンツはモジュールのアンインストール時に削除されません。Drupal 8のモジュールアンインストールでコンテンツを削除する

モジュールのアンインストール時に、そのコンテンツタイプから作成されたすべてのコンテンツを削除するにはどうすればよいですか?

hook_uninstallでモジュール設定を削除しても効果がありません。

ありがとうございました!

答えて

0

mymodule.installファイルにhook_uninstallを実装する必要があります。このフックで

、次のコードを使用して、すべてのコンテンツを削除することができます:あなたはまた、entity_delete_multipleを使用することができますが、この機能は廃止され

/** 
* Implements hook_uninstall(). 
*/ 
function mymodule_uninstall() { 
    // Load services. 
    $queryFactory = \Drupal::service('entity.query') 
    $nodeStorage = \Drupal::entityManager()->getStorage('node'); 

    // Query all entity. 
    $query = $queryFactory->get('node') 
    ->condition('type', 'article'); // <-- Change the type here for yours. 
    $nids = $query->execute(); 

    // Delete entities. 
    if (!empty($nids)) { 
    $entities = $nodeStorage->loadMultiple($nids); 
    $nodeStorage->delete($entities); 
    } 
} 

を。 https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_delete_multiple/8.2.x


は、それはあなたがあなたの問題を解決するのに役立つことを願っています。

関連する問題