ContentTranslationUpdatesManager.php in Drupal 8
File
core/modules/content_translation/src/ContentTranslationUpdatesManager.php
View source
<?php
namespace Drupal\content_translation;
use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@trigger_error('\\Drupal\\content_translation\\ContentTranslationUpdatesManager is scheduled for removal in Drupal 9.0.0. Definitions are updated automatically now so no replacement is needed. See https://www.drupal.org/node/2973222.', E_USER_DEPRECATED);
class ContentTranslationUpdatesManager {
protected $entityFieldManager;
protected $entityLastInstalledSchemaRepository;
protected $entityTypeManager;
protected $updateManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityDefinitionUpdateManagerInterface $update_manager, EntityFieldManagerInterface $entity_field_manager = NULL, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->updateManager = $update_manager;
if (!$entity_field_manager) {
$entity_field_manager = \Drupal::service('entity_field.manager');
}
$this->entityFieldManager = $entity_field_manager;
if (!$entity_last_installed_schema_repository) {
$entity_last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
}
$this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
}
public function updateDefinitions(array $entity_types) {
if ($this->updateManager
->needsUpdates()) {
foreach ($entity_types as $entity_type_id => $entity_type) {
$storage_definitions = $this->entityFieldManager
->getFieldStorageDefinitions($entity_type_id);
$installed_storage_definitions = $this->entityLastInstalledSchemaRepository
->getLastInstalledFieldStorageDefinitions($entity_type_id);
foreach (array_diff_key($storage_definitions, $installed_storage_definitions) as $storage_definition) {
if ($storage_definition
->getProvider() == 'content_translation') {
$this->updateManager
->installFieldStorageDefinition($storage_definition
->getName(), $entity_type_id, 'content_translation', $storage_definition);
}
}
}
}
}
}