Add ajax on hook_field_widget_paragraphs_form_alter I'm working with paragraph and I try to change a paragraph with AJAX.
My content type have a content field which contains &quot;section&quot; paragraphs which can contain various paragraph types which themselves can contain various paragraphs types.
To do certain modification on paragraphs, I use hook_field_widget_paragraphs_form_alter. It's work well but I meet a problem when I try to use #ajax because I don't know how to retrieve which paragraph has been modified in the ajax callback because I receive the entire form from the content and no information on which part has been modified. Here my code:
function mymodule_field_widget_paragraphs_form_alter(&amp;$element, &amp;$form_state, $context) {
  switch ($element['#paragraph_type']) {
    case 'block_special':
      $element['subform']['field_type']['widget']['#ajax'] = [
          'wrapper' =&gt; 'type-bs-wrapper',
          'callback' =&gt; '_type_paragraph_callback',
        ];

        $element['subform']['field_content']['widget']['#attributes'] = ['id' =&gt; 'type-bs-wrapper'];
       
        $values_paragraph = $form_state-&gt;getValues();
        if(!empty($values_paragraph)) {
          foreach ($element['#field_parents'] as $field) {
            $values_paragraph = $values_paragraph[$field];
          }

          $type = $values_paragraph['subform']['field_type'];
        }

        if (!empty($type) &amp;&amp; $type === 'exception') {
          unset($element['subform']['field_content']['widget']['add_more']['add_more_button_paragraph_type1']);
          unset($element['subform']['field_content']['widget']['add_more']['add_more_button_paragraph_type2']);
        }
  }
}

function _type_paragraph_callback(array $form, FormStateInterface $form_state) {

  return $form; // &lt;- How can I know what I should return?
}

I don't know which paragraph have been return. I don't know if I can pass the argument $element['#parent'] from the function hook_field_widget_paragraphs_form_alter (but how in this case) or if I should do a recursive research between default value of all paragraphs of my form between form_values (which will be laborious).
You should be able to get this information from the submitted data in $form_state, specifically the triggering element.
For example:
use Drupal\Component\Utility\NestedArray;

function _type_paragraph_callback(array $form, FormStateInterface $form_state) {
  $button = $form_state-&gt;getTriggeringElement();
  // Go one level up in the form, to the widgets container.
  $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));

  return $element;
} 

I've copied this from the Paragraphs module:
modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php