From 085b55be785416312157670630d5c4c841ec0d58 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Wed, 30 Oct 2024 11:14:47 -0300 Subject: [PATCH] eleminate a warning and add another hook form alter --- disable_field_autocomplete.module | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/disable_field_autocomplete.module b/disable_field_autocomplete.module index 5e10426..bc673eb 100644 --- a/disable_field_autocomplete.module +++ b/disable_field_autocomplete.module @@ -30,6 +30,13 @@ function disable_field_autocomplete_form_node_islandora_object_edit_form_alter(& $form['#validate'][] = 'disable_field_autocomplete_node_edit_validate'; } +/** + * Implements hook_form_alter(). + */ +function disable_field_autocomplete_form_node_islandora_object_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { + $form['#validate'][] = 'disable_field_autocomplete_node_edit_validate'; +} + /** * Extra Islandora Ojbect node validation required due to lacking autocomplete. @@ -54,6 +61,9 @@ function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form function disable_field_autocomplete_validate_fields($field_id, $form, \Drupal\Core\Form\FormStateInterface $form_state) { $contributor_count = 0; $contributors = &$form_state->getValue($field_id); + if(empty($contributors)) { + return; + } foreach ($contributors as &$contributor) { if (is_array($contributor) && isset($contributor['target_id']) && is_array($contributor['target_id'])) { $entity = ($contributor['target_id']['entity']); @@ -65,7 +75,7 @@ function disable_field_autocomplete_validate_fields($field_id, $form, \Drupal\Co $contributor['target_id'] = $term_id; } } catch (Exception $e) { - $form_state->setError($form['field_linked_agent']['widget'][$contributor_count], + $form_state->setError($form[$field_id]['widget'][$contributor_count], t('The entered Term %name is not unique across Vocabularies. You will need to include the term id in brackets. For Example "%name (119)", where 119 is the term id.', array('%name' => $name))); }