Skip to content

Commit ea1e39c

Browse files
committed
UHF-12723: Add vehicle search block
1 parent c1ff18f commit ea1e39c

File tree

7 files changed

+113
-6
lines changed

7 files changed

+113
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
uuid: f73e721d-5865-48b3-a24a-051fa2f42961
2+
langcode: en
3+
status: true
4+
dependencies:
5+
module:
6+
- helfi_kymp_content
7+
- system
8+
theme:
9+
- hdbt_subtheme
10+
id: hdbt_subtheme_hakuvahti
11+
theme: hdbt_subtheme
12+
region: content
13+
weight: 5
14+
provider: null
15+
plugin: kymp_vehicle_removal
16+
settings:
17+
id: kymp_vehicle_removal
18+
label: Hakuvahti
19+
label_display: '0'
20+
provider: helfi_kymp_content
21+
visibility:
22+
request_path:
23+
id: request_path
24+
negate: false
25+
pages: /pysakointi/ajoneuvojen-siirrot/ajoneuvojen-siirtokehotukset
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
langcode: en
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vehicle-removal-search:
2+
version: HELFI_DEPLOYMENT_IDENTIFIER
3+
js: {}
4+
# Theme will extend this library.

public/modules/custom/helfi_kymp_content/helfi_kymp_content.module

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ use Drupal\node\NodeInterface;
1818
/**
1919
* Implements hook_theme().
2020
*/
21-
function helfi_kymp_content_theme() {
21+
function helfi_kymp_content_theme(): array {
2222
return [
23+
'vehicle_removal' => [
24+
'variables' => [],
25+
],
2326
'subdistricts_navigation' => [
2427
'variables' => [
2528
'navigation' => NULL,

public/modules/custom/helfi_kymp_content/src/Plugin/Block/SubdistrictsNavigationBlock.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Drupal\helfi_kymp_content\Plugin\Block;
66

7+
use Drupal\Core\Block\Attribute\Block;
78
use Drupal\Core\Block\BlockBase;
89
use Drupal\Core\Cache\Cache;
910
use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -13,6 +14,7 @@
1314
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
1415
use Drupal\Core\Routing\RouteMatchInterface;
1516
use Drupal\Core\Session\AccountProxyInterface;
17+
use Drupal\Core\StringTranslation\TranslatableMarkup;
1618
use Drupal\Core\Template\Attribute;
1719
use Drupal\helfi_kymp_content\DistrictUtility;
1820
use Drupal\node\NodeInterface;
@@ -22,12 +24,11 @@
2224

2325
/**
2426
* Provides a 'SubdistrictsNavigationBlock' block.
25-
*
26-
* @Block(
27-
* id = "subdistricts_navigation",
28-
* admin_label = @Translation("Subdistricts navigation"),
29-
* )
3027
*/
28+
#[Block(
29+
id: 'subdistricts_navigation',
30+
admin_label: new TranslatableMarkup('Subdistricts navigation'),
31+
)]
3132
final class SubdistrictsNavigationBlock extends BlockBase implements ContainerFactoryPluginInterface {
3233

3334
/**
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\helfi_kymp_content\Plugin\Block;
6+
7+
use Drupal\Core\Block\Attribute\Block;
8+
use Drupal\Core\Block\BlockBase;
9+
use Drupal\Core\Cache\CacheableMetadata;
10+
use Drupal\Core\Config\ConfigFactoryInterface;
11+
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
12+
use Drupal\Core\StringTranslation\TranslatableMarkup;
13+
use Drupal\helfi_hakuvahti\DrupalSettings;
14+
15+
/**
16+
* Block that displays the Hakuvahti signup form.
17+
*/
18+
#[Block(
19+
id: 'kymp_vehicle_removal',
20+
admin_label: new TranslatableMarkup('Hakuvahti'),
21+
)]
22+
final class VehicleRemovalBlock extends BlockBase implements ContainerFactoryPluginInterface {
23+
24+
public function __construct(
25+
array $configuration,
26+
string $plugin_id,
27+
mixed $plugin_definition,
28+
private readonly DrupalSettings $drupalSettings,
29+
private readonly ConfigFactoryInterface $configFactory,
30+
) {
31+
parent::__construct($configuration, $plugin_id, $plugin_definition);
32+
}
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
public function build(): array {
38+
$proxySettings = $this->configFactory->get('elastic_proxy.settings');
39+
$reactSettings = $this->configFactory->get('react_search.settings');
40+
41+
$cache = new CacheableMetadata();
42+
$cache->addCacheableDependency($proxySettings);
43+
$cache->addCacheableDependency($reactSettings);
44+
45+
$build = [
46+
'#theme' => 'vehicle_removal',
47+
'#attached' => [
48+
'drupalSettings' => [
49+
'helfi_react_search' => [
50+
'elastic_proxy_url' => $proxySettings->get('elastic_proxy_url'),
51+
'sentry_dsn_react' => $reactSettings->get('sentry_dsn_react'),
52+
],
53+
],
54+
'library' => [
55+
'helfi_kymp_content/vehicle-removal-search',
56+
],
57+
],
58+
];
59+
60+
// Apply hakuvahti settings.
61+
$this->drupalSettings->applyTo($build);
62+
63+
// Cache tags.
64+
$cache->applyTo($build);
65+
66+
return $build;
67+
}
68+
69+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
{# The React app will load into this div. #}
3+
<div id="helfi-vehicle-removal-search"></div>
4+
</div>

0 commit comments

Comments
 (0)