Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When you programmatically create a field with the option "locked => TRUE" there can be errors like:
- Notice: Undefined index: description in token_form_field_ui_field_edit_form_alter() (line 715 of /sites/all/modules/token/token.module).
- Notice: Undefined index: #description in token_form_field_ui_field_edit_form_alter() (line 715 of /sites/all/modules/token/token.module).
The $form['instance'] variable should be empty, but this does not always happen.
Comment | File | Size | Author |
---|---|---|---|
#1 | field-locked-test-1720576.patch | 453 bytes | daffie |
Comments
Comment #1
daffie CreditAttribution: daffie commentedI have made a patch. Please review it.
Comment #2
Dave ReidI'm not able to duplicate this with just core + Token module. What type of field type should I add which should be locked?
Comment #3
daffie CreditAttribution: daffie commentedTo get the errors you need core + Token + Custom add another modules.
If you create a field instance programmatically with the option "locked => TRUE" and you go to the field_ui_field_edit_form, you should get a message like "The field XXX is locked and cannot be edited.".
You only get the message, there is no form data. This is part of field_create_field() function.
The hook_form_field_ui_field_edit_form_alter function from the Custom add another module adds a form item to the $form['#instance']. The token module only test if the $form['#instance'] is empty. If it is not then it does a string attach to the variable $form['instance']['description']['#description'].
I think that it is wise to not only test if $form['#instance'] is empty, but also to test $form['#field']['locked'] to see of the field instance is locked.
I do not know if there is an explicit understanding that if a field instance is created with the option "locked => true" that the variable $form['#instance'] must be empty. And that every module can expect that. Even if you expect that, I think that it is wise to add the extra check to test if the field instance is locked.
Comment #4
daffie CreditAttribution: daffie commentedComment #5
westwesterson CreditAttribution: westwesterson commentedI can confirm this fixed the problem for me. I had the module media_galley installed as well...
since locked is a property supported by the drupal 7 field api, this change seems to make sense to me.
Comment #6
daffie CreditAttribution: daffie commented@westwesterson: Thank you for testing this patch.
Comment #7
doronin CreditAttribution: doronin commentedThanks for the patch, can also confirm it's working.
Comment #8
papirrin CreditAttribution: papirrin commentedThank you for the patch! It also worked for me!
Comment #9
westwesterson CreditAttribution: westwesterson commentedlets move this along
Comment #10
Dave ReidCommitted #1 to 7.x-1.x. Thanks everyone! http://drupalcode.org/project/token.git/commit/7a37d4b