Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Last active July 9, 2020 14:25
Show Gist options
  • Save rpayanm/cc491a7e03d2dee99a9d0dea0960caa2 to your computer and use it in GitHub Desktop.
Save rpayanm/cc491a7e03d2dee99a9d0dea0960caa2 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_field_widget_multivalue_form_alter().
*/
function MODULE_NAME_field_widget_multivalue_form_alter(&$elements, FormStateInterface $form_state, $context) {
$field = $context['items']->getName();
$build_info = $form_state->getBuildInfo();
if ($field == "FIELD_NAME") {
if (array_key_exists('form_id', $form_state->getBuildInfo())) {
if ($build_info['form_id'] == 'node_CT_NAME_form' ||
$build_info['form_id'] == 'node_CT_NAME_edit_form') {
$i = 0;
do {
$elements[$key]['#process'][] = 'MODULE_NAME_process_FIELD_NAME';
} while (isset($elements[++$i]));
}
}
}
}
/**
* The #process callback for alter field.
*
* Defined in hook_field_widget_multivalue_form_alter().
*/
function MODULE_NAME_process_FIELD_NAME($element, FormStateInterface $form_state) {
// Change the field with widget element, you can alter imagen alt, imagen title, file descriptions, etc.
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment