class EntityUpdateManager in Entity Usage 8
Same name and namespace in other branches
- 8.2 src/EntityUpdateManager.php \Drupal\entity_usage\EntityUpdateManager
- 8.3 src/EntityUpdateManager.php \Drupal\entity_usage\EntityUpdateManager
Class EntityUpdateManager.
@package Drupal\entity_usage
Hierarchy
- class \Drupal\entity_usage\EntityUpdateManager
Expanded class hierarchy of EntityUpdateManager
1 string reference to 'EntityUpdateManager'
1 service uses EntityUpdateManager
File
- src/
EntityUpdateManager.php, line 12
Namespace
Drupal\entity_usageView source
class EntityUpdateManager {
/**
* The usage tracking service.
*
* @var \Drupal\entity_usage\EntityUsage $usage_service
*/
protected $usageService;
/**
* The PluginManager track service.
*
* @var \Drupal\entity_usage\EntityUsageTrackManager $TrackManager
*/
protected $trackManager;
/**
* EntityUpdateManager constructor.
*
* @param \Drupal\entity_usage\EntityUsage $usage_service
* The usage tracking service.
* @param \Drupal\entity_usage\EntityUsageTrackManager $track_manager
* The PluginManager track service.
*/
public function __construct(EntityUsage $usage_service, EntityUsageTrackManager $track_manager) {
$this->usageService = $usage_service;
$this->trackManager = $track_manager;
}
/**
* Track updates on creation of potential host entities.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity we are dealing with.
*/
public function trackUpdateOnCreation(ContentEntityInterface $entity) {
// Only act on content entities.
if (!$entity instanceof ContentEntityInterface) {
return;
}
// Call all plugins that want to track entity usages.
foreach ($this->trackManager
->getDefinitions() as $plugin_id => $plugin_definition) {
/** @var EntityUsageTrackInterface $instance */
$instance = $this->trackManager
->createInstance($plugin_id);
$instance
->trackOnEntityCreation($entity);
}
}
/**
* Track updates on deletion of potential host entities.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity we are dealing with.
*/
public function trackUpdateOnDeletion(ContentEntityInterface $entity) {
// Only act on content entities.
if (!$entity instanceof ContentEntityInterface) {
return;
}
// Call all plugins that want to track entity usages.
foreach ($this->trackManager
->getDefinitions() as $plugin_id => $plugin_definition) {
/** @var EntityUsageTrackInterface $instance */
$instance = $this->trackManager
->createInstance($plugin_id);
$instance
->trackOnEntityDeletion($entity);
}
// Now clean the possible usage of the entity that was deleted when target.
$this->usageService
->delete($entity
->id(), $entity
->getEntityTypeId());
}
/**
* Track updates on edit / update of potential host entities.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity we are dealing with.
*/
public function trackUpdateOnEdition(ContentEntityInterface $entity) {
// Only act on content entities.
if (!$entity instanceof ContentEntityInterface) {
return;
}
// Call all plugins that want to track entity usages.
foreach ($this->trackManager
->getDefinitions() as $plugin_id => $plugin_definition) {
/** @var EntityUsageTrackInterface $instance */
$instance = $this->trackManager
->createInstance($plugin_id);
$instance
->trackOnEntityUpdate($entity);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityUpdateManager:: |
protected | property | The PluginManager track service. | |
EntityUpdateManager:: |
protected | property | The usage tracking service. | |
EntityUpdateManager:: |
public | function | Track updates on creation of potential host entities. | |
EntityUpdateManager:: |
public | function | Track updates on deletion of potential host entities. | |
EntityUpdateManager:: |
public | function | Track updates on edit / update of potential host entities. | |
EntityUpdateManager:: |
public | function | EntityUpdateManager constructor. |