How to migrate "textfield" to "telephone" (D7 to D10)

Created on 25 August 2024, 4 months ago
Updated 5 September 2024, 4 months ago

Problem/Motivation

I feal totally puzzled.

I have two fields in six content types and user on D7 that are build with standard "textfield" and contain phone numbers. I'd like to convert them to "telephone" type during D7 to D10 migration to use the new field formater for tel fields. Is there any easy way or has someone done this and may share code with me, please? I guess it can only be easy as it is text to text migration, but I do not get the hand around any code example around.

I have already read more than 20 documentation pages about migrations and I do not understand what I really need to do as they are full of special cases. Any help is highly appreciated.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

💬 Support request
Status

Active

Version

10.3

Component
Migration 

Last updated about 13 hours ago

Created by

🇩🇪Germany marc.bau

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @marc.bau
  • 🇮🇳India mdsohaib4242

    A more efficient approach would be to proceed with the migration from Drupal 7 to Drupal 10 as it is. Once the migration is complete, you can create a new "telephone" field in Drupal 10 and then transfer the data from the old field to the new one.

    For example, if your content type is "article," and your existing field is `field_old` while the new telephone field is `field_new`, you can use a script to copy all the data.

    $batch_size = 50;
    $nids = \Drupal::entityQuery('node')
      ->condition('type', 'article')
      ->execute();
    $nids_batches = array_chunk($nids, $batch_size);
    
    foreach ($nids_batches as $batch) {
      $article_nodes = \Drupal\node\Entity\Node::loadMultiple($batch);
    
      foreach ($article_nodes as $article_node) {
        if (!$article_node->get('field_old')->isEmpty()) {
          $article_node->set('field_new', $article_node->get('field_old')->getValue());
    
          $article_node->save();
        }
      }
    }
    
    
Production build 0.71.5 2024