|
|
|
@ -38,8 +38,22 @@ function disable_field_autocomplete_form_node_islandora_object_edit_form_alter(&
|
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
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; |
|
|
|
|
$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) { |
|
|
|
|