Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions conf/cmi/language/fi/views.view.high_school_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ display:
advanced:
rewrite:
filter_rewrite_values: '- Kaikki - | Kaikki'
high_school_language:
advanced:
rewrite:
filter_rewrite_values: ''
block:
display_title: Lohko
display_options:
Expand All @@ -42,5 +46,8 @@ display:
study_programme_type_filter:
expose:
label: 'Yleislukio tai aikuislukio'
high_school_language:
expose:
label: Opetuskieli
entity_reference:
display_title: Entiteettiviittaus
7 changes: 7 additions & 0 deletions conf/cmi/language/sv/views.view.high_school_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ display:
advanced:
rewrite:
filter_rewrite_values: '- Alla - | Alla'
high_school_language:
advanced:
rewrite:
filter_rewrite_values: ''
block:
display_options:
filters:
Expand All @@ -34,3 +38,6 @@ display:
study_programme_type_filter:
expose:
label: 'Allmänt gymnasium eller vuxengymnasium'
high_school_language:
expose:
label: Undervisningsspråk
101 changes: 101 additions & 0 deletions conf/cmi/views.view.high_school_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,27 @@ display:
is_secondary: false
hide_label: false
field_classes: ''
high_school_language:
plugin_id: bef
advanced:
sort_options: false
sort_options_method: alphabetical_asc
sort_options_natural: true
rewrite:
filter_rewrite_values: ''
filter_rewrite_values_key: false
collapsible: false
collapsible_disable_automatic_open: false
open_by_default: false
is_secondary: false
hide_label: false
field_classes: ''
select_all_none: false
select_all_none_nested: false
display_inline: false
soft_limit: 0
soft_limit_label_less: 'Show less'
soft_limit_label_more: 'Show more'
access:
type: perm
options:
Expand Down Expand Up @@ -509,6 +530,46 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
high_school_language:
id: high_school_language
table: tpr_unit_field_data
field: high_school_language
relationship: none
group_type: group
admin_label: ''
entity_type: tpr_unit
plugin_id: high_school_language
operator: in
value: { }
group: 2
exposed: true
expose:
operator_id: high_school_language_op
label: 'Language of instruction'
description: ''
use_operator: false
operator: high_school_language_op
operator_limit_selection: false
operator_list: { }
identifier: language
required: false
remember: false
multiple: true
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
filter_groups:
operator: AND
groups:
Expand Down Expand Up @@ -772,6 +833,46 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
high_school_language:
id: high_school_language
table: tpr_unit_field_data
field: high_school_language
relationship: none
group_type: group
admin_label: ''
entity_type: tpr_unit
plugin_id: high_school_language
operator: in
value: { }
group: 2
exposed: true
expose:
operator_id: high_school_language_op
label: 'Language of instruction'
description: ''
use_operator: false
operator: high_school_language_op
operator_limit_selection: false
operator_list: { }
identifier: language
required: false
remember: false
multiple: true
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
filter_groups:
operator: AND
groups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ views.filter.study_programme_type_filter:
type: views.filter.in_operator
label: 'Allowed values'

# Schema definition for high school language filter.
views.filter.high_school_language:
type: views.filter.in_operator
label: 'Allowed languages'

Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ function helfi_kasko_content_views_data_alter(array &$data) {
'id' => 'study_programme_type_filter',
],
];

$data['tpr_unit_field_data']['high_school_language'] = [
'title' => t('High school language'),
'filter' => [
'title' => t('High school language'),
'help' => 'Filters high school units by language of instruction.',
'field' => 'id',
'id' => 'high_school_language',
],
];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_kasko_content\Plugin\views\filter;

use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\views\Plugin\views\query\Sql;
use Drupal\views\ViewExecutable;

/**
* Filter high school units by provided language.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("high_school_language")
*/
class HighSchoolLanguage extends InOperator {

/**
* Mapping of language codes to TPR unit entity IDs.
*/
private const LANGUAGE_UNIT_IDS = [
'fi' => [
15061,
30851,
30852,
30853,
30854,
30855,
30858,
30862,
30863,
30864,
30865,
73120,
],
'sv' => [7051, 6820, 6901],
'en' => [34442, 30863],
];

/**
* {@inheritdoc}
*
* @codeCoverageIgnore
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL): void {
parent::init($view, $display, $options);
$this->valueTitle = (string) $this->t('Allowed languages');
$this->definition['options callback'] = [$this, 'generateOptions'];
}

/**
* {@inheritdoc}
*/
public function query(): void {
if (empty($this->value)) {
return;
}

$unitIds = [];
foreach ($this->value as $langcode) {
if (isset(self::LANGUAGE_UNIT_IDS[$langcode])) {
$unitIds = array_merge($unitIds, self::LANGUAGE_UNIT_IDS[$langcode]);
}
}

if (empty($unitIds)) {
return;
}

assert($this->query instanceof Sql);
$this->query->addWhere($this->options['group'], 'tpr_unit_field_data.id', $unitIds, 'IN');
}

/**
* Generates options.
*
* @return string[]
* Available options for the filter.
*/
public function generateOptions(): array {
return [
'fi' => (string) $this->t('Finnish'),
'sv' => (string) $this->t('Swedish'),
'en' => (string) $this->t('English'),
];
}

}
Loading
Loading