I was attempting to use "hook_field_widget_form_alter" and "hook_field_widget_WIDGET_TYPE_form_alter" to make changes to a form with 2 unlimited field_collection elements. My problem was the form_alter would not be invoked.
I had found a patch here https://www.drupal.org/node/1592814#comment-9696717 that would allow for altering of field_multiple_value_form(s). It creates a hook_field_multiple_value_form_alter that is able to be invoked.
Long story short - noticing the
"drupal_alter(array('field_widget_form', 'field_widget_' . $instance['widget']['type'] . '_form'), $element, $form_state, $context);" (line 260 of "form.field.inc")
I tried to figure out why the hooks related to it were not be invoked. I looked at the code all seemed fine but would not work. So playing around, I tried adding 'field_multiple_value_form' to the array of $type(s) in the drupal_alter. I found that I could use a "hook_field_multiple_value_form_alter" coming from the drupal_alter() at line 260.
Additionally, I was also then able to use the "hook_field_widget_form_alter" and "hook_field_widget_WIDGET_TYPE_form_alter", too.
So my edited drupal_alter() at line 260 of "form.field.inc" in the "field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state)" function looks like this.
"drupal_alter(array('field_widget_form', 'field_widget_' . $instance['widget']['type'] . '_form', 'field_multiple_value_form'), $element, $form_state, $context);"
I do not know why this works, it just does.
Additionally, it works regardless of having the patch code, it is merely because I added the 'field_multiple_value_form' to the $type array.
Comments
Comment #2
JimJS CreditAttribution: JimJS commentedComment #3
JimJS CreditAttribution: JimJS commentedComment #4
cilefen CreditAttribution: cilefen commentedI am not sure what you are asking here. Would you mind refactoring the issue summary with the issue template?
Comment #5
JimJS CreditAttribution: JimJS commentedProblem/Motivation
The problem is when I tried using -
hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $context)
and
hook_field_widget_form_alter(&$element, &$form_state, $context)
- called from mymodule_form_entityform_edit_form_alter they would not be invoked (like dead functions).
Proposed resolution
I edited the drupal_alter() at line 260 of "form.field.inc" in the function "field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state)" to add 'field_multiple_value_form' as an additional item in the $type array. Then hook_field_widget_WIDGET_TYPE_form_alter and hook_field_widget_form_alter started working.
I don't know why this works but I was thinking there is some bug if the alters don't work for without this change. Not heavily into knowing Drupal's core so I cannot add more.
So I don't know that I am asking anything I am simply pointing out my findings. Here is a question for this issue.
Why don't the hook_field_widget_WIDGET_TYPE_form_alter and hook_field_widget_form_alter work when called from mymodule_form_entityform_edit_form_alter?