From 1ee17070c3ac0c6edf311c3a435570ae3e7d0cb8 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Fri, 12 Jul 2024 15:23:28 +0300 Subject: [PATCH 01/15] initial commit for the fix. Recursively find the parameters from the array tree --- .../HelfiHakuvahtiSubscribeController.php | 72 ++++++++++++++++--- .../custom/helfi_hakuvahti/translations/fi.po | 21 ++++++ 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index f157ff7d..fa98df22 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -153,21 +153,31 @@ private function getSearchDescriptionTaxonomies($obj): string { $taxonomyIds = []; $elasticQuery = base64_decode($obj->elastic_query); - $elasticQueryObject = json_decode($elasticQuery); + $queryAsArray = json_decode($elasticQuery, TRUE); // Free text search. - $query = $elasticQueryObject->query->bool->must[1]->bool->should[1]->combined_fields->query ?? NULL; + if ( + $this->queryContains('combined_fields', $elasticQuery) && + $combinedFields = $this->sliceTree($queryAsArray['query']['bool']['must'], 'combined_fields') + ) { + $query = $combinedFields['query']; + } - // Ammattiala / Task area. - $externalTaxonomyIds = array_merge($taxonomyIds, $elasticQueryObject->query->bool->must[2]->terms->task_area_external_id ?? []); - if (!empty($externalTaxonomyIds)) { - $terms = $this->getLabelsByExternalId($externalTaxonomyIds, $obj->lang); + $taskAreaField = 'task_area_external_id'; + if ( + $this->queryContains($taskAreaField, $elasticQuery) && + $taskAreaIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $taskAreaField) + ) { + $terms = $this->getLabelsByExternalId($taskAreaIds, $obj->lang); } - // Type of employment. - $taxonomyIds = array_merge($taxonomyIds, $elasticQueryObject->query->bool->must[3]->bool->should[1]->terms->employment_type_id ?? []); - if (!empty($taxonomyIds)) { - $employmentTermLabels = $this->getLabelsByTermIds($taxonomyIds, $obj->lang); + + $employmentTypeField = 'employment_type_id'; + if ( + $this->queryContains($employmentTypeField, $elasticQuery) && + $employmentIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $employmentTypeField) + ) { + $employmentTermLabels = $this->getLabelsByTermIds($employmentIds, $obj->lang); } // Job location: @@ -265,4 +275,46 @@ public function post(): JsonResponse { } } + /** + * Recursive function to get what we want from tree of arrays. + * + * @param $tree + * Array we are traversing. + * @param $needle + * What key are we looking for. + * + * @return false|array + * False or the array we are looking for. + */ + private function sliceTree($tree, $needle): false|array { + if (is_array($tree) && isset($tree[$needle])) return $tree[$needle]; + + $result = NULL; + foreach($tree as $branch) { + if (isset($branch[$needle])) return $branch[$needle]; + + $result = $this->sliceTree($branch, $needle); + if ($result) { + break; + } + } + + return $result ?? false; + } + + /** + * Check if the non-decoded query contains a specific string. + * + * @param string $term_name + * What are we looking for. + * @param string $query_string + * Where are we looking from. + * + * @return bool + * The string exists. + */ + private function queryContains(string $term_name, string $query_string): bool { + return str_contains($query_string, $term_name); + } + } diff --git a/public/modules/custom/helfi_hakuvahti/translations/fi.po b/public/modules/custom/helfi_hakuvahti/translations/fi.po index e2b023bc..03b99d0a 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/fi.po +++ b/public/modules/custom/helfi_hakuvahti/translations/fi.po @@ -65,3 +65,24 @@ msgstr "Vahvista hakuvahti" msgid "Are you sure you wish to delete the saved search?" msgstr "Haluatko varmasti poistaa hakuvahdin?" + +msgid "Central area" +msgstr "Keskinen alue" + +msgid "Eastern area" +msgstr "Itäinen alue" + +msgid "Southern area" +msgstr "Eteläinen alue" + +msgid "South-Eastern area" +msgstr "Kaakkoinen alue" + +msgid "Western area" +msgstr "Läntinen alue" + +msgid "Northern area" +msgstr "Pohjoinen alue" + +msgid "North-Eastern area" +msgstr "Luoteinen alue" From 02a52ae34d6b26551ad41fd202e1f85e5ddc47b5 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 07:20:26 +0300 Subject: [PATCH 02/15] added contexts --- public/modules/custom/helfi_hakuvahti/translations/fi.po | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/modules/custom/helfi_hakuvahti/translations/fi.po b/public/modules/custom/helfi_hakuvahti/translations/fi.po index 03b99d0a..8132a6b0 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/fi.po +++ b/public/modules/custom/helfi_hakuvahti/translations/fi.po @@ -66,23 +66,30 @@ msgstr "Vahvista hakuvahti" msgid "Are you sure you wish to delete the saved search?" msgstr "Haluatko varmasti poistaa hakuvahdin?" +msgctxt "Search filter option: Central area" msgid "Central area" msgstr "Keskinen alue" +msgctxt "Search filter option: Eastern area" msgid "Eastern area" msgstr "Itäinen alue" +msgctxt "Search filter option: Southern area" msgid "Southern area" msgstr "Eteläinen alue" +msgctxt "Search filter option: South-Eastern area" msgid "South-Eastern area" msgstr "Kaakkoinen alue" +msgctxt "Search filter option: Western area area" msgid "Western area" msgstr "Läntinen alue" +msgctxt "Search filter option: Northern area" msgid "Northern area" msgstr "Pohjoinen alue" +msgctxt "Search filter option: North-Eastern area" msgid "North-Eastern area" msgstr "Luoteinen alue" From 8b527dd90afdc7ef713d50c4cc00c459d491f5ee Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 11:00:15 +0300 Subject: [PATCH 03/15] refactored the controller. Added recursive array search to fix the problem with missing parameters in email title --- .../helfi_hakuvahti.services.yml | 10 + .../HelfiHakuvahtiSubscribeController.php | 351 +++++++++--------- 2 files changed, 186 insertions(+), 175 deletions(-) create mode 100644 public/modules/custom/helfi_hakuvahti/helfi_hakuvahti.services.yml diff --git a/public/modules/custom/helfi_hakuvahti/helfi_hakuvahti.services.yml b/public/modules/custom/helfi_hakuvahti/helfi_hakuvahti.services.yml new file mode 100644 index 00000000..08a54ade --- /dev/null +++ b/public/modules/custom/helfi_hakuvahti/helfi_hakuvahti.services.yml @@ -0,0 +1,10 @@ +services: + _defaults: + autoconfigure: true + autowire: true + + logger.channel.helfi_hakuvahti: + parent: logger.channel_base + arguments: ['helfi_hakuvahti'] + + Drupal\helfi_hakuvahti\HelfiHakuvahtiSubscribeController: ~ diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index fa98df22..e1b0ac1f 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -5,11 +5,12 @@ namespace Drupal\helfi_hakuvahti\Controller; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use GuzzleHttp\Client; +use Drupal\Core\Entity\EntityStorageInterface; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\RequestOptions; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Psr\Log\LoggerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; @@ -19,23 +20,134 @@ */ final class HelfiHakuvahtiSubscribeController extends ControllerBase { - use StringTranslationTrait; + private EntityStorageInterface $termStorage; /** * Constructor for the HelfiHakuvahtiSubscribeController class. * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The container. * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $_entityTypeManager - * The entity type manager. */ public function __construct( - protected ContainerInterface $container, protected RequestStack $requestStack, - protected EntityTypeManagerInterface $_entityTypeManager, - ) {} + private readonly ClientInterface $client, + #[Autowire(service: 'logger.channel.helfi_hakuvahti')] private readonly LoggerInterface $logger, + ) { + $this->termStorage = $this->entityTypeManager()->getStorage('taxonomy_term'); + } + + /** + * A method to handle the POST request for subscription. + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + * The JSON response based on the subscription request. + */ + public function post(): JsonResponse { + if (!$hakuvahtiServer = getenv('HAKUVAHTI_URL')) { + $this->logger->error('Hakuvahti is missing a required HAKUVAHTI_URL configuration.'); + return new JsonResponse(['success' => FALSE, 'error' => 'Unable to process the request.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $request = $this->requestStack->getCurrentRequest(); + $body = $request->getContent(FALSE); + $bodyObj = json_decode($body); + $bodyObj->search_description = $this->getSearchDescriptionTaxonomies($bodyObj); + + $token = $request->headers->get('token'); + + // @todo Validate token. + // + // Somehow, we would need to validate token from + // /session/token from react + // side, but there's just no way to match it at backend?! + // $csrfTokenService = $this->container->get('csrf_token'); + // $expectedToken = $csrfTokenService->get('session'); + // if ($this->csrfTokenService->validate($token, 'session') === FALSE) {}. + try { + $this->client->request('POST', "$hakuvahtiServer/subscription", [ + RequestOptions::JSON => $bodyObj, + RequestOptions::HEADERS => [ + 'token' => $token, + 'Content-Type' => 'application/json', + ], + ]); + } + catch (GuzzleException $e) { + $this->logger->error("Unable to send Hakuvahti-request - Code {$e->getCode()}: {$e->getMessage()}"); + return new JsonResponse(['success' => FALSE, 'error' => 'Error while handling the request.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return new JsonResponse(['success' => TRUE], Response::HTTP_OK); + } + + /** + * Retrieves search description taxonomies from the provided object. + * + * @param mixed $obj + * The object containing elastic query data. + * + * @return string + * The concatenated search description taxonomies. + */ + private function getSearchDescriptionTaxonomies(mixed $obj): string { + $terms = []; + $employmentTermLabels = []; + $areaFiltersTranslated = []; + $query = ''; + + $elasticQuery = base64_decode($obj->elastic_query); + $queryAsArray = json_decode($elasticQuery, TRUE); + + // Free text search. + if ( + $this->elasticQueryContains('combined_fields', $elasticQuery) && + $combinedFields = $this->sliceTree($queryAsArray['query']['bool']['must'], 'combined_fields') + ) { + $query = $combinedFields['query']; + } + + $taskAreaField = 'task_area_external_id'; + if ( + $this->elasticQueryContains($taskAreaField, $elasticQuery) && + $taskAreaIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $taskAreaField) + ) { + $terms = $this->getLabelsByExternalId($taskAreaIds, $obj->lang); + } + + $employmentTypeField = 'employment_type_id'; + if ( + $this->elasticQueryContains($employmentTypeField, $elasticQuery) && + $employmentIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $employmentTypeField) + ) { + $employmentTermLabels = $this->getLabelsByTermIds($employmentIds, $obj->lang); + } + + // Job location: + if ($area_filters = $this->extractQueryParameters($obj->query, 'area_filter')) { + foreach ($area_filters as $area) { + $areaFiltersTranslated[] = $this->translateAreaString($area, $obj->lang); + } + } + + $description = $this->buildDescription($query, $terms, $areaFiltersTranslated, $employmentTermLabels); + + return $description ? $description : '*'; + } + + /** + * Check if the non-decoded query contains a specific string. + * + * @param string $term_name + * What are we looking for. + * @param string $query_string + * Where are we looking from. + * + * @return bool + * The string exists. + */ + private function elasticQueryContains(string $term_name, string $query_string): bool { + return str_contains($query_string, $term_name); + } /** * Retrieves taxonomy labels by field_external_id values in a given language. @@ -48,9 +160,9 @@ public function __construct( * @return array * An array of taxonomy term labels in the specified language. */ - private function getLabelsByExternalId(array $external_ids, $language) { + private function getLabelsByExternalId(array $external_ids, string $language): array { $labels = []; - $terms = $this->_entityTypeManager->getStorage('taxonomy_term')->loadByProperties(['field_external_id' => $external_ids]); + $terms = $this->termStorage->loadByProperties(['field_external_id' => $external_ids]); foreach ($terms as $term) { $translated_term = $term->hasTranslation($language) ? $term->getTranslation($language) : $term; $labels[] = $translated_term->label(); @@ -69,9 +181,9 @@ private function getLabelsByExternalId(array $external_ids, $language) { * @return array * An array of taxonomy term labels in the specified language. */ - private function getLabelsByTermIds(array $term_ids, $language) { + private function getLabelsByTermIds(array $term_ids, string $language): array { $labels = []; - $terms = $this->_entityTypeManager->getStorage('taxonomy_term')->loadMultiple($term_ids); + $terms = $this->termStorage->loadMultiple($term_ids); foreach ($terms as $term) { $translated_term = $term->hasTranslation($language) ? $term->getTranslation($language) : $term; $labels[] = $translated_term->label(); @@ -80,25 +192,6 @@ private function getLabelsByTermIds(array $term_ids, $language) { return $labels; } - /** - * Function to get translated string in a given language. - * - * phpcs:ignore is used to mute error about string literals as there - * is no other way to do this translation. - * - * @param string $string - * The string to be translated. - * @param string $language - * The language code for the desired translation. - * - * @return string - * The translated string. - */ - private function translateString($string, $language) { - $translatedString = $this->t($string, [], ['langcode' => $language]); // @phpcs:ignore - return (string) $translatedString; - } - /** * Function to extract specific query parameters from a URL string. * @@ -110,7 +203,7 @@ private function translateString($string, $language) { * @return array * An array of values for the specified query parameter. */ - private function extractQueryParameters($url, $parameter) { + private function extractQueryParameters(string $url, string $parameter): array { $parsed_url = parse_url($url); $query = $parsed_url['query'] ?? ''; $query_parameters = []; @@ -140,157 +233,80 @@ private function extractQueryParameters($url, $parameter) { } /** - * Retrieves search description taxonomies from the provided object. + * Build description string out of search parameters. * - * @param mixed $obj - * The object containing elastic query data. + * @param string $query + * The search query from text field. + * @param array $terms + * Array of term values. + * @param array $areaFiltersTranslated + * Array of area labels. + * @param array $employmentTermLabels + * Array of employment terms. * * @return string - * The concatenated search description taxonomies. + * The description string. */ - private function getSearchDescriptionTaxonomies($obj): string { - $terms = []; - $taxonomyIds = []; - - $elasticQuery = base64_decode($obj->elastic_query); - - $queryAsArray = json_decode($elasticQuery, TRUE); - // Free text search. - if ( - $this->queryContains('combined_fields', $elasticQuery) && - $combinedFields = $this->sliceTree($queryAsArray['query']['bool']['must'], 'combined_fields') - ) { - $query = $combinedFields['query']; - } - - $taskAreaField = 'task_area_external_id'; - if ( - $this->queryContains($taskAreaField, $elasticQuery) && - $taskAreaIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $taskAreaField) - ) { - $terms = $this->getLabelsByExternalId($taskAreaIds, $obj->lang); - } - - - $employmentTypeField = 'employment_type_id'; - if ( - $this->queryContains($employmentTypeField, $elasticQuery) && - $employmentIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $employmentTypeField) - ) { - $employmentTermLabels = $this->getLabelsByTermIds($employmentIds, $obj->lang); - } + private function buildDescription(string $query, array $terms, array $areaFiltersTranslated, array $employmentTermLabels): string { + $description = $query; + $allTerms = array_merge($terms, $areaFiltersTranslated); - // Job location: - $area_filters = $this->extractQueryParameters($obj->query, 'area_filter'); - if (!empty($area_filters)) { - // Duplicated from react frondend for proper translation mapping. - $areasList = [ - 'eastern' => 'Eastern area', - 'central' => 'Central area', - 'southern' => 'Southern area', - 'southeastern' => 'South-Eastern area', - 'western' => 'Western area', - 'northern' => 'Northern area', - 'northeast' => 'North-Eastern area', - ]; - - foreach ($area_filters as $area) { - $areaFiltersTranslated[] = $this->translateString($areasList[$area], $obj->lang); - } - } - - // Build description string: - $description = ''; - - // Search term first. - $description .= $query; - - // All these can be printed out with , separator. - if (!empty($areaFiltersTranslated)) { - $allTerms = array_merge($terms, $areaFiltersTranslated); - } - - if (!empty($allTerms)) { - if (!empty($description)) { - $description .= ', '; - } - $description .= implode(', ', array_filter($allTerms)); - } + $description .= $allTerms ? ', ' : ''; + $description .= implode(', ', array_filter($allTerms)); // Employment label should use / instead of comma. - if (!empty($employmentTermLabels)) { - if (!empty($description)) { - $description .= ', '; - } - $description .= implode(' / ', $employmentTermLabels); - } - - // Backup description if no terms or keywords found, must return something. - if (empty($description)) { - '*'; - } + $description .= $employmentTermLabels ? ', ': ''; + $description .= implode(' / ', $employmentTermLabels); return $description; } /** - * A method to handle the POST request for subscription. + * Function to get translated string in a given language. * - * @return \Symfony\Component\HttpFoundation\JsonResponse - * The JSON response based on the subscription request. + * phpcs:ignore is used to mute error about string literals as there + * is no other way to do this translation. + * + * @param string $string + * The string to be translated. + * @param string $language + * The language code for the desired translation. + * + * @return string + * The translated string. */ - public function post(): JsonResponse { - $request = $this->requestStack->getCurrentRequest(); - $body = $request->getContent(FALSE); - $bodyObj = json_decode($body); - $bodyObj->search_description = $this->getSearchDescriptionTaxonomies($bodyObj); + private function translateAreaString(string $area, string $language): string { + $translatedString = match(true) { + $area == 'eastern' => $this->t('Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: Eastern area']), + $area == 'central' => $this->t('Central area', [], ['langcode' => $language, 'context' => 'Search filter option: Central area']), + $area == 'southern' => $this->t('Southern area', [], ['langcode' => $language, 'context' => 'Search filter option: Southern area']), + $area == 'southeastern' => $this->t('South-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: South-Eastern area']), + $area == 'western' => $this->t('Western area', [], ['langcode' => $language, 'context' => 'Search filter option: Western area']), + $area == 'northern' => $this->t('Northern area', [], ['langcode' => $language, 'context' => 'Search filter option: Northern area']), + $area == 'northeast' => $this->t('North-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: North-Eastern area']), + default => '', + }; - $token = $request->headers->get('token'); - - // FIXME: somehow, we would need to validate token from - // /session/token from react - // side, but there's just no way to match it at backend?! - // $csrfTokenService = $this->container->get('csrf_token'); - // $expectedToken = $csrfTokenService->get('session'); - // if ($this->csrfTokenService->validate($token, 'session') === FALSE) { - // - // }. - $client = new Client(); - $hakuvahtiServer = getenv('HAKUVAHTI_URL'); - $response = $client->request('POST', $hakuvahtiServer . '/subscription', [ - RequestOptions::JSON => $bodyObj, - RequestOptions::HEADERS => [ - 'token' => $token, - 'Content-Type' => 'application/json', - ], - ]); - - $statusCode = $response->getStatusCode(); - - if ($statusCode >= 200 && $statusCode < 300) { - return new JsonResponse(['success' => TRUE], Response::HTTP_OK); - } - else { - return new JsonResponse(['success' => FALSE, 'error' => $response->getBody()->getContents()], Response::HTTP_INTERNAL_SERVER_ERROR); - } + return (string) $translatedString; } /** - * Recursive function to get what we want from tree of arrays. + * Recursive function to get an array by key from a tree of arrays. * - * @param $tree + * @param mixed $tree * Array we are traversing. - * @param $needle - * What key are we looking for. + * @param string $needle + * The key we are looking for. * * @return false|array * False or the array we are looking for. */ - private function sliceTree($tree, $needle): false|array { + private function sliceTree(array $tree, string $needle): array { if (is_array($tree) && isset($tree[$needle])) return $tree[$needle]; $result = NULL; foreach($tree as $branch) { + if (!is_array($branch)) return []; if (isset($branch[$needle])) return $branch[$needle]; $result = $this->sliceTree($branch, $needle); @@ -299,22 +315,7 @@ private function sliceTree($tree, $needle): false|array { } } - return $result ?? false; - } - - /** - * Check if the non-decoded query contains a specific string. - * - * @param string $term_name - * What are we looking for. - * @param string $query_string - * Where are we looking from. - * - * @return bool - * The string exists. - */ - private function queryContains(string $term_name, string $query_string): bool { - return str_contains($query_string, $term_name); + return $result ?? []; } } From 355f279b5b747c16fd78dee2f484b03a7aa9f014 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 13:44:22 +0300 Subject: [PATCH 04/15] Added text when no search filters selected --- .../HelfiHakuvahtiSubscribeController.php | 21 ++++++++++--------- .../custom/helfi_hakuvahti/translations/fi.po | 4 ++++ .../custom/helfi_hakuvahti/translations/sv.po | 4 ++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index e1b0ac1f..7f395401 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -125,13 +125,13 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { // Job location: if ($area_filters = $this->extractQueryParameters($obj->query, 'area_filter')) { foreach ($area_filters as $area) { - $areaFiltersTranslated[] = $this->translateAreaString($area, $obj->lang); + $areaFiltersTranslated[] = $this->translateString($area, $obj->lang); } } $description = $this->buildDescription($query, $terms, $areaFiltersTranslated, $employmentTermLabels); - return $description ? $description : '*'; + return $description ?: $this->translateString('No search filters', $obj->lang); } /** @@ -275,15 +275,16 @@ private function buildDescription(string $query, array $terms, array $areaFilter * @return string * The translated string. */ - private function translateAreaString(string $area, string $language): string { + private function translateString(string $string, string $language): string { $translatedString = match(true) { - $area == 'eastern' => $this->t('Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: Eastern area']), - $area == 'central' => $this->t('Central area', [], ['langcode' => $language, 'context' => 'Search filter option: Central area']), - $area == 'southern' => $this->t('Southern area', [], ['langcode' => $language, 'context' => 'Search filter option: Southern area']), - $area == 'southeastern' => $this->t('South-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: South-Eastern area']), - $area == 'western' => $this->t('Western area', [], ['langcode' => $language, 'context' => 'Search filter option: Western area']), - $area == 'northern' => $this->t('Northern area', [], ['langcode' => $language, 'context' => 'Search filter option: Northern area']), - $area == 'northeast' => $this->t('North-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: North-Eastern area']), + $string == 'eastern' => $this->t('Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: Eastern area']), + $string == 'central' => $this->t('Central area', [], ['langcode' => $language, 'context' => 'Search filter option: Central area']), + $string == 'southern' => $this->t('Southern area', [], ['langcode' => $language, 'context' => 'Search filter option: Southern area']), + $string == 'southeastern' => $this->t('South-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: South-Eastern area']), + $string == 'western' => $this->t('Western area', [], ['langcode' => $language, 'context' => 'Search filter option: Western area']), + $string == 'northern' => $this->t('Northern area', [], ['langcode' => $language, 'context' => 'Search filter option: Northern area']), + $string == 'northeast' => $this->t('North-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: North-Eastern area']), + $string == 'No search filters' => $this->t('No search filters', [], ['langcode' => $language, 'context' => 'Hakuvahti empty filters']), default => '', }; diff --git a/public/modules/custom/helfi_hakuvahti/translations/fi.po b/public/modules/custom/helfi_hakuvahti/translations/fi.po index 8132a6b0..347ad12e 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/fi.po +++ b/public/modules/custom/helfi_hakuvahti/translations/fi.po @@ -93,3 +93,7 @@ msgstr "Pohjoinen alue" msgctxt "Search filter option: North-Eastern area" msgid "North-Eastern area" msgstr "Luoteinen alue" + +msgctxt "Hakuvahti empty filters" +msgid "No search filters" +msgstr "Ei hakuehtoja" diff --git a/public/modules/custom/helfi_hakuvahti/translations/sv.po b/public/modules/custom/helfi_hakuvahti/translations/sv.po index acd7651c..69c398cf 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/sv.po +++ b/public/modules/custom/helfi_hakuvahti/translations/sv.po @@ -65,3 +65,7 @@ msgstr "Bekräfta sökvakten" msgid "Are you sure you wish to delete the saved search?" msgstr "Är du säker på att du vill ta bort sökvakten?" + +msgctxt "Hakuvahti empty filters" +msgid "No search filters" +msgstr "Inga ansökningskriterier" From 2066e63514f04878c8f62a459e9903b2250f2fc2 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 14:24:44 +0300 Subject: [PATCH 05/15] code fixes --- .../HelfiHakuvahtiSubscribeController.php | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index 7f395401..8109dea6 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -25,8 +25,12 @@ final class HelfiHakuvahtiSubscribeController extends ControllerBase { /** * Constructor for the HelfiHakuvahtiSubscribeController class. * - * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * @param Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack. + * @param GuzzleHttp\ClientInterface $client + * The httpclient. + * @param Psr\Log\LoggerInterface $logger + * The logger. */ public function __construct( protected RequestStack $requestStack, @@ -255,7 +259,7 @@ private function buildDescription(string $query, array $terms, array $areaFilter $description .= implode(', ', array_filter($allTerms)); // Employment label should use / instead of comma. - $description .= $employmentTermLabels ? ', ': ''; + $description .= $employmentTermLabels ? ', ' : ''; $description .= implode(' / ', $employmentTermLabels); return $description; @@ -276,15 +280,24 @@ private function buildDescription(string $query, array $terms, array $areaFilter * The translated string. */ private function translateString(string $string, string $language): string { - $translatedString = match(true) { - $string == 'eastern' => $this->t('Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: Eastern area']), - $string == 'central' => $this->t('Central area', [], ['langcode' => $language, 'context' => 'Search filter option: Central area']), - $string == 'southern' => $this->t('Southern area', [], ['langcode' => $language, 'context' => 'Search filter option: Southern area']), - $string == 'southeastern' => $this->t('South-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: South-Eastern area']), - $string == 'western' => $this->t('Western area', [], ['langcode' => $language, 'context' => 'Search filter option: Western area']), - $string == 'northern' => $this->t('Northern area', [], ['langcode' => $language, 'context' => 'Search filter option: Northern area']), - $string == 'northeast' => $this->t('North-Eastern area', [], ['langcode' => $language, 'context' => 'Search filter option: North-Eastern area']), - $string == 'No search filters' => $this->t('No search filters', [], ['langcode' => $language, 'context' => 'Hakuvahti empty filters']), + $context = [ + 'langcode' => $language, + 'context' => '' + ]; + + $context = fn($context) => ['langcode' => $language, 'context' => "Search filter option: $context"]; + $translatedString = match(TRUE) { + $string == 'eastern' => $this->t('Eastern area', [], $context('Eastern area')), + $string == 'central' => $this->t('Central area', [], $context('Central area')), + $string == 'southern' => $this->t('Southern area', [], $context('Southern area')), + $string == 'southeastern' => $this->t('South-Eastern area', [], $context('South-Eastern area')), + $string == 'western' => $this->t('Western area', [], $context('Western area')), + $string == 'northern' => $this->t('Northern area', [], $context('Northern area')), + $string == 'northeast' => $this->t('North-Eastern area', [], $context('North-Eastern area')), + $string == 'No search filters' => $this->t( + string: 'No search filters', + options: ['langcode' => $language, 'context' => 'Hakuvahti empty filters'], + ), default => '', }; @@ -303,12 +316,18 @@ private function translateString(string $string, string $language): string { * False or the array we are looking for. */ private function sliceTree(array $tree, string $needle): array { - if (is_array($tree) && isset($tree[$needle])) return $tree[$needle]; + if (is_array($tree) && isset($tree[$needle])) { + return $tree[$needle]; + } $result = NULL; - foreach($tree as $branch) { - if (!is_array($branch)) return []; - if (isset($branch[$needle])) return $branch[$needle]; + foreach ($tree as $branch) { + if (!is_array($branch)) { + return []; + } + if (isset($branch[$needle])) { + return $branch[$needle]; + } $result = $this->sliceTree($branch, $needle); if ($result) { From 2e639240441e4ba3418e61b1eb148f30a6ea56f1 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 14:35:58 +0300 Subject: [PATCH 06/15] code fixes --- .../HelfiHakuvahtiSubscribeController.php | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index 8109dea6..cacb87a9 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -20,6 +20,11 @@ */ final class HelfiHakuvahtiSubscribeController extends ControllerBase { + /** + * The term storage. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ private EntityStorageInterface $termStorage; /** @@ -104,7 +109,7 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { // Free text search. if ( - $this->elasticQueryContains('combined_fields', $elasticQuery) && + str_contains('combined_fields', $elasticQuery) && $combinedFields = $this->sliceTree($queryAsArray['query']['bool']['must'], 'combined_fields') ) { $query = $combinedFields['query']; @@ -112,7 +117,7 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { $taskAreaField = 'task_area_external_id'; if ( - $this->elasticQueryContains($taskAreaField, $elasticQuery) && + str_contains($taskAreaField, $elasticQuery) && $taskAreaIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $taskAreaField) ) { $terms = $this->getLabelsByExternalId($taskAreaIds, $obj->lang); @@ -120,7 +125,7 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { $employmentTypeField = 'employment_type_id'; if ( - $this->elasticQueryContains($employmentTypeField, $elasticQuery) && + str_contains($employmentTypeField, $elasticQuery) && $employmentIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $employmentTypeField) ) { $employmentTermLabels = $this->getLabelsByTermIds($employmentIds, $obj->lang); @@ -138,21 +143,6 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { return $description ?: $this->translateString('No search filters', $obj->lang); } - /** - * Check if the non-decoded query contains a specific string. - * - * @param string $term_name - * What are we looking for. - * @param string $query_string - * Where are we looking from. - * - * @return bool - * The string exists. - */ - private function elasticQueryContains(string $term_name, string $query_string): bool { - return str_contains($query_string, $term_name); - } - /** * Retrieves taxonomy labels by field_external_id values in a given language. * @@ -295,8 +285,7 @@ private function translateString(string $string, string $language): string { $string == 'northern' => $this->t('Northern area', [], $context('Northern area')), $string == 'northeast' => $this->t('North-Eastern area', [], $context('North-Eastern area')), $string == 'No search filters' => $this->t( - string: 'No search filters', - options: ['langcode' => $language, 'context' => 'Hakuvahti empty filters'], + 'No search filters', options: ['language' => $language, 'context' => 'Hakuvahti empty filters',] ), default => '', }; From 3b84dfe1c4eb5e95d88a684cbdd2a0c6b0329aef Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 14:42:15 +0300 Subject: [PATCH 07/15] commas --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index cacb87a9..a7aba7ed 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -272,7 +272,7 @@ private function buildDescription(string $query, array $terms, array $areaFilter private function translateString(string $string, string $language): string { $context = [ 'langcode' => $language, - 'context' => '' + 'context' => '', ]; $context = fn($context) => ['langcode' => $language, 'context' => "Search filter option: $context"]; @@ -285,7 +285,7 @@ private function translateString(string $string, string $language): string { $string == 'northern' => $this->t('Northern area', [], $context('Northern area')), $string == 'northeast' => $this->t('North-Eastern area', [], $context('North-Eastern area')), $string == 'No search filters' => $this->t( - 'No search filters', options: ['language' => $language, 'context' => 'Hakuvahti empty filters',] + 'No search filters', options: ['language' => $language, 'context' => 'Hakuvahti empty filters'] ), default => '', }; From 68d538987670a135064604fd9df35fc9dd3caa2f Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 14:52:39 +0300 Subject: [PATCH 08/15] phpstan fixes --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index a7aba7ed..db49364e 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -6,6 +6,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\taxonomy\TermInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\RequestOptions; @@ -30,11 +31,11 @@ final class HelfiHakuvahtiSubscribeController extends ControllerBase { /** * Constructor for the HelfiHakuvahtiSubscribeController class. * - * @param Symfony\Component\HttpFoundation\RequestStack $requestStack + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack. - * @param GuzzleHttp\ClientInterface $client + * @param \GuzzleHttp\ClientInterface $client * The httpclient. - * @param Psr\Log\LoggerInterface $logger + * @param \Psr\Log\LoggerInterface $logger * The logger. */ public function __construct( @@ -158,6 +159,7 @@ private function getLabelsByExternalId(array $external_ids, string $language): a $labels = []; $terms = $this->termStorage->loadByProperties(['field_external_id' => $external_ids]); foreach ($terms as $term) { + assert($term instanceof TermInterface); $translated_term = $term->hasTranslation($language) ? $term->getTranslation($language) : $term; $labels[] = $translated_term->label(); } From 86dbea74a3abfe835612c03f3f6f8749f2bd6c04 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 15:00:45 +0300 Subject: [PATCH 09/15] phpstan fixes --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index db49364e..a31f0eef 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -181,6 +181,7 @@ private function getLabelsByTermIds(array $term_ids, string $language): array { $labels = []; $terms = $this->termStorage->loadMultiple($term_ids); foreach ($terms as $term) { + assert($term instanceof TermInterface); $translated_term = $term->hasTranslation($language) ? $term->getTranslation($language) : $term; $labels[] = $translated_term->label(); } @@ -298,16 +299,16 @@ private function translateString(string $string, string $language): string { /** * Recursive function to get an array by key from a tree of arrays. * - * @param mixed $tree + * @param array $tree * Array we are traversing. * @param string $needle * The key we are looking for. * - * @return false|array + * @return array * False or the array we are looking for. */ private function sliceTree(array $tree, string $needle): array { - if (is_array($tree) && isset($tree[$needle])) { + if (isset($tree[$needle])) { return $tree[$needle]; } From bca244d05053f80090259d860a8b40dd283aab9a Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 15:37:49 +0300 Subject: [PATCH 10/15] added compose override --- compose.override.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 compose.override.yaml diff --git a/compose.override.yaml b/compose.override.yaml new file mode 100644 index 00000000..a369c861 --- /dev/null +++ b/compose.override.yaml @@ -0,0 +1,7 @@ +services: + app: + environment: + HAKUVAHTI_URL: 'http://helfi-rekry.docker.so:3000' +networks: + hakuvahti-network: + external: true From 58e8e5e2bce04de47105d235f6a5c0f201c56db1 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 15:38:52 +0300 Subject: [PATCH 11/15] removed useless code --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index a31f0eef..efd7d486 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -273,11 +273,6 @@ private function buildDescription(string $query, array $terms, array $areaFilter * The translated string. */ private function translateString(string $string, string $language): string { - $context = [ - 'langcode' => $language, - 'context' => '', - ]; - $context = fn($context) => ['langcode' => $language, 'context' => "Search filter option: $context"]; $translatedString = match(TRUE) { $string == 'eastern' => $this->t('Eastern area', [], $context('Eastern area')), From f970786e4994e982a91cd0b241f1608570c02c15 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 15 Jul 2024 15:46:59 +0300 Subject: [PATCH 12/15] parameters in wrong order --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index efd7d486..0cd0ea56 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -110,15 +110,15 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { // Free text search. if ( - str_contains('combined_fields', $elasticQuery) && + str_contains($elasticQuery, 'combined_fields') && $combinedFields = $this->sliceTree($queryAsArray['query']['bool']['must'], 'combined_fields') ) { - $query = $combinedFields['query']; + $query = $combinedFields['query'] ?? ''; } $taskAreaField = 'task_area_external_id'; if ( - str_contains($taskAreaField, $elasticQuery) && + str_contains($elasticQuery, $taskAreaField) && $taskAreaIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $taskAreaField) ) { $terms = $this->getLabelsByExternalId($taskAreaIds, $obj->lang); @@ -126,7 +126,7 @@ private function getSearchDescriptionTaxonomies(mixed $obj): string { $employmentTypeField = 'employment_type_id'; if ( - str_contains($employmentTypeField, $elasticQuery) && + str_contains($elasticQuery, $employmentTypeField) && $employmentIds = $this->sliceTree($queryAsArray['query']['bool']['must'], $employmentTypeField) ) { $employmentTermLabels = $this->getLabelsByTermIds($employmentIds, $obj->lang); From f6b53061a17c6e6e7174e8f5eec66443b3f760f6 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Tue, 16 Jul 2024 12:11:52 +0300 Subject: [PATCH 13/15] swedish translations, fixed one bad translation --- .../custom/helfi_hakuvahti/translations/fi.po | 2 +- .../custom/helfi_hakuvahti/translations/sv.po | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/public/modules/custom/helfi_hakuvahti/translations/fi.po b/public/modules/custom/helfi_hakuvahti/translations/fi.po index 347ad12e..22d86991 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/fi.po +++ b/public/modules/custom/helfi_hakuvahti/translations/fi.po @@ -92,7 +92,7 @@ msgstr "Pohjoinen alue" msgctxt "Search filter option: North-Eastern area" msgid "North-Eastern area" -msgstr "Luoteinen alue" +msgstr "Koillinen alue" msgctxt "Hakuvahti empty filters" msgid "No search filters" diff --git a/public/modules/custom/helfi_hakuvahti/translations/sv.po b/public/modules/custom/helfi_hakuvahti/translations/sv.po index 69c398cf..626ec461 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/sv.po +++ b/public/modules/custom/helfi_hakuvahti/translations/sv.po @@ -69,3 +69,35 @@ msgstr "Är du säker på att du vill ta bort sökvakten?" msgctxt "Hakuvahti empty filters" msgid "No search filters" msgstr "Inga ansökningskriterier" + +msgctxt "Search filter option: Central area" +msgid "Central area" +msgstr "Mellersta området" + +msgctxt "Search filter option: Eastern area" +msgid "Eastern area" +msgstr "Östra området" + +msgctxt "Search filter option: Southern area" +msgid "Southern area" +msgstr "Södra området" + +msgctxt "Search filter option: South-Eastern area" +msgid "South-Eastern area" +msgstr "Sydöstra området" + +msgctxt "Search filter option: Western area area" +msgid "Western area" +msgstr "Västra området" + +msgctxt "Search filter option: Northern area" +msgid "Northern area" +msgstr "Norra området" + +msgctxt "Search filter option: North-Eastern area" +msgid "North-Eastern area" +msgstr "Nordöstra området" + +msgctxt "Hakuvahti empty filters" +msgid "No search filters" +msgstr "Ei hakuehtoja" From 9dcc2cc3c464a28e22757faac88f9bc5d837aba8 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Tue, 16 Jul 2024 12:15:23 +0300 Subject: [PATCH 14/15] bad logic caused extra comma, fixed the logic --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index 0cd0ea56..12a3bc2a 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -248,11 +248,11 @@ private function buildDescription(string $query, array $terms, array $areaFilter $description = $query; $allTerms = array_merge($terms, $areaFiltersTranslated); - $description .= $allTerms ? ', ' : ''; + $description .= $query ? ', ' : ''; $description .= implode(', ', array_filter($allTerms)); // Employment label should use / instead of comma. - $description .= $employmentTermLabels ? ', ' : ''; + $description .= $allTerms ? ', ' : ''; $description .= implode(' / ', $employmentTermLabels); return $description; From af2839c29a34821ec7b5c2a1ae5dc059e28f1d31 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Tue, 16 Jul 2024 12:52:56 +0300 Subject: [PATCH 15/15] wrong key in translations, removed duplicate translation --- .../src/Controller/HelfiHakuvahtiSubscribeController.php | 2 +- public/modules/custom/helfi_hakuvahti/translations/sv.po | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index 12a3bc2a..224ed581 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -283,7 +283,7 @@ private function translateString(string $string, string $language): string { $string == 'northern' => $this->t('Northern area', [], $context('Northern area')), $string == 'northeast' => $this->t('North-Eastern area', [], $context('North-Eastern area')), $string == 'No search filters' => $this->t( - 'No search filters', options: ['language' => $language, 'context' => 'Hakuvahti empty filters'] + 'No search filters', options: ['langcode' => $language, 'context' => 'Hakuvahti empty filters'] ), default => '', }; diff --git a/public/modules/custom/helfi_hakuvahti/translations/sv.po b/public/modules/custom/helfi_hakuvahti/translations/sv.po index 626ec461..86e478ff 100644 --- a/public/modules/custom/helfi_hakuvahti/translations/sv.po +++ b/public/modules/custom/helfi_hakuvahti/translations/sv.po @@ -97,7 +97,3 @@ msgstr "Norra området" msgctxt "Search filter option: North-Eastern area" msgid "North-Eastern area" msgstr "Nordöstra området" - -msgctxt "Hakuvahti empty filters" -msgid "No search filters" -msgstr "Ei hakuehtoja"