location_selector-8.x-1.x-dev/location_selector.module
location_selector.module
<?php
/**
* @file
* Contains location_selector.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\FieldStorageConfigInterface;
/**
* Implements hook_help().
*/
function location_selector_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the location_selector module.
case 'help.page.location_selector':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The solution is to use a Location API instead of taxonomies. Google API has a price program, and is no longer free at a certain point. <a href="https://www.geonames.org/" target="_blank" rel="nofollow">GeoNames</a> on the other hand has a Creative Commons Attribution 4.0 License and a huge location database too. So in my opinion its the better deal.<br>
Theorethically, the module can be further developed for further APIs in the future.') . '</p>';
$output .= '<h3>' .t('How to use') . '</h3>';
$output .= '<p>' .t('<ol>
<li>Install the module like every normal module.</li>
<li>Go to <a href="http://www.geonames.org/login" target="_blank" rel="nofollow">www.geonames.org/login</a> and create a free account for limitless API access. See also: <a href="https://www.geonames.org/export/web-services.html" target="_blank" rel="nofollow">www.geonames.org/export/web-services</a> for more information.</li>
<li>Go to /admin/config/location_selector/settings and enter the geonames username.</li>
<li>On "Manage Fields": Add a location selector field to your entity (e.g. Content Type).</li>
<li>On "Manage Form Display": Set the Field Widget parameters.</li>
<li>On "Manage Display": Set the Field Display parameters.</li>
</ol>') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_field_views_data_alter().
*
* Views integration for entity reference fields which reference nodes.
* Adds a term relationship to the default field data.
*
* @see views_field_default_views_data()
* @see https://drupal.stackexchange.com/questions/226268/views-exposed-filter-to-have-dropdown-of-entity-reference-in-cutstom-entity
*/
function location_selector_field_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) {
if ($field_storage->getType() == 'location_selector_type') {
foreach ($data as $table_name => $table_data) {
foreach ($table_data as $field_name => $field_data) {
if (isset($field_data['filter']) && $field_name != 'delta') {
$data[$table_name][$field_name]['filter']['id'] = 'location_selector_filter';
}
}
}
}
}
