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-9530: Linked events keywords #710

Merged
merged 9 commits into from
Mar 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- field.field.paragraph.event_list.field_event_list_title
- field.field.paragraph.event_list.field_event_location
- field.field.paragraph.event_list.field_event_time
- field.field.paragraph.event_list.field_filter_keywords
- field.field.paragraph.event_list.field_free_events
- field.field.paragraph.event_list.field_remote_events
- paragraphs.paragraphs_type.event_list
Expand Down Expand Up @@ -63,6 +64,16 @@ content:
settings:
display_label: true
third_party_settings: { }
field_filter_keywords:
type: entity_reference_autocomplete_tags
weight: 8
region: content
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
field_free_events:
type: boolean_checkbox
weight: 7
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
uuid: d3bdb49e-461c-4a0f-a88c-c34eb54f7101
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.linked_events_keywords.field_keyword_id
- taxonomy.vocabulary.linked_events_keywords
module:
- hdbt_admin_tools
- path
- readonly_field_widget
id: taxonomy_term.linked_events_keywords.default
targetEntityType: taxonomy_term
bundle: linked_events_keywords
mode: default
content:
description:
type: formatted_text_character_counter
weight: 0
region: content
settings:
counter_step: 160
counter_total: 200
rows: 5
placeholder: ''
third_party_settings: { }
field_keyword_id:
type: readonly_field_widget
weight: 101
region: content
settings:
label: above
formatter_type: null
formatter_settings: { }
show_description: false
third_party_settings: { }
langcode:
type: language_select
weight: 2
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
region: content
settings: { }
third_party_settings: { }
status:
type: boolean_checkbox
weight: 100
region: content
settings:
display_label: true
third_party_settings: { }
translation:
weight: 10
region: content
settings: { }
third_party_settings: { }
hidden: { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- field.field.paragraph.event_list.field_event_list_title
- field.field.paragraph.event_list.field_event_location
- field.field.paragraph.event_list.field_event_time
- field.field.paragraph.event_list.field_filter_keywords
- field.field.paragraph.event_list.field_free_events
- field.field.paragraph.event_list.field_remote_events
- paragraphs.paragraphs_type.event_list
Expand Down Expand Up @@ -61,6 +62,14 @@ content:
third_party_settings: { }
weight: 3
region: content
field_filter_keywords:
type: entity_reference_label
label: above
settings:
link: true
third_party_settings: { }
weight: 6
region: content
field_free_events:
type: boolean
label: above
Expand All @@ -83,3 +92,4 @@ content:
region: content
hidden:
field_api_url: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uuid: 19cd3ce0-e5a8-4db8-ab50-ae7bde5fa981
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.linked_events_keywords.field_keyword_id
- taxonomy.vocabulary.linked_events_keywords
module:
- text
id: taxonomy_term.linked_events_keywords.default
targetEntityType: taxonomy_term
bundle: linked_events_keywords
mode: default
content:
description:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
hidden:
field_keyword_id: true
langcode: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
uuid: 05609557-0317-49a6-b2dd-1e7a2e69c10b
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_filter_keywords
- paragraphs.paragraphs_type.event_list
- taxonomy.vocabulary.linked_events_keywords
id: paragraph.event_list.field_filter_keywords
field_name: field_filter_keywords
entity_type: paragraph
bundle: event_list
label: Topics
description: 'Select options for "filter by topic" filter. The filter is hidden if no keywords are selected.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
linked_events_keywords: linked_events_keywords
sort:
field: name
direction: asc
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uuid: f04d1d15-8a22-440d-aa3f-1af424df9124
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_keyword_id
- taxonomy.vocabulary.linked_events_keywords
id: taxonomy_term.linked_events_keywords.field_keyword_id
field_name: field_keyword_id
entity_type: taxonomy_term
bundle: linked_events_keywords
label: 'Keyword ID'
description: 'Linked events keyword id.'
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: 2950aba3-734a-4bd3-9791-775aceae8e5e
langcode: en
status: true
dependencies:
module:
- paragraphs
- taxonomy
id: paragraph.field_filter_keywords
field_name: field_filter_keywords
entity_type: paragraph
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: 8c76f060-07d3-4c16-b305-cc4ade3105a9
langcode: en
status: true
dependencies:
module:
- taxonomy
id: taxonomy_term.field_keyword_id
field_name: field_keyword_id
entity_type: taxonomy_term
type: string
settings:
max_length: 255
case_sensitive: false
is_ascii: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: Asiasanat
description: 'Valitse "suodata asiasanoilla" -suodattimen vaihtoehdot. Suodatinta ei näytetä jos ainuttakaan asiasanaa ei ole valittu.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
uuid: 757cd796-00f7-445a-907d-0977ffe099be
langcode: en
status: true
dependencies: { }
name: 'Linked Events Keywords'
vid: linked_events_keywords
description: 'Keywords from yso dataset.'
weight: 0
3 changes: 3 additions & 0 deletions modules/helfi_react_search/helfi_react_search.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ dependencies:
- 'drupal:language'
- 'drupal:link'
- 'drupal:text'
- 'drupal:taxonomy'
- 'drupal:migrate'
- 'helfi_platform_config:helfi_platform_config'
- 'readonly_field_widget:readonly_field_widget'
- 'paragraphs:paragraphs'
package: HELfi
'interface translation project': helfi_react_search
Expand Down
9 changes: 9 additions & 0 deletions modules/helfi_react_search/helfi_react_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ function helfi_react_search_update_9006() : void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_react_search');
}

/**
* UHF-9613: Linked events keywords.
*/
function helfi_react_search_update_9007() : void {
// Make sure the configurations are correctly installed.
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_react_search');
}
29 changes: 29 additions & 0 deletions modules/helfi_react_search/helfi_react_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

declare(strict_types=1);

use Drupal\helfi_react_search\Entity\EventList;

/**
* Implements hook_entity_bundle_info_alter().
*/
function helfi_react_search_entity_bundle_info_alter(array &$bundles): void {
if (isset($bundles['paragraph']['event_list'])) {
$bundles['paragraph']['event_list']['class'] = EventList::class;
}
}

/**
* Event count dropdown selectable values.
*
Expand Down Expand Up @@ -65,3 +76,21 @@ function helfi_react_search_theme(): array {
],
];
}

/**
* Lookup tid with keyword id.
*/
function _helfi_react_search_lookup_term_tid(string $keyword_id) {
$ids = \Drupal::entityQuery('taxonomy_term')
->condition('field_keyword_id', $keyword_id)
->range(0, 1)
->latestRevision()
->accessCheck(FALSE)
->execute();

if (!empty($ids)) {
return reset($ids);
}

return NULL;
}
25 changes: 25 additions & 0 deletions modules/helfi_react_search/migrations/linked_events_keywords.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
enforced:
module:
- helfi_react_search
id: linked_events_keywords
migration_tags:
- linked_events
label: 'Linked events: topics'
source:
plugin: linked_events_keywords
url: "https://api.hel.fi/linkedevents/v1/keyword/?data_source=yso&has_upcoming_events=True&page_size=100"
process:
tid:
- plugin: callback
callable: _helfi_react_search_lookup_term_tid
source: id
name: name
field_keyword_id: id
language: language
destination:
plugin: translatable_entity:taxonomy_term
default_bundle: linked_events_keywords
migration_dependencies: { }
40 changes: 40 additions & 0 deletions modules/helfi_react_search/src/Entity/EventList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_react_search\Entity;

use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;

/**
* Bundle class for Hero -paragraph.
*/
class EventList extends Paragraph implements ParagraphInterface {

/**
* Get list of enabled filter keywords.
*
* @param string $langcode
* Keyword translation langcode.
*
* @return \Drupal\taxonomy\TermInterface[]
* Enabled keyword.
*/
public function getFilterKeywords(string $langcode) : array {
$keywords = [];

/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $field_keywords */
$field_keywords = $this->get('field_filter_keywords');

/** @var \Drupal\taxonomy\TermInterface $term */
foreach ($field_keywords->referencedEntities() as $term) {
if ($term->hasTranslation($langcode)) {
$keywords[] = $term->getTranslation($langcode);
}
}

return $keywords;
}

}
3 changes: 2 additions & 1 deletion modules/helfi_react_search/src/LinkedEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ protected function setCache(string $id, $data) : void {
* Resulting api url with params a query string
*/
public function getEventsRequest(array $options = [], string $pageSize = '3') : string {
$url = Url::fromUri(self::API_URL . 'event');
// Linked events URLs should end with '/' (URLs without '/' are redirect).
$url = Url::fromUri(self::API_URL . 'event/');

$defaultOptions = [
'event_type' => 'General',
Expand Down
Loading
Loading