From 595d683d5772ce394f2d4c1c3bdcd5071a3fc8c2 Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 14:17:05 +0300 Subject: [PATCH 1/6] UHF-8703: add task area link to job listing. --- .../custom/hdbt_subtheme/hdbt_subtheme.theme | 60 ++++++++++++++----- .../layout/node--job-listing.html.twig | 5 +- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme index f655d14a..84b1a9b1 100644 --- a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme +++ b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme @@ -15,7 +15,7 @@ use Drupal\node\NodeInterface; /** * Implements hook_preprocess_HOOK(). */ -function hdbt_subtheme_preprocess_block(&$variables) { +function hdbt_subtheme_preprocess_block(&$variables): void { if (isset($variables['elements']['#id'])) { $variables['content']['#attributes']['block_id'] = $variables['elements']['#id']; } @@ -24,15 +24,27 @@ function hdbt_subtheme_preprocess_block(&$variables) { /** * Implements hook_preprocess_HOOK(). */ -function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables) { +function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables): void { // Get the search page nid from config. $config = \Drupal::config('helfi_rekry_content.job_listings'); $search_page_nid = $config->get('search_page'); - if ($search_page_nid) { - $alias = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], ['absolute' => TRUE]); + + if (!$search_page_nid) { + return; } - if ($alias) { - $variables['related_jobs_link'] = $alias; + + $node = \Drupal::routeMatch()->getParameter('node'); + if ($node->getType() !== 'job_listing') { + return; + } + + if ($task_area_term = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { + $options = ['query' => ['task_areas' => $task_area_term->get('field_external_id')->value], 'absolute' => TRUE]; + $alias = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); + + if ($alias) { + $variables['related_jobs_link'] = $alias; + } } } @@ -44,7 +56,7 @@ function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables) { * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ -function hdbt_subtheme_preprocess_organization_information_block(array &$variables) : void { +function hdbt_subtheme_preprocess_organization_information_block(array &$variables): void { $variables['view_mode'] = $variables['elements']['#view_mode']; // Helpful $content variable for template. @@ -146,7 +158,7 @@ function hdbt_subtheme_theme_suggestions_menu_alter(&$suggestions, $variables) { /** * Implements hook_preprocess_HOOK(). */ -function hdbt_subtheme_preprocess_page(&$variables) { +function hdbt_subtheme_preprocess_page(&$variables): void { // Handle sidebar visibility. $entity = hdbt_admin_tools_get_page_entity(); if ($entity instanceof NodeInterface) { @@ -162,17 +174,33 @@ function hdbt_subtheme_preprocess_page(&$variables) { /** * Implements hook_preprocess_node(). */ -function hdbt_subtheme_preprocess_node(&$variables) { +function hdbt_subtheme_preprocess_node(&$variables): void { $node = $variables['node']; - if ($node->getType() == 'job_listing') { - // Check if job listing publication starts today. - $variables['publication_starts_today'] = FALSE; + if ($node->getType() !== 'job_listing') { + return; + } + // Check if job listing publication starts today. + $variables['publication_starts_today'] = FALSE; + $publication_starts_value = $node->get('field_publication_starts')->value; - $publication_starts_value = $node->get('field_publication_starts')->value; + if ($publication_starts_value && date('Y-m-d', strtotime($publication_starts_value)) == date('Y-m-d')) { + $variables['publication_starts_today'] = TRUE; + } + + if ($task_area_terms = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + $variables['task_area_name'] = $task_area_terms->label(); + + if ($task_area_terms->hasTranslation($langcode)) { + $variables['task_area_name'] = $task_area_terms->getTranslation($langcode)->label(); + } - if ($publication_starts_value && date('Y-m-d', strtotime($publication_starts_value)) == date('Y-m-d')) { - $variables['publication_starts_today'] = TRUE; + // Get the search page nid from config. + $config = \Drupal::config('helfi_rekry_content.job_listings'); + if ($search_page_nid = $config->get('search_page')) { + $options = ['query' => ['task_areas' => $task_area_terms->get('field_external_id')->value], 'absolute' => TRUE]; + $variables['task_area_rekry_search_url'] = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); } } } @@ -180,7 +208,7 @@ function hdbt_subtheme_preprocess_node(&$variables) { /** * Implements hook_preprocess_HOOK(). */ -function hdbt_subtheme_preprocess_html(&$variables) { +function hdbt_subtheme_preprocess_html(&$variables): void { /** @var \Drupal\helfi_api_base\Environment\EnvironmentResolver $resolver */ $resolver = \Drupal::service('helfi_api_base.environment_resolver'); /** @var \Drupal\helfi_api_base\Environment\Environment $environment */ diff --git a/public/themes/custom/hdbt_subtheme/templates/layout/node--job-listing.html.twig b/public/themes/custom/hdbt_subtheme/templates/layout/node--job-listing.html.twig index 6e6258a7..f9f0436d 100644 --- a/public/themes/custom/hdbt_subtheme/templates/layout/node--job-listing.html.twig +++ b/public/themes/custom/hdbt_subtheme/templates/layout/node--job-listing.html.twig @@ -64,6 +64,8 @@ * is an administrator. * - publication_starts_today: Helper variable for displaying 'today' instead * of the actual timestamp if the job listing is published today. + * - task_area_name: Task area name for Rekry search link. + * - task_area_rekry_search_url: Rekry search url with task area url query param. * * @see template_preprocess_node() * @@ -136,8 +138,9 @@ { label: 'Application period ends'|t, icon: 'clock', content: content.field_publication_ends }, content.field_salary|render ? { label: 'Pay'|t, icon: 'glyph-euro', content: content.field_salary }, { label: 'Employment contract'|t, icon: 'calendar', content: content.field_job_duration }, - { label: 'Address'|t, icon: 'location', content: [content.field_address, content.field_postal_code, content.field_postal_area] }, { label: 'Published'|t, icon: 'calendar-clock', content: publication_starts }, + { label: 'Address'|t, icon: 'location', content: [content.field_address, content.field_postal_code, content.field_postal_area] }, + task_area_name is defined ? { label: 'Task area'|t, icon: 'occupation', content: task_area_rekry_search_url is defined ? link(task_area_name, task_area_rekry_search_url) : task_area_name }, { label: 'Job code'|t, icon: 'locate', content: content.field_recruitment_id }, ] %} From d3c1f439f7d4cf32f1315f0938b6a97a92549801 Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 14:17:38 +0300 Subject: [PATCH 2/6] UHF-8703: update see all related jobs link. --- .../templates/block/block--views-block--of-interest.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/themes/custom/hdbt_subtheme/templates/block/block--views-block--of-interest.html.twig b/public/themes/custom/hdbt_subtheme/templates/block/block--views-block--of-interest.html.twig index 331257a5..712436f2 100644 --- a/public/themes/custom/hdbt_subtheme/templates/block/block--views-block--of-interest.html.twig +++ b/public/themes/custom/hdbt_subtheme/templates/block/block--views-block--of-interest.html.twig @@ -41,7 +41,7 @@ {% block content %} {{ content }} {% set link_title %} - {{ 'Find open jobs'|t({}, {'context': 'Related jobs button'}) }} + {{ 'See all task area jobs'|t({}, {'context': 'Related jobs button'}) }} {% endset %} {% set link_attributes = { 'class': [ From d42d2dd5039cf16154dccfeca2044c6f3e0b522a Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 14:58:57 +0300 Subject: [PATCH 3/6] UHF-8703: update po-files for related jobs button. --- public/themes/custom/hdbt_subtheme/translations/fi.po | 4 ++-- public/themes/custom/hdbt_subtheme/translations/sv.po | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/themes/custom/hdbt_subtheme/translations/fi.po b/public/themes/custom/hdbt_subtheme/translations/fi.po index 7f189071..6de6a416 100644 --- a/public/themes/custom/hdbt_subtheme/translations/fi.po +++ b/public/themes/custom/hdbt_subtheme/translations/fi.po @@ -42,5 +42,5 @@ msgstr[0] "työpaikkailmoitus" msgstr[1] "työpaikkailmoitusta" msgctxt "Related jobs button" -msgid "Find open jobs" -msgstr "Etsi avoimia paikkoja" +msgid "See all task area jobs" +msgstr "Katso kaikki ammattialan tehtävät" diff --git a/public/themes/custom/hdbt_subtheme/translations/sv.po b/public/themes/custom/hdbt_subtheme/translations/sv.po index 8c89ce4e..e7946755 100644 --- a/public/themes/custom/hdbt_subtheme/translations/sv.po +++ b/public/themes/custom/hdbt_subtheme/translations/sv.po @@ -42,5 +42,5 @@ msgstr[0] "öppet jobbannons" msgstr[1] "öppna jobbannonser" msgctxt "Related jobs button" -msgid "Find open jobs" -msgstr "Sök lediga jobb" +msgid "See all task area jobs" +msgstr "Se alla job i branchen" From fb7103f0cbdeabade6ac224c20c248bf444cff03 Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 15:02:20 +0300 Subject: [PATCH 4/6] UHF-8703: add task area translation. --- public/themes/custom/hdbt_subtheme/translations/fi.po | 3 +++ public/themes/custom/hdbt_subtheme/translations/sv.po | 3 +++ 2 files changed, 6 insertions(+) diff --git a/public/themes/custom/hdbt_subtheme/translations/fi.po b/public/themes/custom/hdbt_subtheme/translations/fi.po index 6de6a416..6bfe1fe5 100644 --- a/public/themes/custom/hdbt_subtheme/translations/fi.po +++ b/public/themes/custom/hdbt_subtheme/translations/fi.po @@ -44,3 +44,6 @@ msgstr[1] "työpaikkailmoitusta" msgctxt "Related jobs button" msgid "See all task area jobs" msgstr "Katso kaikki ammattialan tehtävät" + +msgid "Task area" +msgstr "Ammattiala" diff --git a/public/themes/custom/hdbt_subtheme/translations/sv.po b/public/themes/custom/hdbt_subtheme/translations/sv.po index e7946755..5f5e27f0 100644 --- a/public/themes/custom/hdbt_subtheme/translations/sv.po +++ b/public/themes/custom/hdbt_subtheme/translations/sv.po @@ -44,3 +44,6 @@ msgstr[1] "öppna jobbannonser" msgctxt "Related jobs button" msgid "See all task area jobs" msgstr "Se alla job i branchen" + +msgid "Task area" +msgstr "Bransch" From 74e290da3c8f511f6728e74438ab44d1dffb24ac Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 15:07:46 +0300 Subject: [PATCH 5/6] UHF-8703: fix phpcs errors. --- .../custom/hdbt_subtheme/hdbt_subtheme.theme | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme index 84b1a9b1..2ac6862d 100644 --- a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme +++ b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme @@ -39,7 +39,10 @@ function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables): } if ($task_area_term = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { - $options = ['query' => ['task_areas' => $task_area_term->get('field_external_id')->value], 'absolute' => TRUE]; + $options = [ + 'query' => ['task_areas' => $task_area_term->get('field_external_id')->value], + 'absolute' => TRUE + ]; $alias = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); if ($alias) { @@ -188,18 +191,21 @@ function hdbt_subtheme_preprocess_node(&$variables): void { $variables['publication_starts_today'] = TRUE; } - if ($task_area_terms = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { + if ($task_area_term = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); - $variables['task_area_name'] = $task_area_terms->label(); + $variables['task_area_name'] = $task_area_term->label(); - if ($task_area_terms->hasTranslation($langcode)) { - $variables['task_area_name'] = $task_area_terms->getTranslation($langcode)->label(); + if ($task_area_term->hasTranslation($langcode)) { + $variables['task_area_name'] = $task_area_term->getTranslation($langcode)->label(); } // Get the search page nid from config. $config = \Drupal::config('helfi_rekry_content.job_listings'); if ($search_page_nid = $config->get('search_page')) { - $options = ['query' => ['task_areas' => $task_area_terms->get('field_external_id')->value], 'absolute' => TRUE]; + $options = [ + 'query' => ['task_areas' => $task_area_term->get('field_external_id')->value], + 'absolute' => TRUE + ]; $variables['task_area_rekry_search_url'] = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); } } From a8f41940a0b51e6ce4ee8bbaf63da15f9a7b2efc Mon Sep 17 00:00:00 2001 From: Jussi Leskinen Date: Fri, 29 Sep 2023 15:14:03 +0300 Subject: [PATCH 6/6] UHF-8703: fix phpcs errors. --- public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme index 2ac6862d..66776f90 100644 --- a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme +++ b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme @@ -41,7 +41,7 @@ function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables): if ($task_area_term = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { $options = [ 'query' => ['task_areas' => $task_area_term->get('field_external_id')->value], - 'absolute' => TRUE + 'absolute' => TRUE, ]; $alias = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); @@ -204,7 +204,7 @@ function hdbt_subtheme_preprocess_node(&$variables): void { if ($search_page_nid = $config->get('search_page')) { $options = [ 'query' => ['task_areas' => $task_area_term->get('field_external_id')->value], - 'absolute' => TRUE + 'absolute' => TRUE, ]; $variables['task_area_rekry_search_url'] = Url::fromRoute('entity.node.canonical', ['node' => $search_page_nid], $options); }