Guest User

Untitled

a guest
Jul 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. showdoctor.load_doctor_controller_load:
  2. path: 'doctor/{doctor_id}'
  3. defaults:
  4. _controller: 'DrupalshowdoctorControllerLoadDoctorController::load'
  5. _title: 'load'
  6. requirements:
  7. _permission: 'access content'
  8.  
  9. class LoadDoctorController extends ControllerBase
  10. {
  11. public function load($doctor_id)
  12. {
  13. $result = RestCurl::post("http://myrest_server.com", [
  14. 'filter' => ['doctor.id' => $doctor_id],
  15. ]);
  16.  
  17. $fullname = $result['data']->message->data[0]->firstName;
  18. $fullname = $fullname . ' ' . $result['data']->message->data[0]->lastName;
  19. // Fetch doctor node with EFQ
  20. $query = Drupal::entityQuery('node');
  21. $query->condition('type', 'doctor');
  22. $query->condition('field_doctor_id', $doctor_id);
  23. $nids = $query->execute();
  24. if (!$nids) {
  25. $node = Node::create([
  26. 'type' => 'doctor',
  27. 'title' => $fullname,
  28. 'uid' => 1,
  29. ]);
  30. $node->set('field_doctor_id', $doctor_id);
  31. $node->save();
  32. $element = array(
  33. '#markup' => $node,
  34. );
  35. return $element;
  36. } else {
  37. $element = array(
  38. '#markup' => $node,
  39. );
  40. return $element;
  41. }
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment