Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ There are two default bundle types, address and area.

There is [an overview of the bundles and reusing addresses on the wiki](https://github.com/localgovdrupal/localgov_geo/wiki/Locations-Module-(LocalGov-Geo)).

## Ordnance Survey Places geocoder
This module provides a Drupal geocoder plugin for the [Ordnance Survey Places PHP geocoder](https://packagist.org/packages/localgovdrupal/localgov_os_places_geocoder_provider). This plugin is useful for geocoding and address lookup using the [Ordnance Survey Places API](https://osdatahub.os.uk/docs/places/overview) which covers addresses in the UK. This plugin requires an API key. It is free for UK local authorities.

### Good to know
- Install the [Ordnance Survey Places PHP geocoder](https://packagist.org/packages/localgovdrupal/localgov_os_places_geocoder_provider) to use this plugin as per the composer suggestion.
- There is a [known issue](https://www.drupal.org/project/geocoder/issues/3153678#comment-14203727) with Drupal geocoder plugins that they sometimes do not immediately appear in the *Geocoder provider* dropdown at /admin/config/system/geocoder/geocoder-provider. If this happens, restart PHP or the (virtual) machine hosting PHP and then review the dropdown.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
},
"require-dev": {
"localgovdrupal/localgov_core": "^2.1"
},
"suggest": {
"localgovdrupal/localgov_os_places_geocoder_provider": "1.x-dev"
}
}
20 changes: 20 additions & 0 deletions config/schema/localgov_geo.geocoder.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
geocoder_provider.configuration.localgov_os_places:
type: geocoder_provider_configuration
label: 'Localgov OS Places arguments'
mapping:
genericAddressQueryUrl:
type: string
label: 'Street address-based query URL'
description: 'URL of the OS Places API server for street address-based query.'
postcodeQueryUrl:
type: string
label: 'Postcode-based query URL'
description: 'URL of the OS Places API server for postcode-based query.'
apiKey:
type: string
label: 'API key'
description: 'Value of the API key'
userAgent:
type: string
label: 'User agent'
description: 'Value of the User-Agent header'
6 changes: 3 additions & 3 deletions localgov_geo.install
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function localgov_geo_update_8004() {
->set("module.localgov_geo_address", 0)
->set('module', module_config_sort($extension_config->get('module')))
->save(TRUE);
drupal_set_installed_schema_version('localgov_geo_address', 0);
\Drupal::service('update.update_hook_registry')->setInstalledVersion('localgov_geo_address', 0);

// Copy default view mode to be same as new embed view mode.
$default = \Drupal::configFactory()->get('core.entity_view_display.localgov_geo.address.default');
Expand Down Expand Up @@ -512,8 +512,8 @@ EOY;
* Correct localgov_geo_address submodule schema.
*/
function localgov_geo_update_8006() {
if (drupal_get_installed_schema_version('localgov_geo_address') == 0) {
drupal_set_installed_schema_version('localgov_geo_address', 8000);
if (\Drupal::service('update.update_hook_registry')->getInstalledVersion('localgov_geo_address') == 0) {
\Drupal::service('update.update_hook_registry')->setInstalledVersion('localgov_geo_address', 8000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/LocalgovGeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* revision_data_table = "localgov_geo_field_revision",
* show_revision_ui = TRUE,
* translatable = TRUE,
* admin_permission = "administer geo types",
* admin_permission = "access geo overview",
* entity_keys = {
* "id" = "id",
* "revision" = "revision_id",
Expand Down
21 changes: 20 additions & 1 deletion src/Form/LocalgovGeoForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Form controller for the geo entity edit forms.
*/
class LocalgovGeoForm extends ContentEntityForm {

/**
* The renderer service.
*
* @var \Drupal\Core\Render\Renderer
*/
protected $renderer;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$form = parent::create($container);

$form->renderer = $container->get('renderer');

return $form;
}

/**
* {@inheritdoc}
*/
Expand All @@ -20,7 +39,7 @@ public function save(array $form, FormStateInterface $form_state) {
$link = $entity->toLink($this->t('View'))->toRenderable();

$message_arguments = ['%label' => $this->entity->label()];
$logger_arguments = $message_arguments + ['link' => render($link)];
$logger_arguments = $message_arguments + ['link' => $this->renderer->render($link)];

if ($result == SAVED_NEW) {
$this->messenger()->addStatus($this->t('New geo %label has been created.', $message_arguments));
Expand Down
1 change: 1 addition & 0 deletions src/LocalgovGeoListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function render() {

$total = $this->getStorage()
->getQuery()
->accessCheck(TRUE)
->count()
->execute();

Expand Down
24 changes: 24 additions & 0 deletions src/Plugin/Geocoder/Provider/LocalgovOsPlacesGeocoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types = 1);

namespace Drupal\localgov_geo\Plugin\Geocoder\Provider;

use Drupal\geocoder\ConfigurableProviderUsingHandlerWithAdapterBase;

/**
* Provides an Ordnance Survey Places API-based geocoder provider plugin.
*
* @GeocoderProvider(
* id = "localgov_os_places",
* name = "Localgov OS Places",
* handler = "\LocalgovDrupal\OsPlacesGeocoder\Provider\OsPlacesGeocoder",
* arguments = {
* "genericAddressQueryUrl" = "https://api.os.uk/search/places/v1/find",
* "postcodeQueryUrl" = "https://api.os.uk/search/places/v1/postcode",
* "apiKey" = "",
* "userAgent" = "LocalGov Drupal"
* }
* )
*/
class LocalgovOsPlacesGeocoder extends configurableProviderUsingHandlerWithAdapterBase {}
4 changes: 2 additions & 2 deletions tests/src/Functional/GeoBundleCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GeoBundleCreationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'system',
'text',
'field_ui',
Expand Down Expand Up @@ -58,7 +58,7 @@ class GeoBundleCreationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();

// Have two users ready to be used in tests.
Expand Down
120 changes: 120 additions & 0 deletions tests/src/Functional/GeoOverviewAccessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace Drupal\Tests\localgov_geo\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Geo ovewview page access tests.
*
* Ensures that non-admin users with the right permissions can access the Geo
* overview page.
*
* @group localgov_geo
*/
class GeoOverviewAccessTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'localgov_geo',
];

/**
* Permissions for the admin user that will be logged-in for test.
*
* @var array
*/
protected static $adminUserPermissions = [
'access geo overview',
'delete geo',
'create geo',
'edit geo',
'administer geo types',
];

/**
* Permissions given to an Editor user.
*
* @var array
*/
protected static $nonAdminUserPermissions = [
'access geo overview',
'create geo',
'edit geo',
'delete geo',
];

/**
* Permissions for non-editor who can create geo.
*
* @var array
*/
protected static $creatorUserPermissions = [
'create geo',
'edit geo',
];

/**
* An admin test user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;

/**
* A non-admin test user account.
*
* @var \drupal\user\userinterface
*/
protected $nonAdminUser;

/**
* A creator test user account.
*
* @var \drupal\user\userinterface
*/
protected $creatorUser;

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

// Have two users ready to be used in tests.
$this->adminUser = $this->drupalCreateUser(static::$adminUserPermissions);
$this->nonAdminUser = $this->drupalCreateUser(static::$nonAdminUserPermissions);
$this->creatorUser = $this->drupalCreateUser(static::$creatorUserPermissions);

// Start off logged in as admin.
$this->drupalLogin($this->adminUser);
}

/**
* Access test for the Geo overview page.
*
* The Editor user should be able to access the overview page.
*/
public function testOverviewPageAccess() {

$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(200);

$this->drupalLogin($this->nonAdminUser);
$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(200);

$this->drupalLogin($this->creatorUser);
$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(403);
}

}