Score:1

How can I copy a field to another field?

br flag

I have an Article content type for which I want to change the machine name of its fields. I created new fields with a different machine name.

How do I copy the old fields to the new fields?

Score:1
de flag

You can run this, in hook_update_N():

$storage = \Drupal::entityTypeManager()->getStorage('node');
// Load all the nodes IDs for nodes that don't have the new value set.
$nids = $storage->getQuery()
  // Load all nodes for which the new field has no value.
  ->notExists('new_field_name')
  ->execute();

// Loop through the nodes.
foreach ($nids as $nid) {
  // Load the current node.
  $node = $storage->load($nid);
  // Set the new field name to the old field name and save.
  $node->set('new_field_name', $node->get('old_field_name')->value)
    ->save();
}
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.