Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently a hard coded character count of 1 is required for the JS to send a AJAX request, this figure is too small in our experience, and doesn't return useful results. We'd like the minimum character count to be configured on a site basis.
Hard coded figure in js/autocomplete.js:160
: minLength: 1
Comments
Comment #2
mpp CreditAttribution: mpp at AmeXio for District09 commentedComment #3
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedThis patch will add a textbox in the CKEditor Linkit plugin settings which will allow to set the minimum length before autocomplete is triggered.
Comment #4
kunalkursija CreditAttribution: kunalkursija at Axelerant commented@gskharmujai This will be a nice to have feature. Below is some feedback that I thought of while reviewing this patch.
we should not limit size and max length. These can vary based on user requirements and hence should be kept open.
If we go for type 'number', The validation function won't be required.
We could change the property 'linkit_AutocompleteLimit' to 'linkit_autoCompleteLimit'
One last thing, The latest release for the module is D9 compatible and has got rid of few deprecations. I think it will be better to make this patch available in the 8.x-4.3 version and also reroll it for the latest release.
Comment #5
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedThanks @kunalkursija. I have made some changes and updated the patch specifically for 8.x-4.3.
Also, i have added the cleanup functionalty to purge the Linkit plugin entries from CKEditor text formats when the Linkit module is uninstalled.
I think i will also need to roll out another patch for 8.x-5.x as there is an implementation change in the CKEditor Linkit plugin.
Comment #6
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedComment #7
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedComment #8
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedLooks like i had upload a wrong patch before. This is the correct patch.
3055954-configurable-autocomplete-character-limit-8-v4.3.patch
Comment #9
kunalkursija CreditAttribution: kunalkursija at Axelerant commented@gskharmujai - i reviewed the patch today and feature seems to be working.
However, I have second thoughts about getting into the text-formats configurations. And on trying few things today I think we could simply create a configuration form at say 'admin/config/content/linkit/autocomplete-minlength' which allows to save integer value for min-length. (default value 1)
We could pass this min-length from
processLinkitAutocomplete
function ofDrupal\linkit\Element\Linkit
class to/js/autocomplete.js
usingdrupalSettings
. Off-course we will have to define drupalSettings library as a dependency in libraries.yml.I think this solution will be easier to maintain in the long run.
Comment #10
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedYes. This implementation is more straightforward and easier to maintain and it removes the dependency on the editor configuration.
I will see how to get this done. I feel that this solution will also work well with 8.x-5.x.
Comment #12
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedComment #13
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedUploaded a new patch to fix this issue.
Comment #14
kunalkursija CreditAttribution: kunalkursija at Axelerant commentedI reviewed the patch and here are some suggestions:
Remove these and rather let's initialize 'minlength' in the autocomplete object itself. We can do so by adding drupalSettings in the JS file as followed:
(function ($, Drupal, _, document) {
with(function ($, Drupal, _, document, drupalSettings) {
})(jQuery, Drupal, _, document);
with})(jQuery, Drupal, _, document, drupalSettings);
minlength: 1
will becomeminLength: (drupalSettings.linkitMinLength) ? drupalSettings.linkitMinLength : 1
Comment #15
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedI have updated the patch with these changes. Looks more straightforward and clean now.
Comment #16
kunalkursija CreditAttribution: kunalkursija at Axelerant commented@gskharmujai The patch worked for me, And I think this looks like a nice to have feature.
This patch might fail and we might need a re-roll to make it work with the latest Linkit release.
Comment #17
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedI had done some ground work to get this patch working for 5.x too a while back where 5.x has some implementation differences.
I think this new patch will work for 8.x-5.x-dev.
Comment #18
kunalkursija CreditAttribution: kunalkursija at Axelerant commented@gskharmujai the patch application was clean on the latest module release.
Comment #19
gskharmujai CreditAttribution: gskharmujai at Axelerant commented@kunalkursija : Thank you for spending time to test it out.
Comment #20
gskharmujai CreditAttribution: gskharmujai at Axelerant commentedRe-rolling patch to work for both 6.0.x and 6.1.x.
Comment #21
firewaller CreditAttribution: firewaller commentedUpdated patch for latest 6.0.x (<=6.0.2)