There is already a hook_proximity_views_handlers present.
I added a 'module' and a 'path' argument to the proximity handler definition.
This way a module can define plugins by implementing hook_proximity_views_handlers

Attached you can find a patch to make this possible and a small module that defines a custom proximity plugin.
With the module you can choose a taxonomy library with a geofield and use the terms of this library as a select option.
This is handy when you want to limit the users location options.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bneil’s picture

Status: Active » Needs review
RdeBoer’s picture

Great patch and great little module!

The patch is simple and would further improve Geofield's already great architecture.

See the discussion at https://drupal.org/comment/8528069#comment-8528069

Rik

mglaman’s picture

Status: Needs review » Needs work

I don't have a chance to reroll patch at the moment, but you're calling $plugins:

module_load_include('inc', $plugins[$plugin]['module'], $plugins[$plugin]['path']. $handlers[$plugin]['class']);

when it should be $handlers, I believe

module_load_include('inc', $handlers[$plugin]['module'], $handlers[$plugin]['path']. $handlers[$plugin]['class']);

RdeBoer’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.33 KB

Agree with mglaman in #3. Typo. Here's a new patch.

EDIT try the patch from #12.

Stijn.blomme's idea for the original patch is simple, elegant, low-risk, yet hugely important in allowing other modules to add proximity plugins to Geofield, without Geofield having to know about the modules.
So it avoids Geofield maintainers having to put ugly if (module_exists('someonesmodule')) { ... .} every time someone has convinced them of a useful plugin.

For starters, his idea allows me to redo https://drupal.org/comment/8528069 inside ip_geoloc (where it belongs), rather than making it as part of Geofield.

Stijn.blomme's patch makes for a much cleaner and more maintainable Geofield architecture.

Please Brandonian, apply the patch from #12, so we can all build on it in our own modules.

Rik

RdeBoer’s picture

RdeBoer’s picture

Sorry typo in my patch. New patch attached.

RdeBoer’s picture

This patch adds some robustness to the previous one, avoiding WSODs in case typos were made in the plugin name or file spec.
This patch, if chosen, needs to be applied instead of the one in the previous comment, NOT in addition too.

vlooivlerke’s picture

FileSize
28.43 KB

Hi, Rik

     $form['radius_of_earth'] = array(
diff --git a/views/handlers/geofield_handler_filter.inc b/views/handlers/geofield_handler_filter.inc
index 980071f..19020b0 100644
--- a/views/handlers/geofield_handler_filter.inc
+++ b/views/handlers/geofield_handler_filter.inc
@@ -107,8 +107,10 @@ class geofield_handler_filter extends views_handler_filter_numeric {
     );
     $proximityHandlers = module_invoke_all('proximity_views_handlers');
     foreach ($proximityHandlers as $key => $handler) {
-      $proximityPlugin = new $handler['class']();
-      $proximityPlugin->option_definition($options, $this);
+      if (class_exists($handler['class'])) {
+        $proximityPlugin = new $handler['class']();
+        $proximityPlugin->option_definition($options, $this);
+      }
     }
     return $options;
   }

when applying patch against 7.x-2.x-dev the top part does not apply.
giving me the following ajax error when trying to add the proximity filter

ajax error

I manually patch it, but then noticed that it is a bit different than what the patch sugests

    $proximityHandlers = module_invoke_all('proximity_views_handlers');
    foreach ($proximityHandlers as $key => $handler) {
      // Manually skip 'Exposed Filter', since it wouldn't make any sense in this context.
      if ($key != 'exposed_geofield_filter') {
        $form['source']['#options'][$key] = $handler['name'];

      if (class_exists($handler['class'])) {
        $proximityPlugin = new $handler['class']();
        $proximityPlugin->option_definition($options, $this);
      }
      }
    }

the

      if ($key != 'exposed_geofield_filter') {
        $form['source']['#options'][$key] = $handler['name'];

part is not in the patch

RdeBoer’s picture

Re #8:
The bit you tried to change manually is near line 141. It is very similar to the lines near 107, which is what the patch changes.
However the lines near 141 do, on second observation, need a similar treatment for the case where old Views are converted to the new style.
I'll produce a new patch soon.
Rik

pixelsweatshop’s picture

Status: Reviewed & tested by the community » Needs work

Can confirm #8. Any chance you have that updated patch, Rik? I tried to give it a go but it my attempt was messy.

vlooivlerke’s picture

Play with this version of Rik's geofield
its got some superhero stuff build in, and works

RdeBoer’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
8.86 KB

Reran the patch. Hopefully this one applies without issues.
The patch is against Geofield branch 7.x-2.x

RdeBoer’s picture

Here's Geofield 7.x-2.x with the above patch from #12 attached as a read-to-install module.

  • Brandonian committed 8e32d16 on 7.x-2.x authored by RdeBoer
    #2134777: Allow other modules to define their own proximity plugins
    
Brandonian’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch, @RdeBoer. Committed to 7.x-2.x

https://www.drupal.org/commitlog/commit/19248/8e32d16fdb69569ec7c91a4c7f...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.