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