You are here

protected function ContentLanguageSettings::processSettings in Acquia Content Hub 8.2

Applies appropriate schema for content entities that support multilingual.

This process appears to normally happen through the form submission process which is unreliable for entity imports, so we've replicated the basic functionality until core solves this problem.

Parameters

\Drupal\language\ContentLanguageSettingsInterface $settings: The ContentLanguageSettings entity.

2 calls to ContentLanguageSettings::processSettings()
ContentLanguageSettings::onImportNew in src/EventSubscriber/EntityImport/ContentLanguageSettings.php
Handles the importing of new ContentLanguageSettings entities.
ContentLanguageSettings::onImportUpdate in src/EventSubscriber/EntityImport/ContentLanguageSettings.php
Handles the importing of existing ContentLanguageSettings entities.

File

src/EventSubscriber/EntityImport/ContentLanguageSettings.php, line 83

Class

ContentLanguageSettings
Handles ContentLanguageSetting entity saves to apply related schema.

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityImport

Code

protected function processSettings(ContentLanguageSettingsInterface $settings) {

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
  $field_manager = \Drupal::service('entity_field.manager');

  /** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $schema_repository */
  $schema_repository = \Drupal::service('entity.last_installed_schema.repository');
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type_id = $settings
    ->getTargetEntityTypeId();
  $field_manager
    ->useCaches(FALSE);
  $storage_definitions = $field_manager
    ->getFieldStorageDefinitions($entity_type_id);
  $field_manager
    ->useCaches(TRUE);
  $installed_storage_definitions = $schema_repository
    ->getLastInstalledFieldStorageDefinitions($entity_type_id);
  foreach (array_diff_key($storage_definitions, $installed_storage_definitions) as $storage_definition) {

    /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition */
    if ($storage_definition
      ->getProvider() == 'content_translation') {
      $definition_update_manager
        ->installFieldStorageDefinition($storage_definition
        ->getName(), $entity_type_id, 'content_translation', $storage_definition);
    }
  }
}