- 🇫🇷France arnaud-brugnon
Great news
https://www.drupal.org/node/3180429 →
hook_field_widget_WIDGET_TYPE_form_alter no longer exist.
Use hook_field_widget_single_element_form_alter instead - 🇨🇦Canada alberto56
Here is my experiencing updating paragraphs 1.17 (with the patch at #16) to 1.19 (at the time of this writing the latest version of Paragraphs) on Drupal 10.5.1. This is purely my own experience and I am probably missing something, but I'd like to explain why I have decided to keep the patch at #16 of this issue, even though the issue is purportedly fixed as of May 18, 2018, as per #73.
When I inherited the site with paragraphs 1.17 with the patch at #16, one of the custom modules was implementing a hook like this:
/** * Implements hook_form_paragraphs_subform_TYPE_alter(). */ function MY_MODULE_form_paragraphs_subform_PARAGRAPH_TYPE_alter(array &$subform, FormStateInterface $form_state, $delta) { $subform['description']['#markup'] = 'Some markup'; }
This was causing "some markup" to appear when I visited a widget controlling PARAGRAPH TYPE.
Because this issue #2868155 is marked as fixed, I updated paragraphs to 1.19 and did not patch it. I examined the code at https://git.drupalcode.org/project/paragraphs/-/blob/8.x-1.x/tests/modul... and found that the test implements
/** * Implements hook_field_widget_WIDGET_TYPE_form_alter(). */ function paragraphs_test_field_widget_single_element_entity_reference_paragraphs_form_alter(&$element, &$form_state, $context) { if ($element['#paragraph_type'] == 'altered_paragraph') { $element['subform']['field_text']['widget'][0]['#title'] = 'Altered title'; } }
However, as mentioned by @arnaud-brugnon in #94, according to https://www.drupal.org/node/3180429 → , hook_field_widget_WIDGET_TYPE_form_alter() has been "marked as deprecated and will be removed in Drupal 10.".
I am assuming, therefore, that I cannot hook_field_widget_WIDGET_TYPE_form_alter().
https://www.drupal.org/node/3180429 → states that:
The new field widget hooks hook_field_widget_single_element_form_alter (hook_field_widget_single_element_WIDGET_TYPE_form_alter) should be used instead of hook_field_widget_form_alter (hook_field_widget_WIDGET_TYPE_form_alter).
However when I try to replace my existing hook, MY_MODULE_form_paragraphs_subform_PARAGRAPH_TYPE_alter() for Paragraphs 1.17 patched with #16, with MY_MODULE_field_widget_single_element_form_alter() for Paragraphs 1.19 unpatched as described in https://api.drupal.org/api/drupal/core%21modules%21field%21field.api.php..., I am unable to determine the paragraph type (I'm sure there is a way, I just can't figure it out):
I can determine that the widget type is entity_reference because $field_definition->getType() == 'entity_reference', however it's not clear to me how to determine the paragraph type in order to alter the form for that paragraph.
In my tests, applying the patch at #16 to Paragraphs 1.19 makes it so I can continue to use hook_form_paragraphs_subform_TYPE_alter() as I could with Paragraphs 1.17 patched with #16.