ViewUnpublishedInstallHelper.php in view_unpublished 8
File
src/ViewUnpublishedInstallHelper.php
View source
<?php
namespace Drupal\view_unpublished;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class ViewUnpublishedInstallHelper {
protected $configFactory;
protected $configStorage;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, CachedStorage $config_storage) {
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
$this->configStorage = $config_storage;
}
public function flagRebuild() {
$query = $this->entityTypeManager
->getStorage('node')
->getQuery();
$count_unpublished = (int) $query
->condition('status', FALSE)
->count()
->execute();
if ($count_unpublished > 0) {
node_access_needs_rebuild(TRUE);
}
}
public function removeDependency() {
$view_names = $this->configStorage
->listAll('views.view');
foreach ($view_names as $name) {
$dependencies = $this->configFactory
->get($name)
->get('dependencies.module');
if (!empty($dependencies) && array_key_exists('view_unpublished', array_flip($dependencies))) {
$dependencies = array_diff($dependencies, [
'view_unpublished',
]);
$this->configFactory
->getEditable($name)
->set('dependencies.module', $dependencies)
->save(TRUE);
}
}
}
}