Skip to content

Commit

Permalink
UHF-9946: Merge branch 'main' of https://github.com/City-of-Helsinki/…
Browse files Browse the repository at this point in the history
…drupal-hdbt into UHF-9946
  • Loading branch information
teroelonen committed Jun 20, 2024
2 parents 77d4dde + 49507f5 commit 057da89
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 357 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.14.0
20
2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hdbt.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ hyphenopoly:
- hdbt/hyphenopoly-loader

job-search:
version: 1.6
version: 1.8.0
js:
dist/js/job-search.min.js: {
preprocess: false
Expand Down
42 changes: 33 additions & 9 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ function hdbt_preprocess(&$variables): void {
}
}

// Hakuvahti server url, expose to react if it's enabled or not.
$hakuvahtiUrl = getenv('HAKUVAHTI_URL');
$variables['#attached']['drupalSettings']['helfi_react_search']['hakuvahti_url_set'] = !empty($hakuvahtiUrl);

// Required for allowing subtheming for HDBT theme.
$variables['active_theme'] = $active_theme = \Drupal::theme()->getActiveTheme()->getName();
$variables['theme_prefix'] = $active_theme !== 'hdbt' ? $active_theme : '';
Expand Down Expand Up @@ -1755,24 +1751,52 @@ function hdbt_preprocess_paragraph__job_search(array &$variables) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];
$paragraph_type = $paragraph->getType();
$language_manager = \Drupal::languageManager();
$langcode = $language_manager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();

if ($paragraph_type == 'job_search') {
if ($search_result_page_nid = $paragraph->get('field_job_search_result_page')->getString()) {
$entity = Node::load($search_result_page_nid);
$language = \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();

if ($entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
if ($entity->hasTranslation($langcode)) {
$entity = $entity->getTranslation($langcode);
}

$url = $entity->toUrl()->toString();
$variables['#attached']['drupalSettings']['helfi_rekry_job_search']['results_page_path'] = $url;
}
}

// Attach job search library.
$variables['#attached']['library'][] = 'hdbt/job-search';

// Hakuvahti server url, expose to react if it's enabled or not.
$hakuvahtiUrl = getenv('HAKUVAHTI_URL');
$variables['#attached']['drupalSettings']['helfi_react_search']['hakuvahti_url_set'] = !empty($hakuvahtiUrl);

// Hakuvahti TOS settings.
if (!empty($hakuvahtiUrl)) {
$tos_variables = [
'hakuvahti_tos_checkbox_label',
'hakuvahti_tos_link_text',
'hakuvahti_tos_link_url',
];

// Attempt to get the translated configuration.
$language = $language_manager->getLanguage($langcode);
$original_language = $language_manager->getConfigOverrideLanguage();
$language_manager->setConfigOverrideLanguage($language);
$config = \Drupal::config('helfi_rekry_content.job_listings');

foreach ($tos_variables as $tos_variable) {
$variables['#attached']['drupalSettings']['helfi_rekry_job_search'][$tos_variable] = $config->get($tos_variable) ?: 'undefined';
}

// Set the config back to the original language.
$language_manager->setConfigOverrideLanguage($original_language);
}
}

/**
Expand Down
Loading

0 comments on commit 057da89

Please sign in to comment.