GSoC Week #6: Porting geocode plugin

In the last week, I worked for Geocode Plugin, fixed some issues and now it is completely working with search api location module. Are you wondering what "Geocode" plugin exactly does. Well, let me first tell you what is Geocoder module does. It geocodes just about anything you throw at it including addresses, GPX files, geo-tagged images, and KML files. It is commonly used to automatically geocode Addressfield addresses into Geofield points for display on Openlayers Maps. It also supports the geolocation, and location modules.  

Search API Location modules provides a plugin "geocode" of plugin type "Location_Input " which leverages the functionalities of Geocoder module via a service "plugin.manager.geocoder.provider". It provides some facilities like site admin to quickly drag and reorder the geocoding providers like google maps, yandex etc according to geocoding preference. The first one among the providers which returns a valid location in lat/long pair format is used. But here is a major issue which was a blocker to use Search_Api_Location module in production site. Notice the issue given below, It shows "-10 " is plugin id of one of the geocoding providers plugins which never exists. Because  plugins are keyed as string values like "bingmaps", "googlemaps" etc not as integers. 

Drupal\Component\Plugin\Exception\PluginNotFoundException : The "-10" plugin does not exist. dans Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (ligne 52 de C:\wamp64\www\drupal-8.2.6\core\lib\Drupal\Component\Plugin\Discovery\DiscoveryTrait.php).   

If you notice the geocode.php, when we are trying to sort the active plugins i.e checked we are trying to sort them using a cheap way of usorting, which results removing the $id's actual value i.e string with integers value. To overcome this problem of disappearing actual offset, we need to implement uasort method to sort a multidimensional array. ( In our case it is $plugins array ). Some screenshots are given below where I tried to print the plugins array before sort and after sort using kint() must give you a solid understanding. 

Error
                                                                                After usort of $plugins 
 
error
                                          After uasort of $plugins 

Thanks for reading. Don't forget to give your valuable feedback. In the next week I will be trying to port map plugin. Stay tuned.