Skip to content

Commit 88cf531

Browse files
Drupal 10 deprecation fixes
- Updated *.info.yml to be compatible with Drupal 10. - Replaced fully qualified class names with imported class names for improved readability. - Replaced deprecated jQuery $.once to pure javascript .once library. - Replaced deprecated hook_field_widget_form_alter() with hook_field_widget_single_element_form_alter() for more granular control over field widget form elements. - Replaced deprecated getVocabularyId() with bundle() for retrieving vocabulary IDs.
1 parent 0d1e2a9 commit 88cf531

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

finto_taxonomy.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Finto Taxonomy
22
type: module
33
core: 8.x
4+
core_version_requirement: ">=8"
45
package: Kirjastot.fi
56
description: "Integrate querying Finto vocabularies with taxonomy"
67
dependencies:

finto_taxonomy.libraries.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ kifiform-tags-plugin:
66
public/js/kifiform-tags-plugin.js: {}
77
dependencies:
88
- kifiform/autocomplete-tags
9+
- core/jquery
10+
- core/once

finto_taxonomy.module

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
34
use Drupal\Core\Entity\Element\EntityAutocomplete;
45
use Drupal\Core\Form\FormStateInterface;
56
use Drupal\finto_taxonomy\TaxonomyHelper;
@@ -8,7 +9,7 @@ use Drupal\finto_taxonomy\Element\EntityAutocomplete as FintoEntityAutocomplete;
89

910
use Drupal\finto_taxonomy\Plugin\LanguageNegotiation\AutoCompleteRoute;
1011

11-
function finto_taxonomy_field_widget_form_alter(array &$parent, FormStateInterface $form_state, $context) {
12+
function finto_taxonomy_field_widget_single_element_form_alter(array &$parent, FormStateInterface $form_state, $context) {
1213
// Autocomplete widget wraps the actual widgets inside a redundant array.
1314
if (empty($parent['target_id'])) {
1415
return;
@@ -21,7 +22,7 @@ function finto_taxonomy_field_widget_form_alter(array &$parent, FormStateInterfa
2122
$finto_tids = [];
2223

2324
foreach ($parent['target_id']['#default_value'] as $term) {
24-
if ($term->getVocabularyId() == $finto_vid) {
25+
if ($term->bundle() == $finto_vid) {
2526
$finto_tids[] = $term->id();
2627
}
2728
}
@@ -31,6 +32,6 @@ function finto_taxonomy_field_widget_form_alter(array &$parent, FormStateInterfa
3132
}
3233

3334
function finto_taxonomy_language_negotiation_info_alter(&$negotiation_info) {
34-
$method_id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::METHOD_ID;
35+
$method_id = LanguageNegotiationUrl::METHOD_ID;
3536
$negotiation_info[$method_id]['class'] = AutoCompleteRoute::class;
3637
}

public/js/kifiform-tags-plugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
(function($) {
22
"use strict";
33

4-
$("input.form-autocomplete")
5-
.once("finto-taxonomy-tag-insert")
4+
$(once("finto-taxonomy-tag-insert", "input.form-autocomplete"))
65
.on("kififormtaginsert", function(event, ui) {
76
var tids = ui.autocomplete[0].dataset.finto_taxonomyTerms.split(/,/);
87

0 commit comments

Comments
 (0)