Browse Source

added other host fields

main
Paul Pound 2 months ago
parent
commit
15bcfef834
  1. 21
      disable_field_autocomplete.module

21
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 * @param \Drupal\Core\Form\FormStateInterface $form_state
* @return void * @return void
*/ */
function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state){ function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$contributors = &$form_state->getValue('field_linked_agent'); // 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; $contributor_count = 0;
$contributors = &$form_state->getValue($field_id);
foreach ($contributors as &$contributor) { foreach ($contributors as &$contributor) {
if (is_array($contributor) && isset($contributor['target_id']) && is_array($contributor['target_id'])) { if (is_array($contributor) && isset($contributor['target_id']) && is_array($contributor['target_id'])) {
$entity = ($contributor['target_id']['entity']); $entity = ($contributor['target_id']['entity']);
@ -59,7 +73,6 @@ function disable_field_autocomplete_node_edit_validate(&$form, \Drupal\Core\Form
} }
$contributor_count++; $contributor_count++;
} }
return;
} }
/** /**
@ -74,7 +87,7 @@ function disable_field_autocomplete_get_term_id($term_name) {
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$terms = $storage->loadByProperties([ $terms = $storage->loadByProperties([
'name' => $term_name, 'name' => $term_name,
'vid' => ['Person', 'Contributors', 'Host Contributors', 'Series Contributors'], 'vid' => ['person', 'corporate_body', 'event', 'family'],
]); ]);
if ($terms) { if ($terms) {

Loading…
Cancel
Save