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/external_entities.external_entity_type.helfi_news_neighbourhoods.yml b/conf/cmi/external_entities.external_entity_type.helfi_news_neighbourhoods.yml index e7f668016..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: @@ -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/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 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: 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..898f37d96 --- /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(); + } + +} 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/.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 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') }}