From df0ac2aece3081d31cbe68660d912c84db78c372 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 17 Jan 2025 08:50:45 +0200 Subject: [PATCH 1/7] UHF-11002: Revert "Revert "UHF-10774: news location"" This reverts commit 6c2cb781e35c6741b2a5599cfe64697cc83554c3. --- ...onomy_term.news_neighbourhoods.default.yml | 64 +++++++++++ ...onomy_term.news_neighbourhoods.default.yml | 25 ++++ conf/cmi/search_api.index.news.yml | 26 +++++ .../helfi_etusivu/helfi_etusivu.deploy.php | 108 ++++++++++++++++++ 4 files changed, 223 insertions(+) create mode 100644 conf/cmi/core.entity_form_display.taxonomy_term.news_neighbourhoods.default.yml create mode 100644 conf/cmi/core.entity_view_display.taxonomy_term.news_neighbourhoods.default.yml create mode 100644 public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php diff --git a/conf/cmi/core.entity_form_display.taxonomy_term.news_neighbourhoods.default.yml b/conf/cmi/core.entity_form_display.taxonomy_term.news_neighbourhoods.default.yml new file mode 100644 index 000000000..d4987cc5b --- /dev/null +++ b/conf/cmi/core.entity_form_display.taxonomy_term.news_neighbourhoods.default.yml @@ -0,0 +1,64 @@ +uuid: dc0590fe-78b1-402d-b0c7-686c8f32d3e5 +langcode: en +status: true +dependencies: + config: + - field.field.taxonomy_term.news_neighbourhoods.field_location + - taxonomy.vocabulary.news_neighbourhoods + module: + - helfi_platform_config + - path + - text +id: taxonomy_term.news_neighbourhoods.default +targetEntityType: taxonomy_term +bundle: news_neighbourhoods +mode: default +content: + description: + type: text_textfield + weight: 0 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + field_location: + type: location + weight: 101 + region: content + settings: { } + third_party_settings: { } + langcode: + type: language_select + weight: 2 + region: content + settings: + include_locked: true + third_party_settings: { } + name: + type: string_textfield + weight: -5 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + path: + type: path + weight: 30 + region: content + settings: { } + third_party_settings: { } + status: + type: boolean_checkbox + weight: 100 + region: content + settings: + display_label: true + third_party_settings: { } + translation: + weight: 10 + region: content + settings: { } + third_party_settings: { } +hidden: { } diff --git a/conf/cmi/core.entity_view_display.taxonomy_term.news_neighbourhoods.default.yml b/conf/cmi/core.entity_view_display.taxonomy_term.news_neighbourhoods.default.yml new file mode 100644 index 000000000..ef913c501 --- /dev/null +++ b/conf/cmi/core.entity_view_display.taxonomy_term.news_neighbourhoods.default.yml @@ -0,0 +1,25 @@ +uuid: 96825838-b49d-4139-8bf9-24ba7d31b5ac +langcode: en +status: true +dependencies: + config: + - field.field.taxonomy_term.news_neighbourhoods.field_location + - taxonomy.vocabulary.news_neighbourhoods + module: + - text +id: taxonomy_term.news_neighbourhoods.default +targetEntityType: taxonomy_term +bundle: news_neighbourhoods +mode: default +content: + description: + type: text_default + label: hidden + settings: { } + third_party_settings: { } + weight: 0 + region: content +hidden: + field_location: true + langcode: true + search_api_excerpt: true diff --git a/conf/cmi/search_api.index.news.yml b/conf/cmi/search_api.index.news.yml index e1b59b347..70acba8ef 100644 --- a/conf/cmi/search_api.index.news.yml +++ b/conf/cmi/search_api.index.news.yml @@ -3,6 +3,8 @@ langcode: en status: true dependencies: config: + - field.storage.node.field_main_image_caption + - field.storage.taxonomy_term.field_location - field.storage.media.field_media_image - field.storage.media.field_photographer - field.storage.node.field_main_image @@ -13,6 +15,11 @@ dependencies: - field.storage.node.field_short_title - search_api.server.default module: + - node + - taxonomy + - media + - publication_date + - search_api - helfi_etusivu - helfi_react_search - media @@ -55,6 +62,14 @@ field_settings: label: 'Entity type' property_path: search_api_entity_type type: string + field_location: + label: Location + datasource_id: 'entity:taxonomy_term' + property_path: field_location + type: location + dependencies: + config: + - field.storage.taxonomy_term.field_location field_main_image_caption: label: Caption datasource_id: 'entity:node' @@ -112,6 +127,17 @@ field_settings: dependencies: config: - field.storage.node.field_short_title + news_location: + label: 'Kaupunginosat » Luokittelutermi » Location' + datasource_id: 'entity:node' + property_path: 'field_news_neighbourhoods:entity:field_location' + type: location + dependencies: + config: + - field.storage.node.field_news_neighbourhoods + - field.storage.taxonomy_term.field_location + module: + - taxonomy main_image_url: label: 'Main Image' property_path: main_image_url diff --git a/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php b/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php new file mode 100644 index 000000000..71ade3560 --- /dev/null +++ b/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php @@ -0,0 +1,108 @@ + [60.187933, 24.944132], + 'Eira' => [60.155249, 24.938121], + 'Etu-Töölö' => [60.173279, 24.923774], + 'Haaga' => [60.221837, 24.896392], + 'Hakaniemi' => [60.180465, 24.951613], + 'Hermanni' => [60.195101, 24.966697], + 'Hernesaari' => [60.149268, 24.924342], + 'Herttoniemi' => [60.193202, 25.036063], + 'Honkasuo' => [60.256156, 24.845279], + 'Itäkeskus ja Vartiokylä' => [60.214989, 25.089473], + 'Jätkäsaari' => [60.156744, 24.913439], + 'Kaarela' => [60.251193, 24.881449], + 'Kaartinkaupunki' => [60.165227, 24.948996], + 'Kaivopuisto' => [60.155933, 24.955835], + 'Kalasatama' => [60.185294, 24.980741], + 'Kallio' => [60.184327, 24.949712], + 'Kamppi' => [60.167335, 24.931190], + 'Kannelmäki' => [60.241693, 24.885368], + 'Karhusaari' => [60.250323, 25.220108], + 'Katajanokka' => [60.166662, 24.969216], + 'Keskusta' => [60.169519, 24.952272], + 'Kluuvi' => [60.172580, 24.941144], + 'Koivusaari' => [60.163196, 24.856204], + 'Konala' => [60.236852, 24.845177], + 'Koskela' => [60.218253, 24.966418], + 'Kruununhaka' => [60.172352, 24.956470], + 'Kruunuvuorenranta' => [60.166554, 25.022126], + 'Kulosaari' => [60.185983, 25.008457], + 'Kumpula' => [60.209094, 24.964821], + 'Kuninkaantammi' => [60.261009, 24.890437], + 'Käpylä' => [60.214154, 24.950797], + 'Laajasalo' => [60.171870, 25.043385], + 'Laakso' => [60.192795, 24.916465], + 'Lauttasaari' => [60.158291, 24.874188], + 'Länsisatama' => [60.159699, 24.924461], + 'Malmi' => [60.250980, 25.010506], + 'Malminkartano' => [60.247517, 24.862129], + 'Meilahti' => [60.191904, 24.898236], + 'Mellunkylä' => [60.233563, 25.102157], + 'Munkkiniemi' => [60.198247, 24.875977], + 'Mustikkamaa-Korkeasaari' => [60.180563, 24.990058], + 'Myllypuro' => [60.223721, 25.067943], + 'Oulunkylä' => [60.229094, 24.963609], + 'Pakila' => [60.244177, 24.948121], + 'Pasila' => [60.203116, 24.926870], + 'Pitäjänmäki' => [60.222972, 24.862067], + 'Pukinmäki' => [60.245141, 24.988965], + 'Punavuori' => [60.161450, 24.937520], + 'Ruoholahti' => [60.163818, 24.908564], + 'Ruskeasuo' => [60.202629, 24.905525], + 'Salmenkallio' => [60.263065, 25.192160], + 'Santahamina' => [60.147226, 25.051203], + 'Suomenlinna' => [60.145609, 24.986295], + 'Suurmetsä' => [60.265570, 25.079241], + 'Suutarila' => [60.280899, 25.010958], + 'Sörnäinen' => [60.186503, 24.968059], + 'Taka-Töölö' => [60.184170, 24.923262], + 'Talosaari' => [60.242051, 25.197464], + 'Tammisalo' => [60.191309, 25.063848], + 'Tapaninkylä' => [60.262263, 25.011138], + 'Toukola' => [60.206072, 24.972955], + 'Tuomarinkylä' => [60.256383, 24.966787], + 'Ulkosaaret' => [60.089292, 24.926002], + 'Ullanlinna' => [60.158457, 24.948937], + 'Ultuna' => [60.278678, 25.195271], + 'Vallila' => [60.194432, 24.956953], + 'Vanhakaupunki' => [60.216221, 24.981143], + 'Vartiokylä' => [60.217183, 25.095837], + 'Vartiosaari' => [60.184930, 25.078028], + 'Viikki' => [60.224815, 25.020019], + 'Villinki' => [60.158338, 25.114887], + 'Vuosaari' => [60.209362, 25.147469], + 'Östersundom' => [60.251257, 25.182209], + ]; + + $storage = \Drupal::entityTypeManager() + ->getStorage('taxonomy_term'); + + foreach ($neighbourhoods as $name => $location) { + $terms = $storage->loadByProperties(['name' => $name, 'vid' => 'news_neighbourhoods']); + if (!$terms) { + continue; + } + + [$latitude, $longitude] = $location; + $term = reset($terms); + $term->set('field_location', [ + 'latitude' => $latitude, + 'longitude' => $longitude, + ]); + $term->save(); + } + +} From 07350131bbd7b5a062fb1fd5b2b8aaf754edb68f Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 17 Jan 2025 08:50:48 +0200 Subject: [PATCH 2/7] Revert "Remove field_location config" This reverts commit 11b866c6b74c5d50c1e11ca47219944a93a68813. --- ...erm.news_neighbourhoods.field_location.yml | 23 +++++++++++++++++++ ...d.storage.taxonomy_term.field_location.yml | 21 +++++++++++++++++ ...erm.news_neighbourhoods.field_location.yml | 1 + ...erm.news_neighbourhoods.field_location.yml | 1 + 4 files changed, 46 insertions(+) create mode 100644 conf/cmi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml create mode 100644 conf/cmi/field.storage.taxonomy_term.field_location.yml create mode 100644 conf/cmi/language/fi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml create mode 100644 conf/cmi/language/sv/field.field.taxonomy_term.news_neighbourhoods.field_location.yml diff --git a/conf/cmi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml b/conf/cmi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml new file mode 100644 index 000000000..80d02f51d --- /dev/null +++ b/conf/cmi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml @@ -0,0 +1,23 @@ +uuid: 77736144-e2d4-4f43-9bf4-d6a5700454e9 +langcode: en +status: true +dependencies: + config: + - field.storage.taxonomy_term.field_location + - taxonomy.vocabulary.news_neighbourhoods + module: + - helfi_platform_config +_core: + default_config_hash: zMqD_YIcxb2SEi-zEfioqQpiVagAuP6dpQnuKTmr4LU +id: taxonomy_term.news_neighbourhoods.field_location +field_name: field_location +entity_type: taxonomy_term +bundle: news_neighbourhoods +label: Location +description: 'Neighbourhood location. Used to search nearby content.' +required: true +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: location diff --git a/conf/cmi/field.storage.taxonomy_term.field_location.yml b/conf/cmi/field.storage.taxonomy_term.field_location.yml new file mode 100644 index 000000000..812b4d065 --- /dev/null +++ b/conf/cmi/field.storage.taxonomy_term.field_location.yml @@ -0,0 +1,21 @@ +uuid: 44d5b217-5ef0-4178-8a1a-6190babb12e2 +langcode: en +status: true +dependencies: + module: + - helfi_platform_config + - taxonomy +_core: + default_config_hash: J3VYlUUqe9orySkqRTkfaf3zmiABVwpRFgS2Wk-qykg +id: taxonomy_term.field_location +field_name: field_location +entity_type: taxonomy_term +type: location +settings: { } +module: helfi_platform_config +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/conf/cmi/language/fi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml b/conf/cmi/language/fi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml new file mode 100644 index 000000000..d109e918b --- /dev/null +++ b/conf/cmi/language/fi/field.field.taxonomy_term.news_neighbourhoods.field_location.yml @@ -0,0 +1 @@ +label: Sijainti diff --git a/conf/cmi/language/sv/field.field.taxonomy_term.news_neighbourhoods.field_location.yml b/conf/cmi/language/sv/field.field.taxonomy_term.news_neighbourhoods.field_location.yml new file mode 100644 index 000000000..9a338e991 --- /dev/null +++ b/conf/cmi/language/sv/field.field.taxonomy_term.news_neighbourhoods.field_location.yml @@ -0,0 +1 @@ +label: Plats From 8dc9ecf9f262db5aead1687cee3c1136de924449 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 17 Jan 2025 08:50:49 +0200 Subject: [PATCH 3/7] UHF-11002: Update node to latest LTS release --- public/themes/custom/hdbt_subtheme/.nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/themes/custom/hdbt_subtheme/.nvmrc b/public/themes/custom/hdbt_subtheme/.nvmrc index d5a159609..2bd5a0a98 100644 --- a/public/themes/custom/hdbt_subtheme/.nvmrc +++ b/public/themes/custom/hdbt_subtheme/.nvmrc @@ -1 +1 @@ -20.10.0 +22 From a0f0ada44cd02fc3e5c396574312dc7fc52318a6 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 17 Jan 2025 08:50:50 +0200 Subject: [PATCH 4/7] UHF-11002: Add location to news_terms index --- conf/cmi/search_api.index.news.yml | 26 ------------------------ conf/cmi/search_api.index.news_terms.yml | 9 ++++++++ 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/conf/cmi/search_api.index.news.yml b/conf/cmi/search_api.index.news.yml index 70acba8ef..e1b59b347 100644 --- a/conf/cmi/search_api.index.news.yml +++ b/conf/cmi/search_api.index.news.yml @@ -3,8 +3,6 @@ langcode: en status: true dependencies: config: - - field.storage.node.field_main_image_caption - - field.storage.taxonomy_term.field_location - field.storage.media.field_media_image - field.storage.media.field_photographer - field.storage.node.field_main_image @@ -15,11 +13,6 @@ dependencies: - field.storage.node.field_short_title - search_api.server.default module: - - node - - taxonomy - - media - - publication_date - - search_api - helfi_etusivu - helfi_react_search - media @@ -62,14 +55,6 @@ field_settings: label: 'Entity type' property_path: search_api_entity_type type: string - field_location: - label: Location - datasource_id: 'entity:taxonomy_term' - property_path: field_location - type: location - dependencies: - config: - - field.storage.taxonomy_term.field_location field_main_image_caption: label: Caption datasource_id: 'entity:node' @@ -127,17 +112,6 @@ field_settings: dependencies: config: - field.storage.node.field_short_title - news_location: - label: 'Kaupunginosat » Luokittelutermi » Location' - datasource_id: 'entity:node' - property_path: 'field_news_neighbourhoods:entity:field_location' - type: location - dependencies: - config: - - field.storage.node.field_news_neighbourhoods - - field.storage.taxonomy_term.field_location - module: - - taxonomy main_image_url: label: 'Main Image' property_path: main_image_url diff --git a/conf/cmi/search_api.index.news_terms.yml b/conf/cmi/search_api.index.news_terms.yml index 7998b4448..d034b7bdc 100644 --- a/conf/cmi/search_api.index.news_terms.yml +++ b/conf/cmi/search_api.index.news_terms.yml @@ -3,6 +3,7 @@ langcode: en status: true dependencies: config: + - field.storage.taxonomy_term.field_location - search_api.server.default module: - helfi_etusivu @@ -81,6 +82,14 @@ field_settings: dependencies: module: - taxonomy + field_location: + label: Location + datasource_id: 'entity:taxonomy_term' + property_path: field_location + type: location + dependencies: + config: + - field.storage.taxonomy_term.field_location datasource_settings: 'entity:taxonomy_term': bundles: From 57836707675bfb46866ea84d84056a9a4e4954fb Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 17 Jan 2025 08:50:51 +0200 Subject: [PATCH 5/7] UHF-11002: Implement news near you component --- ..._entity_type.helfi_news_neighbourhoods.yml | 2 + .../helfi_etusivu/helfi_etusivu.info.yml | 1 + .../custom/helfi_etusivu/helfi_etusivu.module | 2 + .../HelsinkiNearYouResultsController.php | 233 ++++++++++-------- .../src/Enum/InternalSearchLink.php | 6 + .../custom/helfi_etusivu/src/Servicemap.php | 27 +- .../helsinki-near-you-results-page.html.twig | 42 +++- .../custom/hdbt_subtheme/translations/fi.po | 16 ++ .../custom/hdbt_subtheme/translations/sv.po | 16 ++ 9 files changed, 239 insertions(+), 106 deletions(-) diff --git a/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml b/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml index e7f668016..8d66af388 100644 --- a/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml +++ b/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml @@ -21,6 +21,8 @@ field_mapper_config: value: '$._source.name[0]' tid: value: '$._source.tid[0]' + location: + value: '$._source.field_location' storage_client_id: helfi_news_neighbourhoods storage_client_config: { } persistent_cache_max_age: 86400 diff --git a/public/modules/custom/helfi_etusivu/helfi_etusivu.info.yml b/public/modules/custom/helfi_etusivu/helfi_etusivu.info.yml index 65bd3c07f..12dc63827 100644 --- a/public/modules/custom/helfi_etusivu/helfi_etusivu.info.yml +++ b/public/modules/custom/helfi_etusivu/helfi_etusivu.info.yml @@ -12,5 +12,6 @@ dependencies: - helfi_annif:helfi_annif - simple_sitemap:simple_sitemap - helfi_react_search:helfi_react_search + - helfi_platform_config:helfi_paragraphs_news_list 'interface translation project': helfi_etusivu 'interface translation server pattern': modules/custom/helfi_etusivu/translations/%language.po diff --git a/public/modules/custom/helfi_etusivu/helfi_etusivu.module b/public/modules/custom/helfi_etusivu/helfi_etusivu.module index 133173a43..a279cf1bd 100644 --- a/public/modules/custom/helfi_etusivu/helfi_etusivu.module +++ b/public/modules/custom/helfi_etusivu/helfi_etusivu.module @@ -330,6 +330,8 @@ function helfi_etusivu_theme() : array { 'coordinates' => NULL, 'title' => NULL, 'service_groups' => NULL, + 'nearby_neighbourhoods' => NULL, + 'news_archive_url' => NULL, ], 'template' => 'helsinki-near-you-results-page', ], diff --git a/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php b/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php index d31870d0b..1ff6fcdfe 100644 --- a/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php +++ b/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php @@ -7,9 +7,11 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; +use Drupal\external_entities\Entity\Query\External\Query; use Drupal\helfi_etusivu\Enum\InternalSearchLink; use Drupal\helfi_etusivu\Enum\ServiceMapLink; use Drupal\helfi_etusivu\Servicemap; +use Drupal\helfi_paragraphs_news_list\Entity\ExternalEntity\Term; use Drupal\helfi_react_search\LinkedEvents; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -38,7 +40,6 @@ public function __construct( * Returns a renderable array. * * @param \Symfony\Component\HttpFoundation\Request $request - * * The request. * * @return array @@ -53,7 +54,7 @@ public function content(Request $request) : array|RedirectResponse { return $this->redirect('helfi_etusivu.helsinki_near_you'); } $address = Xss::filter($address); - $addressData = $this->getCoordinates(urldecode($address)); + $addressData = $this->servicemap->getAddressData(urldecode($address)); if (!$addressData) { $this->messenger()->addError( @@ -68,6 +69,12 @@ public function content(Request $request) : array|RedirectResponse { $addressName = $this->resolveTranslation($addressData['address_translations']); + $neighborhoods = $this->getNearbyNewsNeighbourhoods($addressData['coordinates']); + $newsQuery = [ + 'neighbourhoods' => array_values(array_map(static fn (Term $term) => $term->getTid(), $neighborhoods)), + ]; + $newsArchiveUrl = $this->getInternalSearchLink(InternalSearchLink::NEWS_ARCHIVE, $newsQuery); + return [ '#attached' => [ 'drupalSettings' => [ @@ -85,11 +92,17 @@ public function content(Request $request) : array|RedirectResponse { 'seeAllButtonOverride' => $this->t('See all events', [], ['context' => 'Helsinki near you']), 'useExperimentalGhosts' => TRUE, ], + 'helfi_news_archive' => [ + 'elastic_proxy_url' => $this->config('elastic_proxy.settings')->get('elastic_proxy_url'), + 'default_query' => http_build_query($newsQuery), + 'hide_form' => TRUE, + 'max_results' => 3, + ], ], - 'library' => ['hdbt/event-list'], ], '#back_link_label' => $this->t('Edit address', [], ['context' => 'Helsinki near you']), '#back_link_url' => $return_url, + '#news_archive_url' => $newsArchiveUrl, '#cache' => [ 'contexts' => ['url.query_args:q'], ], @@ -100,83 +113,81 @@ public function content(Request $request) : array|RedirectResponse { ['@address' => $addressName], ['context' => 'Helsinki near you'] ), - '#service_groups' => [ - [ - 'title' => $this->t('Health is key', [], ['context' => 'Helsinki near you']), - 'service_links' => [ - [ - 'link_label' => $this->t('Your own health station', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::HEALTH_STATIONS, - $addressName, - ), - ], - [ - 'link_label' => $this->t('Closest maternity and child health clinic', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::CHILD_HEALTH_STATIONS, - $addressName, - ), - ], + '#nearby_neighbourhoods' => $neighborhoods, + '#service_groups' => $this->buildServiceGroups($addressName), + ]; + } + + /** + * Builds service groups render array. + * + * @param string $addressName + * Current address. + * + * @return array + * Render array. + */ + public function buildServiceGroups(string $addressName) : array { + $addressQuery = ['address' => urlencode($addressName)]; + + return [ + [ + 'title' => $this->t('Health is key', [], ['context' => 'Helsinki near you']), + 'service_links' => [ + [ + 'link_label' => $this->t('Your own health station', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::HEALTH_STATIONS, $addressQuery), + ], + [ + 'link_label' => $this->t('Closest maternity and child health clinic', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::CHILD_HEALTH_STATIONS, $addressQuery), ], ], - [ - 'title' => $this->t('Grow and learn', [], ['context' => 'Helsinki near you']), - 'service_links' => [ - [ - 'link_label' => $this->t('Schools close to you', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::SCHOOLS, - $addressName, - ), - ], - [ - 'link_label' => $this->t('Closest playgrounds and family houses', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::PLAYGROUNDS_FAMILY_HOUSES, - $addressName, - ), - ], - [ - 'link_label' => $this->t('Closest daycare centres', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::DAYCARES, - $addressName, - ), - ], + ], + [ + 'title' => $this->t('Grow and learn', [], ['context' => 'Helsinki near you']), + 'service_links' => [ + [ + 'link_label' => $this->t('Schools close to you', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::SCHOOLS, $addressQuery), + ], + [ + 'link_label' => $this->t('Closest playgrounds and family houses', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::PLAYGROUNDS_FAMILY_HOUSES, $addressQuery), + ], + [ + 'link_label' => $this->t('Closest daycare centres', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::DAYCARES, $addressQuery), ], ], - [ - 'title' => $this->t('Move around the city', [], ['context' => 'Helsinki near you']), - 'service_links' => [ - [ - 'link_label' => $this->t('Roadway ploughing schedule', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->getInternalSearchLink( - InternalSearchLink::PLOWING_SCHEDULES, - $addressName, - ), - ], - [ - 'link_label' => $this->t('Roadworks and events on map', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->servicemap->getLink(ServiceMapLink::ROADWORK_EVENTS, $addressName), - ], - [ - 'link_label' => $this->t('City bike stations on map', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->servicemap->getLink(ServiceMapLink::CITYBIKE_STATIONS_STANDS, $addressName), - ], + ], + [ + 'title' => $this->t('Move around the city', [], ['context' => 'Helsinki near you']), + 'service_links' => [ + [ + 'link_label' => $this->t('Roadway ploughing schedule', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->getInternalSearchLink(InternalSearchLink::PLOWING_SCHEDULES, $addressQuery), + ], + [ + 'link_label' => $this->t('Roadworks and events on map', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::ROADWORK_EVENTS, $addressName), + ], + [ + 'link_label' => $this->t('City bike stations on map', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::CITYBIKE_STATIONS_STANDS, $addressName), ], ], - [ - 'title' => $this->t('The city is developing', [], ['context' => 'Helsinki near you']), - 'service_links' => [ - [ - 'link_label' => $this->t('Street and park development on map', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->servicemap->getLink(ServiceMapLink::STREET_PARK_PROJECTS, $addressName), - ], - [ - 'link_label' => $this->t('Plans in process on map', [], ['context' => 'Helsinki near you']), - 'link_url' => $this->servicemap->getLink(ServiceMapLink::PLANS_IN_PROCESS, $addressName), - ], + ], + [ + 'title' => $this->t('The city is developing', [], ['context' => 'Helsinki near you']), + 'service_links' => [ + [ + 'link_label' => $this->t('Street and park development on map', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::STREET_PARK_PROJECTS, $addressName), + ], + [ + 'link_label' => $this->t('Plans in process on map', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::PLANS_IN_PROCESS, $addressName), ], ], ], @@ -210,31 +221,6 @@ public function addressSuggestions(Request $request) : JsonResponse { return new JsonResponse($suggestions); } - /** - * Get coordinates from servicemap API. - * - * @param string $address - * The address. - * - * @return array - * The coordinates. - */ - protected function getCoordinates(string $address) : ?array { - $results = $this->servicemap->query($address); - - if ( - isset($results['0']->name) && - isset($results['0']->location->coordinates) - ) { - return [ - 'address_translations' => $results['0']->name, - 'coordinates' => $results['0']->location->coordinates, - ]; - } - - return NULL; - } - /** * Resolves the translation string for given translation object. * @@ -253,22 +239,21 @@ protected function resolveTranslation(\stdClass $translations) : string { } /** - * Generate link to internal search with address param set. + * Generate link to internal search with query params. * * @param \Drupal\helfi_etusivu\Enum\InternalSearchLink $link * Internal search link option. - * @param string $address - * Address param for the link. + * @param array $query + * Query params for the link. * * @return string * The resulting link. */ protected function getInternalSearchLink( InternalSearchLink $link, - string $address, + array $query, ) : string { $langcode = $this->languageManager()->getCurrentLanguage()->getId(); - $query = ['address' => urlencode($address)]; $url = Url::fromUri( $link->getLinkTranslations()[$langcode], ['query' => $query], @@ -277,4 +262,44 @@ protected function getInternalSearchLink( return $url->toString(); } + /** + * Get nearby news neighbourhoods. + * + * @param array $coordinates + * Coordinates tuple. + * + * @return \Drupal\Core\Entity\EntityInterface[] + * Helfi: news Neighbourhoods entities. + */ + protected function getNearbyNewsNeighbourhoods(array $coordinates): array { + $storage = $this->entityTypeManager() + ->getStorage('helfi_news_neighbourhoods'); + $query = $storage + ->getQuery(); + + assert($query instanceof Query); + $query->setParameter('location', [ + $coordinates, + [ + 'unit' => 'km', + 'order' => 'asc', + // 'arc' is more accurate, but within + // a city it should not matter. + 'distance_type' => 'plane', + // What to do in case a field has several geo points. + 'mode' => 'min', + // Unmapped field cause the search to fail. + 'ignore_unmapped' => FALSE, + ], + ], 'GEO_DISTANCE_SORT'); + + $ids = $query + ->range(length: 3) + ->condition('search_api_language', $this->languageManager()->getCurrentLanguage()->getId()) + ->accessCheck(FALSE) + ->execute(); + + return $storage->loadMultiple($ids); + } + } diff --git a/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php b/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php index 4165ebe84..52702f41f 100644 --- a/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php +++ b/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php @@ -17,6 +17,7 @@ enum InternalSearchLink { case PLAYGROUNDS_FAMILY_HOUSES; case DAYCARES; case PLOWING_SCHEDULES; + case NEWS_ARCHIVE; /** * Return array of link translations. @@ -56,6 +57,11 @@ public function getLinkTranslations() : array { 'sv' => 'https://www.hel.fi/sv/stadsmiljo-och-trafik/underhall/gatuunderhall/vinterunderhall-av-gator', 'en' => 'https://www.hel.fi/en/urban-environment-and-traffic/general-maintenance/street-maintenance/winter-street-maintenance', ], + InternalSearchLink::NEWS_ARCHIVE => [ + 'fi' => 'https://www.hel.fi/fi/uutiset/etsi-uutisia', + 'sv' => 'https://www.hel.fi/sv/nyheter/sok-efter-nyheter', + 'en' => 'https://www.hel.fi/en/news/search-for-news', + ] }; } diff --git a/public/modules/custom/helfi_etusivu/src/Servicemap.php b/public/modules/custom/helfi_etusivu/src/Servicemap.php index 80168e44e..5527daee4 100644 --- a/public/modules/custom/helfi_etusivu/src/Servicemap.php +++ b/public/modules/custom/helfi_etusivu/src/Servicemap.php @@ -73,13 +73,38 @@ public function __construct( ) { } + /** + * Get coordinates from servicemap API. + * + * @param string $address + * The address. + * + * @return ?array + * The coordinates. + */ + public function getAddressData(string $address) : ?array { + $results = $this->query($address); + + if ( + isset($results['0']->name) && + isset($results['0']->location->coordinates) + ) { + return [ + 'address_translations' => $results['0']->name, + 'coordinates' => $results['0']->location->coordinates, + ]; + } + + return NULL; + } + /** * Queries location data based on address. * * @param string $address * Address to query against. * @param int $page_size - * Maximum number or results. + * Maximum number of results. * * @return array * Array of results. diff --git a/public/themes/custom/hdbt_subtheme/templates/module/helfi-etusivu/helsinki-near-you-results-page.html.twig b/public/themes/custom/hdbt_subtheme/templates/module/helfi-etusivu/helsinki-near-you-results-page.html.twig index 6db6ffb17..8ccd97a17 100644 --- a/public/themes/custom/hdbt_subtheme/templates/module/helfi-etusivu/helsinki-near-you-results-page.html.twig +++ b/public/themes/custom/hdbt_subtheme/templates/module/helfi-etusivu/helsinki-near-you-results-page.html.twig @@ -48,7 +48,7 @@ component_classes: [ 'component--react-search', 'component--event-list', - 'component--coordinates-based-event-list', + 'component--coordinates-based-list', ], component_title: 'Events near you'|trans({}, {'context': 'Helsinki near you'}), component_description: 'Browse events near you, sorted by their start time'|trans({}, {'context': 'Helsinki near you'}), @@ -57,6 +57,7 @@ %} {% block component_content %} {# Hook React app to this div #} + {{ attach_library('hdbt/event-list') }} diff --git a/public/themes/custom/hdbt_subtheme/translations/fi.po b/public/themes/custom/hdbt_subtheme/translations/fi.po index 0143fc1ea..ac8269f04 100644 --- a/public/themes/custom/hdbt_subtheme/translations/fi.po +++ b/public/themes/custom/hdbt_subtheme/translations/fi.po @@ -25,6 +25,22 @@ msgctxt "Services close to you block" msgid "Services close to you" msgstr "Palvelut lähelläsi" +msgctxt "News close to you block" +msgid "News close to you" +msgstr "Uutisia läheltäsi" + +msgctxt "News close to you block" +msgid " and " +msgstr " ja " + +msgctxt "News close to you block" +msgid "Check out the news from the neighborhoods of %neighbourhoods%" +msgstr "Katso uutisia kaupunginosista %neighbourhoods%" + +msgctxt "News close to you block" +msgid "View all news" +msgstr "Katso kaikki uutiset" + msgctxt "Services close to you block" msgid "Use the links to go to results based on your address." msgstr "Siirry linkeistä oman osoitteesi mukaisiin hakutuloksiin." diff --git a/public/themes/custom/hdbt_subtheme/translations/sv.po b/public/themes/custom/hdbt_subtheme/translations/sv.po index 7aec2f489..ad6a41a3d 100644 --- a/public/themes/custom/hdbt_subtheme/translations/sv.po +++ b/public/themes/custom/hdbt_subtheme/translations/sv.po @@ -25,6 +25,22 @@ msgctxt "Services close to you block" msgid "Services close to you" msgstr "Tjänster nära dig" +msgctxt "News close to you block" +msgid "News close to you" +msgstr "Nyheter nära dig" + +msgctxt "News close to you block" +msgid " and " +msgstr " och " + +msgctxt "News close to you block" +msgid "Check out the news from the neighborhoods of %neighbourhoods%" +msgstr "Kolla in nyheterna från stadsdelarna %neighbourhoods%" + +msgctxt "News close to you block" +msgid "View all news" +msgstr "Se alla nyheter" + msgctxt "Services close to you block" msgid "Use the links to go to results based on your address." msgstr "Använd länkarna för att visa resultat baserat på din adress." From c918ab589c17f1ebeb23d5e32eea5d2b42f2cd23 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Mon, 20 Jan 2025 14:10:16 +0200 Subject: [PATCH 6/7] UHF-11002: Fix typo --- public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php b/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php index 71ade3560..898f37d96 100644 --- a/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php +++ b/public/modules/custom/helfi_etusivu/helfi_etusivu.deploy.php @@ -2,7 +2,7 @@ /** * @file - * Contains etusivu deployo hooks. + * Contains etusivu deploy hooks. */ declare(strict_types=1); From 4c2b7155005d290de419b274f0a200c39bdf2bf9 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Tue, 21 Jan 2025 10:24:35 +0200 Subject: [PATCH 7/7] UHF-11002: Resolve conflict --- ...ities.external_entity_type.helfi_news_neighbourhoods.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml b/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml index 8d66af388..3138c7482 100644 --- a/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml +++ b/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml @@ -3,13 +3,13 @@ langcode: en status: true dependencies: { } _core: - default_config_hash: 5s8g-adBsUuIIMte5BCEwSFlQjxwFJ_Gq2Do7EEwq2E + default_config_hash: 09-lIa9cl9PNPVIBXCVIR8yBfofPifSwhAsD0QVh8l8 id: helfi_news_neighbourhoods label: 'Helfi: News neighbourhoods' label_plural: 'Helfi: News neighbourhoods' description: 'Retrieves news neighbourhoods taxonomy terms from Helfi' -read_only: true generate_aliases: null +read_only: true field_mapper_id: jsonpath field_mapper_config: field_mappings: @@ -22,7 +22,7 @@ field_mapper_config: tid: value: '$._source.tid[0]' location: - value: '$._source.field_location' + value: $._source.field_location storage_client_id: helfi_news_neighbourhoods storage_client_config: { } persistent_cache_max_age: 86400