geofieldProximityEntityURL.inc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Contains geofieldProximityEntityURL.
  5. */
  6. class geofieldProximityEntityURL extends geofieldProximityBase implements geofieldProximityPluginInterface {
  7. public function option_definition(&$options, $views_plugin) {
  8. $options['geofield_proximity_entity_url_entity_type'] = array(
  9. 'default' => 'node',
  10. );
  11. $options['geofield_proximity_entity_url_field'] = array(
  12. 'default' => '',
  13. );
  14. $options['geofield_proximity_entity_url_delta'] = array(
  15. 'default' => 0,
  16. );
  17. }
  18. public function options_form(&$form, &$form_state, $views_plugin) {
  19. $entities = entity_get_info();
  20. $entity_options = array();
  21. foreach ($entities as $key => $entity) {
  22. $entity_options[$key] = $entity['label'];
  23. }
  24. $form['geofield_proximity_entity_url_entity_type'] = array(
  25. '#type' => 'select',
  26. '#title' => t('Entity Type'),
  27. '#default_value' => $views_plugin->options['geofield_proximity_entity_url_entity_type'],
  28. '#options' => $entity_options,
  29. '#dependency' => array(
  30. 'edit-options-source' => array('entity_from_url'),
  31. ),
  32. );
  33. $geofields = _geofield_get_geofield_fields();
  34. $field_options = array();
  35. foreach ($geofields as $key => $field) {
  36. $field_options[$key] = $key;
  37. }
  38. $form['geofield_proximity_entity_url_field'] = array(
  39. '#type' => 'select',
  40. '#title' => t('Source Field'),
  41. '#default_value' => $views_plugin->options['geofield_proximity_entity_url_field'],
  42. '#options' => $field_options,
  43. '#dependency' => array(
  44. 'edit-options-source' => array('entity_from_url'),
  45. ),
  46. );
  47. }
  48. public function getSourceValue($views_plugin) {
  49. $entity_type = $views_plugin->options['geofield_proximity_entity_url_entity_type'];
  50. $geofield_name = $views_plugin->options['geofield_proximity_entity_url_field'];
  51. $delta = $views_plugin->options['geofield_proximity_entity_url_delta'];
  52. $entity = menu_get_object($entity_type);
  53. if (isset($entity) && !empty($geofield_name)) {
  54. $field_data = field_get_items($entity_type, $entity, $geofield_name);
  55. if ($field_data != FALSE) {
  56. return array(
  57. 'latitude' => $field_data[$delta]['lat'],
  58. 'longitude' => $field_data[$delta]['lon'],
  59. );
  60. }
  61. }
  62. return FALSE;
  63. }
  64. }