Skip to content

Instantly share code, notes, and snippets.

@andyg5000
Created November 15, 2018 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyg5000/c6b5610ea2a9165a839ffce9ca441212 to your computer and use it in GitHub Desktop.
Save andyg5000/c6b5610ea2a9165a839ffce9ca441212 to your computer and use it in GitHub Desktop.
<?php
$pids = [3,15,19,23,25,28,30,31,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,91,93,95,97,99,101];
foreach ($pids as $pid) {
$profile = \Drupal\profile\Entity\Profile::load($pid);
$uid = $profile->get('uid')->getValue()[0]['target_id'];
/** @var \Drupal\profile\Entity\ProfileInterface $main_profile */
$main_profile = \Drupal::entityTypeManager()->getStorage('profile')->loadByProperties(['uid' => $uid, 'type' => 'main_profile']);
$main_profile = reset($main_profile);
$name = $main_profile->get('field_first_name')->getValue()[0]['value'];
$last = $main_profile->get('field_last_name')->getValue()[0]['value'];
$node = \Drupal\node\Entity\Node::create([
'type' => 'member_bio',
'title' => $name . ' ' . $last,
]);
$node->set('field_bio', $profile->get('field_bio')->getValue());
if (!$profile->get('field_photo')->isEmpty()) {
$node->set('field_headshot', $profile->get('field_photo')->getValue());
}
if (!$profile->get('field_image_people_rollover')->isEmpty()) {
$node->set('field_image_people_rollover', $profile->get('field_image_people_rollover')->getValue());
}
if (!$profile->get('field_related_links')->isEmpty()) {
$node->set('field_relevant_links', $profile->get('field_related_links')->getValue());
}
$node->save();
$uid = $profile->get('uid')->getValue()[0]['target_id'];
$user = \Drupal\user\Entity\User::load($uid);
$user->set('field_member_bio', [$node]);
$user->save();
$profile->delete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment