Created
October 15, 2020 15:45
-
-
Save alex-bukach/aaa09f4cd73962e7d8d4591da8f0d651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Move Drupal 8 fields from one entity type to another. | |
// @see https://www.drupal.org/project/field_tools/issues/1349646#comment-13329737 | |
$poc_fields = [ | |
'field_adl_iadl', | |
'field_asa_referrals', | |
'field_authorized_for_lifeline_se', | |
'field_backup_plans', | |
'field_care_coordination_sec_12', | |
'field_care_coordination_sec_19', | |
'field_cf_poc', | |
'field_choice_letter', | |
'field_dhhs_roi', | |
'field_dhhs_roi_attachments', | |
'field_eligibility_letter', | |
'field_hbc_copayment', | |
'field_hbc_waiver_of_copayment', | |
'field_health_welfare', | |
'field_job_description', | |
'field_medical_records_roi', | |
'field_orc_hours_budget', | |
'field_payroll_data_sheet', | |
'field_person_center_plan', | |
'field_plan_of_service_agreement', | |
'field_pre_post_test', | |
'field_privacy_policy_consent', | |
'field_risk_mitigation', | |
'field_rn_assessor_notes', | |
'field_rn_referral', | |
'field_skills_training_hours_budg', | |
'field_wsp_referral', | |
]; | |
foreach ($poc_fields as $poc_field) { | |
$field_storage_source = \Drupal\field\Entity\FieldStorageConfig::loadByName('paragraph', $poc_field); | |
$field_source = \Drupal\field\Entity\FieldConfig::loadByName('paragraph', 'plan_of_care_year', $poc_field); | |
// Field storage: | |
$field_name = $field_storage_source->getName(); | |
$field_type = $field_storage_source->getType(); | |
$field_storage_settings = $field_storage_source->getSettings(); | |
// Field: | |
$field_label = $field_source->getLabel(); | |
$field_settings = $field_source->getSettings(); | |
\Drupal\field\Entity\FieldStorageConfig::create([ | |
'field_name' => $field_name, | |
'type' => $field_type, | |
'entity_type' => 'node', | |
'settings' => $field_storage_settings, | |
]) | |
->save(); | |
\Drupal\field\Entity\FieldConfig::create([ | |
'field_name' => $field_name, | |
'entity_type' => 'node', | |
'bundle' => 'enrollment', | |
'label' => $field_label, | |
'settings' => $field_settings, | |
]) | |
->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment