diff --git a/public/modules/custom/helfi_etusivu/helfi_etusivu.module b/public/modules/custom/helfi_etusivu/helfi_etusivu.module index b0273a5b8..133173a43 100644 --- a/public/modules/custom/helfi_etusivu/helfi_etusivu.module +++ b/public/modules/custom/helfi_etusivu/helfi_etusivu.module @@ -329,6 +329,7 @@ function helfi_etusivu_theme() : array { 'back_link_url' => NULL, 'coordinates' => NULL, 'title' => NULL, + 'service_groups' => 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 286aed5f5..0c74f1a5f 100644 --- a/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php +++ b/public/modules/custom/helfi_etusivu/src/Controller/HelsinkiNearYouResultsController.php @@ -7,6 +7,8 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; +use Drupal\helfi_etusivu\Enum\InternalSearchLink; +use Drupal\helfi_etusivu\Enum\ServiceMapLink; use Drupal\helfi_etusivu\Servicemap; use Drupal\helfi_react_search\LinkedEvents; use Symfony\Component\HttpFoundation\JsonResponse; @@ -36,6 +38,7 @@ public function __construct( * Returns a renderable array. * * @param \Symfony\Component\HttpFoundation\Request $request + * * The request. * * @return array @@ -49,12 +52,8 @@ public function content(Request $request) : array|RedirectResponse { $this->messenger()->addError($this->t('Please enter an address', [], ['context' => 'Helsinki near you'])); return $this->redirect('helfi_etusivu.helsinki_near_you'); } - - $addressData = $this->getCoordinates( - Xss::filter( - urldecode($address) - ) - ); + $address = Xss::filter($address); + $addressData = $this->getCoordinates(urldecode($address)); if (!$addressData) { $this->messenger()->addError( @@ -67,6 +66,8 @@ public function content(Request $request) : array|RedirectResponse { return $this->redirect('helfi_etusivu.helsinki_near_you'); } + $addressName = $this->resolveTranslation($addressData['address_translations']); + return [ '#attached' => [ 'drupalSettings' => [ @@ -92,13 +93,93 @@ public function content(Request $request) : array|RedirectResponse { '#cache' => [ 'contexts' => ['url.query_args:q'], ], - '#coordinates' => $addressData ? $addressData['coordinates'] : NULL, + '#coordinates' => $addressData['coordinates'], '#theme' => 'helsinki_near_you_results_page', '#title' => $this->t( 'Services, events and news near your address @address', - ['@address' => $addressData ? $this->resolveTranslation($addressData['address_translations']) : ''], + ['@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, + ), + ], + ], + ], + [ + '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('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', [], ['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', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::STREET_PARK_PROJECTS, $addressName), + ], + [ + 'link_label' => $this->t('Plans in process', [], ['context' => 'Helsinki near you']), + 'link_url' => $this->servicemap->getLink(ServiceMapLink::PLANS_IN_PROCESS, $addressName), + ], + ], + ], + ], ]; } @@ -171,4 +252,29 @@ protected function resolveTranslation(\stdClass $translations) : string { return $translations->{"$langcode"} ?? $translations->fi; } + /** + * Generate link to internal search with address param set. + * + * @param \Drupal\helfi_etusivu\Enum\InternalSearchLink $link + * Internal search link option. + * @param string $address + * Address param for the link. + * + * @return string + * The resulting link. + */ + protected function getInternalSearchLink( + InternalSearchLink $link, + string $address, + ) : string { + $langcode = $this->languageManager()->getCurrentLanguage()->getId(); + $query = ['address' => urlencode($address)]; + $url = Url::fromUri( + $link->getLinkTranslations()[$langcode], + ['query' => $query], + ); + + return $url->toString(); + } + } diff --git a/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php b/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php new file mode 100644 index 000000000..4165ebe84 --- /dev/null +++ b/public/modules/custom/helfi_etusivu/src/Enum/InternalSearchLink.php @@ -0,0 +1,62 @@ + [ + 'fi' => 'https://www.hel.fi/fi/sosiaali-ja-terveyspalvelut/terveydenhoito/terveysasemat', + 'sv' => 'https://www.hel.fi/sv/social-och-halsovardstjanster/halsovard/halsostationer', + 'en' => 'https://www.hel.fi/en/health-and-social-services/health-care/health-stations', + ], + InternalSearchLink::CHILD_HEALTH_STATIONS => [ + 'fi' => 'https://www.hel.fi/fi/sosiaali-ja-terveyspalvelut/lasten-ja-perheiden-palvelut/aitiys-ja-lastenneuvolat', + 'sv' => 'https://www.hel.fi/sv/social-och-halsovardstjanster/tjanster-for-barn-och-familjer/modra-och-barnradgivningarna', + 'en' => 'https://www.hel.fi/en/health-and-social-services/child-and-family-services/maternity-and-child-health-clinics', + ], + InternalSearchLink::SCHOOLS => [ + 'fi' => 'https://www.hel.fi/fi/kasvatus-ja-koulutus/perusopetus/peruskoulut', + 'sv' => 'https://www.hel.fi/sv/fostran-och-utbildning/grundlaggande-utbildning/grundskolor', + 'en' => 'https://www.hel.fi/en/childhood-and-education/basic-education/comprehensive-schools', + ], + InternalSearchLink::PLAYGROUNDS_FAMILY_HOUSES => [ + 'fi' => 'https://www.hel.fi/fi/kasvatus-ja-koulutus/leikkipuistot/leikkipuistot-ja-perhetalot', + 'sv' => 'https://www.hel.fi/sv/fostran-och-utbildning/lekparker/sok-lekparker-och-familjehus', + 'en' => 'https://www.hel.fi/en/childhood-and-education/playgrounds/find-playgrounds-and-family-houses', + ], + InternalSearchLink::DAYCARES => [ + 'fi' => 'https://www.hel.fi/fi/kasvatus-ja-koulutus/varhaiskasvatus/varhaiskasvatus-paivakodissa/etsi-kunnallisia-paivakoteja', + 'sv' => 'https://www.hel.fi/sv/fostran-och-utbildning/smabarnspedagogik/smabarnspedagogik-pa-daghem/sok-kommunala-daghem', + 'en' => 'https://www.hel.fi/en/childhood-and-education/early-childhood-education/early-childhood-education-in-daycare-centres/search-municipal-daycare-centres', + ], + InternalSearchLink::PLOWING_SCHEDULES => [ + 'fi' => 'https://www.hel.fi/fi/kaupunkiymparisto-ja-liikenne/kunnossapito/katujen-kunnossapito/katujen-talvikunnossapito', + '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', + ], + }; + } + +} diff --git a/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php b/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php new file mode 100644 index 000000000..53b2d3522 --- /dev/null +++ b/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php @@ -0,0 +1,31 @@ + 'eCBuut', + ServiceMapLink::CITYBIKE_STATIONS_STANDS => 'eCAduu', + ServiceMapLink::STREET_PARK_PROJECTS => 'eCBJGT', + ServiceMapLink::PLANS_IN_PROCESS => 'eCCv3K', + }; + } + +} diff --git a/public/modules/custom/helfi_etusivu/src/Servicemap.php b/public/modules/custom/helfi_etusivu/src/Servicemap.php index 7ffa7a1d1..bef3f60cc 100644 --- a/public/modules/custom/helfi_etusivu/src/Servicemap.php +++ b/public/modules/custom/helfi_etusivu/src/Servicemap.php @@ -6,6 +6,8 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Url; +use Drupal\helfi_etusivu\Enum\ServiceMapLink; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; use Psr\Log\LoggerInterface; @@ -17,11 +19,17 @@ final class Servicemap { /** - * API URL. + * API URL for querying data. * * @var string */ private const API_URL = 'https://api.hel.fi/servicemap/v2/search/'; + /** + * Site url for redirecting users. + * + * @var string + */ + private const SITE_URL = 'https://kartta.hel.fi/'; /** * Constructs a new instance. @@ -82,4 +90,33 @@ public function query(string $address, int $page_size = 1) : array { return $result->results; } + /** + * Generate link to servicemap view with predefined data visible. + * + * @param \Drupal\helfi_etusivu\Enum\ServiceMapLink $link + * Service map link option. + * @param string $address + * Address param for the link. + * + * @return string + * The resulting link. + */ + public function getLink(ServiceMapLink $link, string $address) : string { + $langcode = $this->languageManager->getCurrentLanguage()->getId(); + $query = [ + 'link' => $link->link(), + 'addresslocation' => Xss::filter($address), + 'setlanguage' => $langcode, + ]; + + $url = Url::fromUri( + self::SITE_URL, + [ + 'query' => $query, + ], + ); + + return $url->toString(); + } + } diff --git a/public/modules/custom/helfi_etusivu/translations/fi.po b/public/modules/custom/helfi_etusivu/translations/fi.po index b957d8669..81950ee59 100644 --- a/public/modules/custom/helfi_etusivu/translations/fi.po +++ b/public/modules/custom/helfi_etusivu/translations/fi.po @@ -100,3 +100,63 @@ msgstr "Tapahtumat lähelläsi" msgctxt "Helsinki near you" msgid "Browse events near you, sorted by their start time" msgstr "Tutustu tapahtumiin tapahtumisajan mukaisessa järjestyksessä." + +msgctxt "Helsinki near you" +msgid "Health is key" +msgstr "Hoida terveyttä" + +msgctxt "Helsinki near you" +msgid "Your own health station" +msgstr "Oma terveysasema" + +msgctxt "Helsinki near you" +msgid "Closest maternity and child health clinic" +msgstr "Lähin neuvola" + +msgctxt "Helsinki near you" +msgid "Grow and learn" +msgstr "Kasva ja opi" + +msgctxt "Helsinki near you" +msgid "Schools close to you" +msgstr "Lähikoulut" + +msgctxt "Helsinki near you" +msgid "Closest playgrounds and family houses" +msgstr "Lähimmät leikkipuistot ja perhetalot" + +msgctxt "Helsinki near you" +msgid "Closest daycare centres" +msgstr "Lähimmät päiväkodit" + +msgctxt "Helsinki near you" +msgid "Move around the city" +msgstr "Kulje kaupungissa" + +msgctxt "Helsinki near you" +msgid "Roadway ploughing schedule" +msgstr "Aurausaikataulu" + +msgctxt "Helsinki near you" +msgid "Roadworks and events on map" +msgstr "Katutyöt ja tapahtumat kartalla" + +msgctxt "Helsinki near you" +msgid "City bike stations" +msgstr "Kaupunkipyöräasemat ja pyörätelineet" + +msgctxt "Helsinki near you" +msgid "The city is developing" +msgstr "Kaupunki kehittyy" + +msgctxt "Helsinki near you" +msgid "Street and park development" +msgstr "Katu- ja puistohankkeet" + +msgctxt "Helsinki near you" +msgid "Plans in process" +msgstr "Valmisteilla oleva kaavat" + +msgctxt "Helsinki near you" +msgid "Please enter an address" +msgstr "Syötä osoite" diff --git a/public/modules/custom/helfi_etusivu/translations/sv.po b/public/modules/custom/helfi_etusivu/translations/sv.po index 569ed011c..9b41fea06 100644 --- a/public/modules/custom/helfi_etusivu/translations/sv.po +++ b/public/modules/custom/helfi_etusivu/translations/sv.po @@ -89,3 +89,63 @@ msgstr "Evenemang nära dig" msgctxt "Helsinki near you" msgid "Browse events near you, sorted by their start time" msgstr "Utforska evenemang i ordning efter deras starttid." + +msgctxt "Helsinki near you" +msgid "Health is key" +msgstr "Ta hand om din hälsa" + +msgctxt "Helsinki near you" +msgid "Your own health station" +msgstr "Din egen hälsostation" + +msgctxt "Helsinki near you" +msgid "Closest maternity and child health clinic" +msgstr "Närmaste mödra- och barnrådgivning" + +msgctxt "Helsinki near you" +msgid "Grow and learn" +msgstr "Väx och lär dig" + +msgctxt "Helsinki near you" +msgid "Schools close to you" +msgstr "Närliggande skolor" + +msgctxt "Helsinki near you" +msgid "Closest playgrounds and family houses" +msgstr "Närmaste lekparker och familjehus" + +msgctxt "Helsinki near you" +msgid "Closest daycare centres" +msgstr "Närmaste daghem" + +msgctxt "Helsinki near you" +msgid "Move around the city" +msgstr "Rör dig i staden" + +msgctxt "Helsinki near you" +msgid "Roadway ploughing schedule" +msgstr "Plogningstidtabell" + +msgctxt "Helsinki near you" +msgid "Roadworks and events on map" +msgstr "Vägarbeten och evenemang på kartan" + +msgctxt "Helsinki near you" +msgid "City bike stations" +msgstr "Stadscykelstationer och cykelställ" + +msgctxt "Helsinki near you" +msgid "The city is developing" +msgstr "Staden utvecklas" + +msgctxt "Helsinki near you" +msgid "Street and park development" +msgstr "Gatu- och parkområdesprojekt" + +msgctxt "Helsinki near you" +msgid "Plans in process" +msgstr "Pågående planeringsprojekt" + +msgctxt "Helsinki near you" +msgid "Please enter an address" +msgstr "Ange en adress" 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 62960b47c..6db6ffb17 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 @@ -16,10 +16,36 @@ } %} {% endblock component_content %} {% endembed %} + {% embed "@hdbt/misc/component.twig" with + { + component_classes: [ 'component--popular-services' ], + component_title: 'Services close to you'|t({}, {'context': 'Services close to you block'}), + component_description: 'Use the links to go to results based on your address.'|t({}, {'context': 'Services close to you block'}), + component_content_class: 'popular-services', + } + %} + {% block component_content %} + {% for service_group in service_groups %} + {% embed "@hdbt/misc/popular-service-item.twig" with { title: service_group.title } %} + {% block links %} + {% embed "@hdbt/misc/popular-service-links.twig" with { items: service_group.service_links } %} + {% block link %} + {% set link_attributes = { + 'class': [ + 'link__style--highlight', + ], + } %} + {{ link(item.link_label, item.link_url, link_attributes) }} + {% endblock %} + {% endembed %} + {% endblock links %} + {% endembed %} + {% endfor %} + {% endblock component_content %} + {% endembed %} {% embed "@hdbt/misc/component.twig" with { component_classes: [ - 'component--full-width', 'component--react-search', 'component--event-list', 'component--coordinates-based-event-list', diff --git a/public/themes/custom/hdbt_subtheme/translations/fi.po b/public/themes/custom/hdbt_subtheme/translations/fi.po index a59a5282f..0143fc1ea 100644 --- a/public/themes/custom/hdbt_subtheme/translations/fi.po +++ b/public/themes/custom/hdbt_subtheme/translations/fi.po @@ -20,3 +20,11 @@ msgstr "Syvenny ja inspiroidu" msgctxt "Front page news of interest title" msgid "You might be interested in" msgstr "Sinua voisi kiinnostaa" + +msgctxt "Services close to you block" +msgid "Services close to you" +msgstr "Palvelut lähelläsi" + +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 2d691694e..7aec2f489 100644 --- a/public/themes/custom/hdbt_subtheme/translations/sv.po +++ b/public/themes/custom/hdbt_subtheme/translations/sv.po @@ -20,3 +20,11 @@ msgstr "Läs mer och få inspiration" msgctxt "Front page news of interest title" msgid "You might be interested in" msgstr "Du kanske är intresserad av" + +msgctxt "Services close to you block" +msgid "Services close to you" +msgstr "Tjänster nära dig" + +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."