- 🇨🇦Canada avo webworks Ottawa, Ontario, Canada
So I just wanted to post a fix for this so that anyone else struggling with this.
Make sure to target the correct form ID to the forms you want to set.
In a custom module add this code in the mymodule.module file:<?php use Drupal\Core\Form\FormStateInterface; /** * Implements hook_form_alter(). */ function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { // List of relevant form IDs for Bibcite. $target_form_ids = [ 'bibcite_reference_book_form', 'bibcite_reference_book_chapter_form', 'bibcite_reference_journal_article_form', 'bibcite_reference_book_edit_form', 'bibcite_reference_book_chapter_edit_form', 'bibcite_reference_journal_article_edit_form', ]; // Check if the current form is one of the target forms. if (in_array($form_id, $target_form_ids)) { // Check if the Keywords field exists in the form. if (isset($form['keywords']['widget']['#options']) && is_array($form['keywords']['widget']['#options'])) { // Sort the options alphabetically. asort($form['keywords']['widget']['#options']); } } }