Skip to content

Commit

Permalink
Merge pull request #328 from City-of-Helsinki/UHF-8703-add-task-area-…
Browse files Browse the repository at this point in the history
…link-to-job-listing

UHF-8703: Add task area link to job listing
  • Loading branch information
Jussiles authored Oct 2, 2023
2 parents 76f9f94 + a8f4194 commit 6ec2819
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
66 changes: 50 additions & 16 deletions public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand All @@ -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;
}
}
}

Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -162,25 +177,44 @@ 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);
}
}
}

/**
* 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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% block content %}
{{ content }}
{% set link_title %}
<span class="hds-button__label">{{ 'Find open jobs'|t({}, {'context': 'Related jobs button'}) }}</span>
<span class="hds-button__label">{{ 'See all task area jobs'|t({}, {'context': 'Related jobs button'}) }}</span>
{% endset %}
{% set link_attributes = {
'class': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*
Expand Down Expand Up @@ -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 },
] %}

Expand Down
7 changes: 5 additions & 2 deletions public/themes/custom/hdbt_subtheme/translations/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions public/themes/custom/hdbt_subtheme/translations/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6ec2819

Please sign in to comment.