Skip to content

Commit

Permalink
Merge pull request #334 from City-of-Helsinki/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
khalima authored Oct 25, 2023
2 parents 56b705e + d24f1b6 commit 0c1752b
Show file tree
Hide file tree
Showing 12 changed files with 561 additions and 154 deletions.
1 change: 1 addition & 0 deletions .platform/schema
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
"donatj/mock-webserver": "^2.4",
"drupal/coder": "^8.3",
"drupal/core-dev": "^9.5",
"mglaman/phpstan-drupal": "^1.0",
"jangregor/phpstan-prophecy": "^1.0",
"mglaman/phpstan-drupal": "^1.2",
"phpspec/prophecy-phpunit": "^2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^9.6",
"weitzman/drupal-test-traits": "^2.0"
},
Expand Down
435 changes: 289 additions & 146 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ id: helfi_announcements
label: 'Helfi: Announcements'
label_plural: 'Helfi: Announcements'
description: ''
generate_aliases: null
read_only: true
generate_aliases: null
field_mapper_id: jsonpath
field_mapper_config:
field_mappings:
Expand Down
1 change: 0 additions & 1 deletion conf/cmi/user.role.admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ permissions:
- 'administer blocks'
- 'administer eu cookie compliance categories'
- 'administer eu cookie compliance popup'
- 'administer hotjar settings'
- 'administer menu'
- 'administer nodes'
- 'administer paragraphs library'
Expand Down
1 change: 1 addition & 0 deletions conf/cmi/views.view.editoria11y_dismissals.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
uuid: 05cadc7a-3c09-43b9-9a6d-be2b1159da7e
langcode: en
status: true
dependencies:
Expand Down
1 change: 1 addition & 0 deletions conf/cmi/views.view.editoria11y_results.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
uuid: bac64670-e014-40fa-8ca9-8fe22219c020
langcode: en
status: true
dependencies:
Expand Down
46 changes: 45 additions & 1 deletion conf/cmi/views.view.job_listing_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,44 @@ display:
label: ''
field_identifier: ''
exposed: false
arguments: { }
arguments:
field_task_area_target_id:
id: field_task_area_target_id
table: node__field_task_area
field: field_task_area_target_id
relationship: none
group_type: group
admin_label: ''
plugin_id: numeric
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: query_parameter
default_argument_options:
query_param: task_areas
fallback: all
multiple: and
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
override: false
items_per_page: 25
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
filters:
status:
id: status
Expand All @@ -182,6 +219,7 @@ display:
plugin_id: bundle
value:
job_listing: job_listing
group: 1
expose:
operator_limit_selection: false
operator_list: { }
Expand Down Expand Up @@ -227,6 +265,10 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
filter_groups:
operator: AND
groups:
1: AND
style:
type: default
row:
Expand All @@ -251,6 +293,7 @@ display:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
Expand All @@ -267,6 +310,7 @@ display:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
# Optionally, you can add this to your default environments variables to enable or disable
# xdebug by default (like /etc/environments, ~/.bashrc, or ~/.zshrc).
XDEBUG_ENABLE: "${XDEBUG_ENABLE:-false}"
XDEBUG_CONFIG: "${XDEBUG_CONFIG:-}"
PHP_IDE_CONFIG: "${PHP_IDE_CONFIG:-serverName=${DRUPAL_HOSTNAME}}"
# DOCKERHOST: host.docker.internal
# Use drush server to run functional tests, so we don't have to care about
# permission or SSL issues.
Expand Down Expand Up @@ -121,7 +123,7 @@ services:
container_name: "${COMPOSE_PROJECT_NAME}-artemis"
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_EXTRA_ARGS: "--nio --user admin --password admin"
AMQ_EXTRA_ARGS: "--user admin --password admin"
depends_on:
- app
networks:
Expand Down
131 changes: 131 additions & 0 deletions public/modules/custom/helfi_rekry_content/helfi_rekry_content.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ declare(strict_types = 1);

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\helfi_rekry_content\Entity\JobListing;
use Drupal\media\OEmbed\ProviderException;
use Drupal\media\OEmbed\ResourceException;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\node\NodeInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;

/**
* Implements hook_entity_bundle_info_alter().
*/
function helfi_rekry_content_entity_bundle_info_alter(array &$bundles): void {
if (isset($bundles['node']['job_listing'])) {
$bundles['node']['job_listing']['class'] = JobListing::class;
}
}

/**
* Implements hook_form_FORM_ID_alter().
Expand Down Expand Up @@ -436,3 +449,121 @@ function helfi_rekry_content_preprocess_block(&$variables) {
$first_paragraph_gray = 'has-first-gray-bg-block';
}
}

/**
* Implements hook_views_query_alter().
*/
function helfi_rekry_content_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ($view->id() !== 'job_listing_search') {
return;
}

if (!isset($query->where[0]["conditions"][0])) {
return;
}

$task_area_external_id = $query
->where[0]["conditions"][0]["value"][":node__field_task_area_field_task_area_target_id"];

if (!$task_area_external_id) {
return;
}

/** @var \Drupal\taxonomy\Entity\Term $term */
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties(['field_external_id' => $task_area_external_id]);
if (!$terms) {
return;
}

$term = reset($terms);
$query->where[0]["conditions"][0]["value"][":node__field_task_area_field_task_area_target_id"] = $term->id();
}

/**
* Implements hook_page_attachments().
*/
function helfi_rekry_content_page_attachments(array &$attachments) : void {

// Get current entity and entity version.
$entity_matcher = \Drupal::service('helfi_platform_config.entity_version_matcher')->getType();

/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $entity_matcher['entity'];

// No need to continue if entity is not job listing.
if (!$entity instanceof JobListing) {
return;
}

/** @var \Drupal\helfi_rekry_content\Entity\JobListing $job_listing */
$job_listing = $entity;

/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = Drupal::service('date.formatter');

$publication_starts_datetime = $job_listing->get('field_publication_starts')->date->getTimestamp();
$publication_starts_formatted = $date_formatter->format($publication_starts_datetime, 'html_date');

/** @var Drupal\Core\Extension\ThemeHandler $theme_handler */
$theme_handler = Drupal::service('theme_handler');

// Get the default share image as structured data logo.
if ($theme_handler->themeExists('hdbt')) {
$theme = $theme_handler->getTheme('hdbt');
$current_language = \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
$logo_file_name = $current_language === 'sv' ? 'og-global-sv.png' : 'og-global.png';

/** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
$file_url_generator = \Drupal::service('file_url_generator');
$logo_image_url = $file_url_generator->generate("{$theme->getPath()}/src/images/{$logo_file_name}")
->setAbsolute()
->toString();
}

$structured_data = json_encode([
'@context' => 'https://schema.org/',
'@type' => 'JobPosting',
'title' => $job_listing->getTitle(),
'description' => $job_listing->getJobDescription(),
'identifier' => [
'@type' => 'PropertyValue',
'name' => t('City of Helsinki'),
'value' => $job_listing->get('field_recruitment_id')->value,
],
'datePosted' => $publication_starts_formatted,
'validThrough' => $job_listing->get('field_publication_ends')->value,
'employmentType' => $job_listing->getEmploymentType(),
'hiringOrganization' => [
'@type' => 'Organization',
'name' => $job_listing->getOrganizationName(),
'sameAs' => 'https://hel.fi/',
'logo' => $logo_image_url,
],
'jobLocation' => [
'@type' => 'Place',
'address' => [
'@type' => 'PostalAddress',
'streetAddress' => $job_listing->get('field_address')->value,
'addressRegion' => $job_listing->get('field_postal_area')->value,
'postalCode' => $job_listing->get('field_postal_code')->value,
'addressCountry' => t('Finland'),
],
],
]);

if (array_key_exists('#attached', $attachments)) {
$attachments['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'type' => 'application/ld+json',
],
'#value' => $structured_data,
],
'structured_job_listing_data',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Drupal\helfi_rekry_content\Entity;

use Drupal\node\Entity\Node;

/**
* Bundle class for hel_map paragraph.
*/
class JobListing extends Node {

/**
* Get job description or override value.
*
* @return string
* Job description.
*/
public function getJobDescription() : string {
return $this->get('field_job_description_override')->value ?: $this->get('job_description')->value;
}

/**
* Get translated organization name if available or override value.
*
* @return string
* Organization name.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
public function getOrganizationName() : string {
if (!$this->get('field_organization_override')->first()) {
return $this->get('field_organization_name')->value;
}

$storage = $this->entityTypeManager()
->getStorage('taxonomy_term');

$organization_entity = $storage->load($this->get('field_organization_override')->first()->target_id);

if (!$organization_entity->hasTranslation($this->get('langcode')->value)) {
return $organization_entity->getName();
}

$translated_organization_entity = $organization_entity->getTranslation($this->get('langcode')->value);
return $translated_organization_entity->getName();
}

/**
* Get translated employment type if available.
*
* @return string
* Employment type.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
public function getEmploymentType() : string {
if (!$this->get('field_employment_type')->first()) {
return '';
}

$storage = $this->entityTypeManager()
->getStorage('taxonomy_term');

$employment_type_entity = $storage->load($this->get('field_employment_type')->first()->target_id);

if (!$employment_type_entity->hasTranslation($this->get('langcode')->value)) {
return $employment_type_entity->getName();
}

$translated_employment_type_entity = $employment_type_entity->getTranslation($this->get('langcode')->value);
return $translated_employment_type_entity->getName();

}

}
5 changes: 5 additions & 0 deletions tools/make/project/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ endif
DRUPAL_POST_INSTALL_TARGETS := drush-deploy drush-locale-update drush-uli

OC_LOGIN_TOKEN ?= $(shell bash -c 'read -s -p "You must obtain an API token by visiting https://oauth-openshift.apps.arodevtest.hel.fi/oauth/token/request (Token):" token; echo $$token')

SYNC_TARGETS := drush-sync-db

ifneq ($(DUMP_SQL_EXISTS),yes)
SYNC_TARGETS := oc-login oc-sync
endif

PHONY += oc-login
oc-login:
Expand Down

0 comments on commit 0c1752b

Please sign in to comment.