class ViewUnpublishedInstallHelper in view_unpublished 8
Class ViewUnpublishedInstallHelper.
Hierarchy
- class \Drupal\view_unpublished\ViewUnpublishedInstallHelper
Expanded class hierarchy of ViewUnpublishedInstallHelper
1 string reference to 'ViewUnpublishedInstallHelper'
1 service uses ViewUnpublishedInstallHelper
File
- src/
ViewUnpublishedInstallHelper.php, line 12
Namespace
Drupal\view_unpublishedView source
class ViewUnpublishedInstallHelper {
/**
* Drupal\Core\Config\ConfigFactoryInterface definition.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Drupal\Core\Config\CachedStorage definition.
*
* @var \Drupal\Core\Config\CachedStorage
*/
protected $configStorage;
/**
* Drupal\Core\Entity\EntityTypeManagerInterface definition.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new ViewUnpublishedInstallHelper object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Core\Config\CachedStorage $config_storage
* The config storage service.
*/
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;
}
/**
* Helper that flags node_access to be rebuilt if unpublished nodes exist.
*/
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);
}
}
/**
* Remove the errant view_unpublished dependency from Views.
*/
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);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ViewUnpublishedInstallHelper:: |
protected | property | Drupal\Core\Config\ConfigFactoryInterface definition. | |
ViewUnpublishedInstallHelper:: |
protected | property | Drupal\Core\Config\CachedStorage definition. | |
ViewUnpublishedInstallHelper:: |
protected | property | Drupal\Core\Entity\EntityTypeManagerInterface definition. | |
ViewUnpublishedInstallHelper:: |
public | function | Helper that flags node_access to be rebuilt if unpublished nodes exist. | |
ViewUnpublishedInstallHelper:: |
public | function | Remove the errant view_unpublished dependency from Views. | |
ViewUnpublishedInstallHelper:: |
public | function | Constructs a new ViewUnpublishedInstallHelper object. |