Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Implementation of hook_service()
  5. * Required by all server modules
  6. * Returns array defining all the methods available in the service
  7. */
  8. function drupalconnect_service() {
  9. return array(
  10. array(
  11. "#method" => "drupalconnect.get.pages",
  12. "#callback" => "drupalconnect_get_pages",
  13. "#return" => "array",
  14. "#help" => "Returns not a list of pages"
  15. ),
  16. );
  17. }
  18.  
  19. /**
  20. * Get the pages through our view
  21. */
  22. function drupalconnect_get_pages() {
  23. // get the view
  24. $view = views_get_view("drupalconnect");
  25.  
  26. // execute it
  27. $view->execute();
  28.  
  29. // create an array to store our result in
  30. $result = array();
  31.  
  32. // loop through the view result
  33. foreach ($view->result as $row) {
  34. // each row contains the node id
  35. // use the drupal helper function to load the full object
  36. $node = node_load($row->nid);
  37.  
  38. // now this is why I wanted to do it myself,
  39. // now we have the node, we can filter all the data
  40. // we want and leave behind the rest
  41. $clean_node = new stdClass();
  42.  
  43. $clean_node->title = $node->title;
  44. $clean_node->body = $node->body;
  45.  
  46. // store our clean, lightweight node
  47. array_push($result, $clean_node);
  48. }
  49.  
  50. // return the result (the clean one)
  51. return $result;
  52. }
Add Comment
Please, Sign In to add comment