diff --git a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme index f655d14a..66776f90 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,30 @@ 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 +59,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 +161,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 +177,36 @@ 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_term = $node->get('field_task_area')?->first()?->get('entity')?->getValue()) { + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + $variables['task_area_name'] = $task_area_term->label(); + + if ($task_area_term->hasTranslation($langcode)) { + $variables['task_area_name'] = $task_area_term->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_term->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 +214,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/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': [ 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 }, ] %} diff --git a/public/themes/custom/hdbt_subtheme/translations/fi.po b/public/themes/custom/hdbt_subtheme/translations/fi.po index 7f189071..6bfe1fe5 100644 --- a/public/themes/custom/hdbt_subtheme/translations/fi.po +++ b/public/themes/custom/hdbt_subtheme/translations/fi.po @@ -42,5 +42,8 @@ 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" + +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 8c89ce4e..5f5e27f0 100644 --- a/public/themes/custom/hdbt_subtheme/translations/sv.po +++ b/public/themes/custom/hdbt_subtheme/translations/sv.po @@ -42,5 +42,8 @@ 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" + +msgid "Task area" +msgstr "Bransch"