Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-7999: Move hardcoded search page node id to settings form. #202

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/cmi/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ignored_config_entities:
- 'eu_cookie_compliance.cookie_category*'
- hdbt_admin_tools.site_settings
- 'system.site:page.front'
- 'helfi_rekry_content.job_listings:search_page'
1 change: 1 addition & 0 deletions conf/cmi/helfi_rekry_content.job_listings.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
redirect_403: /job-listing-removed
city_description_title: 'City of Helsinki'
city_description_text: 'The City of Helsinki is actively promoting equality and non-discrimination and values the diversity of its personnel. We encourage applications from people of all ages and genders, as well as from people who belong to linguistic, cultural or other minorities.'
search_page: '2971'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ helfi_rekry_content.job_listings:
type: config_object
label: 'Job listings'
mapping:
search_page:
type: string
label: 'Search page node ID'
redirect_403:
type: path
label: 'Redirect 403 path'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\node\Entity\Node;
use Drupal\path_alias\AliasManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -72,6 +73,17 @@ protected function getEditableConfigNames() : array {
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$siteConfig = $this->config('helfi_rekry_content.job_listings');
$searchPage = Node::load($siteConfig->get('search_page'));
$form['job_listings']['search_page'] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#selection_settings' => [
'target_bundles' => ['landing_page', 'page'],
],
'#title' => $this->t('Job search page'),
'#default_value' => $searchPage,
'#description' => $this->t('Displayed after the related jobs block, for example.'),
];

$form['job_listings']['redirect_403'] = [
'#type' => 'textfield',
Expand Down Expand Up @@ -118,6 +130,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('helfi_rekry_content.job_listings')
->set('search_page', $form_state->getValue('search_page'))
->set('redirect_403', $form_state->getValue('redirect_403'))
->set('city_description_title', $form_state->getValue('city_description_title'))
->set('city_description_text', $form_state->getValue('city_description_text'))
Expand Down
12 changes: 9 additions & 3 deletions public/themes/custom/hdbt_subtheme/hdbt_subtheme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ function hdbt_subtheme_preprocess_block(&$variables) {
* Implements hook_preprocess_HOOK().
*/
function hdbt_subtheme_preprocess_block__views_block__of_interest(&$variables) {
// @todo Get the node id somehow else than hardcoded here (UHF-7999).
$alias = Url::fromRoute('entity.node.canonical', ['node' => 2971], ['absolute' => TRUE]);
$variables['related_jobs_link'] = $alias;
// 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 ($alias) {
$variables['related_jobs_link'] = $alias;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@
{% 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">{{ 'Find open jobs'|t({}, {'context': 'Related jobs button'}) }}</span>
{% endset %}
{% set link_attributes = {
'class': [
'hds-button',
'hds-button--primary',
],
} %}
{{ link(link_title, related_jobs_link, link_attributes) }}
{% if related_jobs_link %}
{{ link(link_title, related_jobs_link, link_attributes) }}
{% endif %}
{% endblock %}
</div>
</div>