You are here

function thunder_taxonomy_update_8003 in Thunder 8.2

Use core's term status field definition.

File

modules/thunder_taxonomy/thunder_taxonomy.install, line 69
Contains Thunder taxonomy install / uninstall hooks.

Code

function thunder_taxonomy_update_8003() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $definition_update_manager
    ->getEntityType('taxonomy_term');
  $entity_keys = $entity_type
    ->getKeys();
  $entity_keys['published'] = 'status';
  $entity_type
    ->set('entity_keys', $entity_keys);
  $definition_update_manager
    ->updateEntityType($entity_type);

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
  $field_manager = \Drupal::service('entity_field.manager');
  $status = $field_manager
    ->getBaseFieldDefinitions('taxonomy_term')['status'];
  $definition_update_manager
    ->updateFieldStorageDefinition($status
    ->getFieldStorageDefinition());

  // Copied this part from https://www.drupal.org/node/2985366. It's only for
  // safties sake, because Thunder user should never had the
  // content_translation_status field.
  $has_content_translation_status_field = $definition_update_manager
    ->getFieldStorageDefinition('content_translation_status', 'taxonomy_term');

  // Uninstall the 'content_translation_status' field if needed.
  if ($has_content_translation_status_field) {
    $content_translation_status = $definition_update_manager
      ->getFieldStorageDefinition('content_translation_status', 'taxonomy_term');
    $definition_update_manager
      ->uninstallFieldStorageDefinition($content_translation_status);
  }

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}