Same filename in this branch
- 10 core/modules/forum/src/ForumUninstallValidator.php
- 10 core/modules/forum/src/ProxyClass/ForumUninstallValidator.php
Same filename and directory in other branches
- 8.9.x core/modules/forum/src/ForumUninstallValidator.php
- 9 core/modules/forum/src/ForumUninstallValidator.php
Namespace
Drupal\forum
File
core/modules/forum/src/ForumUninstallValidator.php
View source
<?php
namespace Drupal\forum;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\taxonomy\VocabularyInterface;
class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
protected $entityTypeManager;
protected $configFactory;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
$this->stringTranslation = $string_translation;
}
public function validate($module) {
$reasons = [];
if ($module == 'forum') {
if ($this
->hasForumNodes()) {
$reasons[] = $this
->t('To uninstall Forum, first delete all <em>Forum</em> content');
}
$vocabulary = $this
->getForumVocabulary();
if (!empty($vocabulary) && $this
->hasTermsForVocabulary($vocabulary)) {
if ($vocabulary
->access('view')) {
$reasons[] = $this
->t('To uninstall Forum, first delete all <a href=":url">%vocabulary</a> terms', [
'%vocabulary' => $vocabulary
->label(),
':url' => $vocabulary
->toUrl('overview-form')
->toString(),
]);
}
else {
$reasons[] = $this
->t('To uninstall Forum, first delete all %vocabulary terms', [
'%vocabulary' => $vocabulary
->label(),
]);
}
}
}
return $reasons;
}
protected function hasForumNodes() {
$nodes = $this->entityTypeManager
->getStorage('node')
->getQuery()
->condition('type', 'forum')
->accessCheck(FALSE)
->range(0, 1)
->execute();
return !empty($nodes);
}
protected function hasTermsForVocabulary(VocabularyInterface $vocabulary) {
$terms = $this->entityTypeManager
->getStorage('taxonomy_term')
->getQuery()
->condition('vid', $vocabulary
->id())
->accessCheck(FALSE)
->range(0, 1)
->execute();
return !empty($terms);
}
protected function getForumVocabulary() {
$vid = $this->configFactory
->get('forum.settings')
->get('vocabulary');
if (!empty($vid)) {
return $this->entityTypeManager
->getStorage('taxonomy_vocabulary')
->load($vid);
}
else {
return NULL;
}
}
}
Classes