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.

CommentFileSizeAuthor
#1 field-locked-test-1720576.patch453 bytesdaffie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

daffie’s picture

I have made a patch. Please review it.

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not able to duplicate this with just core + Token module. What type of field type should I add which should be locked?

daffie’s picture

To 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.

daffie’s picture

Status: Postponed (maintainer needs more info) » Needs review
westwesterson’s picture

I 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.

daffie’s picture

@westwesterson: Thank you for testing this patch.

doronin’s picture

Thanks for the patch, can also confirm it's working.

papirrin’s picture

Thank you for the patch! It also worked for me!

westwesterson’s picture

Status: Needs review » Reviewed & tested by the community

lets move this along

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Committed #1 to 7.x-1.x. Thanks everyone! http://drupalcode.org/project/token.git/commit/7a37d4b

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.