geofield_test.module 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function geofield_test_menu() {
  6. $items = array();
  7. $items['geofield-latlon-element'] = array(
  8. 'title' => 'Geofield native Lat/Lon element test',
  9. 'page callback' => 'drupal_get_form',
  10. 'page arguments' => array('geofield_test_formapi_element_form'),
  11. 'access arguments' => array('access content'),
  12. 'type' => MENU_NORMAL_ITEM,
  13. );
  14. $items['geofield-latlon-element/submit'] = array(
  15. 'title' => 'Geofield native element test - Submit page',
  16. 'page callback' => 'geofield_test_latlon_submit_page',
  17. 'access arguments' => array('access content'),
  18. 'type' => MENU_CALLBACK,
  19. );
  20. $items['geofield-bounds-element'] = array(
  21. 'title' => 'Geofield native Bounds element test',
  22. 'page callback' => 'drupal_get_form',
  23. 'page arguments' => array('geofield_test_formapi_bounds_form'),
  24. 'access arguments' => array('access content'),
  25. 'type' => MENU_NORMAL_ITEM,
  26. );
  27. $items['geofield-bounds-element/submit'] = array(
  28. 'title' => 'Geofield bounds element test - Submit page',
  29. 'page callback' => 'geofield_test_bounds_submit_page',
  30. 'access arguments' => array('access content'),
  31. 'type' => MENU_CALLBACK,
  32. );
  33. $items['geofield-proximity-element'] = array(
  34. 'title' => 'Geofield proximity element test',
  35. 'page callback' => 'drupal_get_form',
  36. 'page arguments' => array('geofield_test_formapi_proximity_form'),
  37. 'access arguments' => array('access content'),
  38. 'type' => MENU_NORMAL_ITEM,
  39. );
  40. return $items;
  41. }
  42. /**
  43. * Form API callback for geofield native formapi field.
  44. */
  45. function geofield_test_formapi_element_form() {
  46. variable_del('geofield_test_simple_latlon');
  47. variable_del('geofield_test_verbose_latlon');
  48. $form = array();
  49. $form['geofield_latlon_simple'] = array(
  50. '#type' => 'geofield_latlon',
  51. );
  52. $form['geofield_latlon_verbose'] = array(
  53. '#type' => 'geofield_latlon',
  54. '#title' => t('Verbose Lat/Lon'),
  55. '#description' => t('This form element defines a variety of different elements.'),
  56. '#default_value' => array(
  57. 'lat' => '41',
  58. 'lon' => '-86',
  59. ),
  60. '#geolocation' => TRUE,
  61. );
  62. $form['submit'] = array(
  63. '#type' => 'submit',
  64. '#value' => t('Save'),
  65. );
  66. return $form;
  67. }
  68. function geofield_test_formapi_element_form_submit($form, &$form_state) {
  69. variable_set('geofield_test_simple_latlon', $form_state['values']['geofield_latlon_simple']);
  70. variable_set('geofield_test_verbose_latlon', $form_state['values']['geofield_latlon_verbose']);
  71. drupal_goto('geofield-latlon-element/submit');
  72. }
  73. function geofield_test_latlon_submit_page() {
  74. $content = array();
  75. $simple = variable_get('geofield_test_simple_latlon', FALSE);
  76. $verbose = variable_get('geofield_test_verbose_latlon', FALSE);
  77. if ($simple) {
  78. $content['header'] = array('#markup' => '<h2>Results</h2>');
  79. $content['simple'] = array('#markup' => '<p>Simple - Lat: ' . $simple['lat'] . ' Lon: ' . $simple['lon'] . '</p>');
  80. $content['verbose'] = array('#markup' => '<p>Verbose - Lat: ' . $verbose['lat'] . ' Lon: ' . $verbose['lon'] . '</p>');
  81. }
  82. return $content;
  83. }
  84. /**
  85. * Form API callback for geofield native formapi field.
  86. */
  87. function geofield_test_formapi_bounds_form() {
  88. variable_del('geofield_test_simple_bounds');
  89. $form = array();
  90. $form['geofield_bounds_simple'] = array(
  91. '#type' => 'geofield_bounds',
  92. );
  93. $form['submit'] = array(
  94. '#type' => 'submit',
  95. '#value' => t('Save'),
  96. );
  97. return $form;
  98. }
  99. function geofield_test_formapi_bounds_form_submit($form, &$form_state) {
  100. variable_set('geofield_test_simple_bounds', $form_state['values']['geofield_bounds_simple']);
  101. drupal_goto('geofield-bounds-element/submit');
  102. }
  103. function geofield_test_bounds_submit_page() {
  104. $content = array();
  105. $simple = variable_get('geofield_test_simple_bounds', FALSE);
  106. if ($simple) {
  107. $content['header'] = array('#markup' => '<h2>Results</h2>');
  108. $content['simple'] = array('#markup' => '<p>Simple - Top: ' . $simple['top'] . ' Right: ' . $simple['right'] . ' Bottom: ' . $simple['bottom'] . ' Left: ' . $simple['left'] . '</p>');
  109. }
  110. return $content;
  111. }
  112. /**
  113. * Form API callback for proximity formapi element.
  114. */
  115. function geofield_test_formapi_proximity_form() {
  116. $form = array();
  117. $form['geofield_proximity'] = array(
  118. '#type' => 'geofield_proximity',
  119. '#title' => t('Proximity field - Simple'),
  120. '#description' => t('Test description'),
  121. '#default_value' => array(
  122. 'origin' => '',
  123. 'distance' => 0,
  124. 'unit' => GEOFIELD_KILOMETERS,
  125. ),
  126. );
  127. $form['geofield_proximity_range'] = array(
  128. '#type' => 'geofield_proximity',
  129. '#title' => t('Proximity field - Range'),
  130. '#description' => t('Test description'),
  131. '#default_value' => array(
  132. 'origin' => '',
  133. 'distance' => 0,
  134. 'unit' => GEOFIELD_KILOMETERS,
  135. ),
  136. '#geofield_range' => TRUE,
  137. );
  138. $form['submit'] = array(
  139. '#type' => 'submit',
  140. '#value' => t('Save'),
  141. );
  142. return $form;
  143. }