Skip to main content
added 2 characters in body
Source Link
user72672
user72672

You can use this approach.

/**
 * Implements hook_field_widget_form_alter().
 */
function insights_analyst_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
    if($element['#field_name'] == 'field_figure'){
        $element['#process'][] = 'removeFile';
    }
}

function removeFile(&$element , \Drupal\Core\Form\FormStateInterface $form_state, &$complete_form){
    $element['remove_button']['#submit'][] = 'markupRemove';
    return $element;
}

function markupRemove($form , \Drupal\Core\Form\FormStateInterface $form_state){
    $parents = $form_state->getTriggeringElement()['#array_parents'];
    $button_key = array_pop($parents);
    //print_r($button_key);
    if($button_key == 'remove_button'){
       //Write your logic here
    }
}

You can use this approach.

 * Implements hook_field_widget_form_alter().
 */
function insights_analyst_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
    if($element['#field_name'] == 'field_figure'){
        $element['#process'][] = 'removeFile';
    }
}

function removeFile(&$element , \Drupal\Core\Form\FormStateInterface $form_state, &$complete_form){
    $element['remove_button']['#submit'][] = 'markupRemove';
    return $element;
}

function markupRemove($form , \Drupal\Core\Form\FormStateInterface $form_state){
    $parents = $form_state->getTriggeringElement()['#array_parents'];
    $button_key = array_pop($parents);
    //print_r($button_key);
    if($button_key == 'remove_button'){
       //Write your logic here
    }
}

You can use this approach.

/**
 * Implements hook_field_widget_form_alter().
 */
function insights_analyst_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
    if($element['#field_name'] == 'field_figure'){
        $element['#process'][] = 'removeFile';
    }
}

function removeFile(&$element , \Drupal\Core\Form\FormStateInterface $form_state, &$complete_form){
    $element['remove_button']['#submit'][] = 'markupRemove';
    return $element;
}

function markupRemove($form , \Drupal\Core\Form\FormStateInterface $form_state){
    $parents = $form_state->getTriggeringElement()['#array_parents'];
    $button_key = array_pop($parents);
    //print_r($button_key);
    if($button_key == 'remove_button'){
       //Write your logic here
    }
}
Source Link
Mahtab Alam
  • 255
  • 1
  • 3
  • 12

You can use this approach.

 * Implements hook_field_widget_form_alter().
 */
function insights_analyst_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
    if($element['#field_name'] == 'field_figure'){
        $element['#process'][] = 'removeFile';
    }
}

function removeFile(&$element , \Drupal\Core\Form\FormStateInterface $form_state, &$complete_form){
    $element['remove_button']['#submit'][] = 'markupRemove';
    return $element;
}

function markupRemove($form , \Drupal\Core\Form\FormStateInterface $form_state){
    $parents = $form_state->getTriggeringElement()['#array_parents'];
    $button_key = array_pop($parents);
    //print_r($button_key);
    if($button_key == 'remove_button'){
       //Write your logic here
    }
}