Browse Source

eleminate a warning and add another hook form alter

main
Paul Pound 2 months ago
parent
commit
085b55be78
  1. 12
      disable_field_autocomplete.module

12
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)));
}

Loading…
Cancel
Save