bookOutlineStorage = $book_outline_storage; $this->entityQuery = $query_factory->get('node'); $this->stringTranslation = $string_translation; } /** * {@inheritdoc} */ public function validate($module) { $reasons = []; if ($module == 'book') { if ($this->hasBookOutlines()) { $reasons[] = $this->t('To uninstall Book, delete all content that is part of a book'); } else { // The book node type is provided by the Book module. Prevent uninstall // if there are any nodes of that type. if ($this->hasBookNodes()) { $reasons[] = $this->t('To uninstall Book, delete all content that has the Book content type'); } } } return $reasons; } /** * Checks if there are any books in an outline. * * @return bool * TRUE if there are books, FALSE if not. */ protected function hasBookOutlines() { return $this->bookOutlineStorage->hasBooks(); } /** * Determines if there is any book nodes or not. * * @return bool * TRUE if there are book nodes, FALSE otherwise. */ protected function hasBookNodes() { $nodes = $this->entityQuery ->condition('type', 'book') ->accessCheck(FALSE) ->range(0, 1) ->execute(); return !empty($nodes); } }