Skip to content

Commit 14251b3

Browse files
Merged in feature/BKL-93-RemoveIdFromAutocompleteInput (pull request #63)
Feature/BKL-93-RemoveIdFromAutocompleteInput
2 parents 8bcb3c8 + f02c6d3 commit 14251b3

File tree

6 files changed

+71
-17
lines changed

6 files changed

+71
-17
lines changed

config/sync/core.entity_form_display.node.os2loop_question.default.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,12 @@ content:
9292
weight: 8
9393
os2loop_shared_subject:
9494
settings:
95-
match_limit: '0'
96-
min_length: 0
97-
delimiter: ''
98-
not_found_message: 'The term ''@term'' will be added'
99-
no_empty_message: 'No terms could be found. Please type in order to add a new term.'
100-
not_found_message_allow: false
101-
new_terms: false
10295
match_operator: CONTAINS
103-
autocomplete_route_name: autocomplete_deluxe.autocomplete
96+
match_limit: 10
10497
size: 60
105-
selection_handler: default
98+
placeholder: ''
10699
third_party_settings: { }
107-
type: autocomplete_deluxe
100+
type: entity_reference_autocomplete
108101
region: content
109102
weight: 7
110103
os2loop_shared_tags:

config/sync/language/da/views.view.os2loop_search_db.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ display:
33
display_options:
44
pager:
55
options:
6-
tags:
7-
first: '« Første'
8-
last: 'Sidste »'
96
expose:
107
items_per_page_options_all_label: '- Alle -'
118
filters:

config/sync/views.view.os2loop_search_db.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ display:
5151
id: 0
5252
total_pages: null
5353
tags:
54-
previous: ‹‹
55-
next: ››
56-
first: '« First'
57-
last: 'Last »'
54+
previous: '<'
55+
next: '>'
56+
first: ''
57+
last: ''
5858
expose:
5959
items_per_page: false
6060
items_per_page_label: 'Items per page'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(function ($, Drupal) {
2+
'use strict';
3+
4+
/**
5+
* Remove entity reference ID from "entity_autocomplete" field.
6+
*
7+
* @type {{attach: Drupal.behaviors.autocompleteReferenceEntityId.attach}}
8+
*/
9+
Drupal.behaviors.autocompleteReferenceEntityId = {
10+
attach: function (context) {
11+
// Remove reference IDs for autocomplete elements on init.
12+
$('.form-autocomplete', context).once('replaceReferenceIdOnInit').each(function () {
13+
let splitValues = (this.value && this.value !== 'false') ?
14+
Drupal.autocomplete.splitValues(this.value) : [];
15+
16+
if (splitValues.length > 0) {
17+
let labelValues = [];
18+
for (let i in splitValues) {
19+
let value = splitValues[i].trim();
20+
let entityIdMatch = value.match(/\s*\((.*?)\)$/);
21+
if (entityIdMatch) {
22+
labelValues[i] = value.replace(entityIdMatch[0], '');
23+
}
24+
}
25+
26+
if (labelValues.length > 0) {
27+
$(this).data('real-value', splitValues.join(', '));
28+
this.value = labelValues.join(', ');
29+
}
30+
}
31+
});
32+
}
33+
};
34+
35+
let autocomplete = Drupal.autocomplete.options;
36+
autocomplete.originalValues = [];
37+
autocomplete.labelValues = [];
38+
39+
/**
40+
* Add custom select handler.
41+
*/
42+
autocomplete.select = function (event, ui) {
43+
autocomplete.labelValues = Drupal.autocomplete.splitValues(event.target.value);
44+
autocomplete.labelValues.pop();
45+
autocomplete.labelValues.push(ui.item.label);
46+
autocomplete.originalValues.push(ui.item.value);
47+
48+
$(event.target).data('real-value', autocomplete.originalValues.join(', '));
49+
event.target.value = autocomplete.labelValues.join(', ');
50+
51+
return false;
52+
}
53+
54+
})(jQuery, Drupal);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
hide-reference-ids:
2+
version: 1.x
3+
js:
4+
assets/js/hideReferenceIds.js: {}
5+
dependencies:
6+
- core/jquery

web/profiles/custom/os2loop/modules/os2loop_question/src/Helper/Helper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ private function handleTextFormats(array &$form, FormStateInterface $form_state,
8787
* The id of the the form.
8888
*/
8989
private function alterContentForm(array &$form, FormStateInterface $form_state, string $form_id) {
90+
// Hide reference ids for autocomplete components.
91+
$form['#attached']['library'][] = 'os2loop_question/hide-reference-ids';
92+
93+
// Handle anonymous author setting.
9094
$allowAnonymousAuthor = (bool) $this->config->get('allow_anonymous_question_author');
9195
if (!$allowAnonymousAuthor) {
9296
$form['os2loop_content_anonymous_author']['#access'] = FALSE;

0 commit comments

Comments
 (0)