From 15bcfef834b6fd21c9ef64cd985ca169762002d8 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Wed, 30 Oct 2024 08:59:12 -0300 Subject: [PATCH] added other host fields --- disable_field_autocomplete.module | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/disable_field_autocomplete.module b/disable_field_autocomplete.module index 2109c48..5e10426 100644 --- a/disable_field_autocomplete.module +++ b/disable_field_autocomplete.module @@ -37,9 +37,23 @@ function disable_field_autocomplete_form_node_islandora_object_edit_form_alter(& * @param \Drupal\Core\Form\FormStateInterface $form_state * @return void */ -function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state){ - $contributors = &$form_state->getValue('field_linked_agent'); +function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { + // TODO: discover fields configured to use the disable_field_autocomplete widget instead of hardcoding. + disable_field_autocomplete_validate_fields('field_linked_agent', $form, $form_state); + disable_field_autocomplete_validate_fields('field_host_contributor', $form, $form_state); + disable_field_autocomplete_validate_fields('field_series_contributors', $form, $form_state); +} + +/** + * Do the validation. + * @param $field_id + * @param array $form + * @param \Drupal\Core\Form\FormStateInterface $form_state + * @return void + */ +function disable_field_autocomplete_validate_fields($field_id, $form, \Drupal\Core\Form\FormStateInterface $form_state) { $contributor_count = 0; + $contributors = &$form_state->getValue($field_id); foreach ($contributors as &$contributor) { if (is_array($contributor) && isset($contributor['target_id']) && is_array($contributor['target_id'])) { $entity = ($contributor['target_id']['entity']); @@ -59,7 +73,6 @@ function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form } $contributor_count++; } - return; } /** @@ -74,7 +87,7 @@ function disable_field_autocomplete_get_term_id($term_name) { $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $terms = $storage->loadByProperties([ 'name' => $term_name, - 'vid' => ['Person', 'Contributors', 'Host Contributors', 'Series Contributors'], + 'vid' => ['person', 'corporate_body', 'event', 'family'], ]); if ($terms) {