Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_form_BASE_FORM_ID_alter() for node forms.
- */
- function custom_module_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
- $node = $form_state->getFormObject()->getEntity();
- if ($node->getType() != 'article') {
- return;
- }
- $form['field_image']['widget'][0]['#title_field'] = FALSE;
- array_unshift($form['actions']['submit']['#submit'], 'custom_module_form_submit');
- #multiple field field_image_gallery
- $i=0;
- foreach ($form['field_image']['widget'] as $item) {
- $item[$i]['#title_field'] = False;
- $i++;
- }
- }
- /**
- * Custom submit handler.
- */
- function custom_module_form_submit(&$form, FormStateInterface $form_state) {
- $image_value = $form_state->getValue('field_image');
- $image_value[0]['title'] = $image_value[0]['alt'];
- $form_state->setValue('field_image', $image_value);
- #multiple field field_image_gallery
- $image_value = $form_state->getValue('field_image_gallery');
- foreach ($image_value as $item) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement