Guest User

Untitled

a guest
Nov 14th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2.  
  3. $findings = [
  4. [
  5. 'location' => '204',
  6. 'finding_type' => 132,
  7. 'comments' => 'Needs cord cover',
  8. ],
  9. [
  10. 'location' => '104',
  11. 'finding_type' => 132,
  12. 'comments' => 'Needs cord cover',
  13. ],
  14. [
  15. 'location' => '103',
  16. 'finding_type' => 132,
  17. 'comments' => 'Needs cord cover',
  18. ],
  19. [
  20. 'location' => '302',
  21. 'finding_type' => 132,
  22. 'comments' => 'Needs cord cover',
  23. ],
  24. [
  25. 'location' => '202',
  26. 'finding_type' => 132,
  27. 'comments' => 'Needs cord cover',
  28. ],
  29. [
  30. 'location' => '304',
  31. 'finding_type' => 132,
  32. 'comments' => 'Needs cord cover',
  33. ],
  34. [
  35. 'location' => 'Portable 3',
  36. 'finding_type' => 132,
  37. 'comments' => 'Needs cord cover',
  38. ],
  39. [
  40. 'location' => 'Portable 2',
  41. 'finding_type' => 132,
  42. 'comments' => 'Needs cord cover',
  43. ],
  44. [
  45. 'location' => '907',
  46. 'finding_type' => 132,
  47. 'comments' => 'Needs cord cover',
  48. ],
  49. ];
  50.  
  51. $walkthrough = \Drupal\node\Entity\Node::create([
  52. 'type' => 'walkthrough',
  53. 'field_date' => '2018-11-13',
  54. 'field_facility' => ['target_id' => 17],
  55. 'field_roster' => "",
  56. 'status' => 0,
  57. ]);
  58.  
  59. $walkthrough->save();
  60.  
  61. foreach ($findings as $finding) {
  62. $type = \Drupal\taxonomy\Entity\Term::load($finding['finding_type']);
  63.  
  64. $node = \Drupal\node\Entity\Node::create([
  65. 'type' => 'finding',
  66. 'field_walkthrough' => ['target_id' => $walkthrough->id()],
  67. 'field_location' => $finding['location'],
  68. 'field_finding_type' => ['target_id' => $type->id()],
  69. 'field_comments' => $finding['comments'],
  70. 'field_assigned_to' => $type->field_default_assignment->value ?: NULL,
  71. ]);
  72.  
  73. $node->save();
  74. }
Add Comment
Please, Sign In to add comment