You are here

function multiversion_update_8109 in Multiversion 8

Enable redirect entity type.

File

./multiversion.install, line 592

Code

function multiversion_update_8109() {
  if (\Drupal::moduleHandler()
    ->moduleExists('redirect')) {
    $entity_type_id = 'redirect';
    $update_manager = \Drupal::entityDefinitionUpdateManager();

    // Get the current redirect entity type definition, ensure the storage schema
    // class is set.
    $entity_type = $update_manager
      ->getEntityType($entity_type_id)
      ->setHandlerClass('storage_schema', RedirectStorageSchema::class);

    // Update entity type.
    $update_manager
      ->updateEntityType($entity_type);
    if (\Drupal::moduleHandler()
      ->moduleExists('redirect')) {
      $multiversion_settings = \Drupal::configFactory()
        ->getEditable('multiversion.settings');
      $supported_entity_types = $multiversion_settings
        ->get('supported_entity_types') ?: [];

      // Check if entity type should be added to the supported entity types list.
      if (!in_array($entity_type_id, $supported_entity_types)) {
        $supported_entity_types[] = $entity_type_id;

        // Add new entity types to the supported entity types list.
        $multiversion_settings
          ->set('supported_entity_types', $supported_entity_types)
          ->save();
      }
      $manager = \Drupal::entityTypeManager();
      $entity_types = [];
      $entity_type = $manager
        ->getStorage($entity_type_id)
        ->getEntityType();
      if ($entity_type instanceof ContentEntityTypeInterface) {
        $entity_types[$entity_type_id] = $entity_type;
      }
    }

    // Enable new entity type.
    if (!empty($entity_types)) {
      \Drupal::service('multiversion.manager')
        ->enableEntityTypes($entity_types);
    }
  }
}