Is there a way to lock a field instance?

I want to prevent users from editing or deleting a given instance, but allow the field to be customizable elsewhere by the user. If I lock the field, it will do the former, but prevent the latter.

According to this Field API documentation, fields can be locked by setting locked = TRUE in the field definition, but there is no corresponding locked key for the instance definition.

I experimented by adding locked = TRUE to my field instance definition, and while that removed the edit and delete links from the bundle types view, I can still edit and delete by visiting the appropriate url.

2 Answers 2


I was able to use a snippet from dropbucket to lock and unlock fields. I used the snippet in the devel execute php window but it could certainly be coded into a function instead:

# You can use Devel Module to unlock/lock a existing field where you would otherwise get an error like "The field xxxx is locked and cannot be edited."
# Change the 'xxx' on line 1 with the machine readable name of your field.
$field_name = 'xxx';
$field = field_read_field($field_name);
$field['locked'] = 1; //change this to 0 to unlock a field
Instill devel module Enable the devel module either by drush en or from admin/build/modules. 

It will generate several blocks and look for the one named ‘Execute PHP’ enable it by setting it to a preferred region . Write the code you want to check on the text area for example and then press execute to see the result.

so here we will use this code

$field_name = 'field_name';
$field = field_read_field($field_name);
$field['locked'] = 0; // 0: unlock; 1: lock.

note: this line

$field_name = 'field_name';

you have to add your filed name for example like this

$field_name = commerce_price;

if you got any error such as displayed as messages

Notice: Undefined index” 


“Notice: Undefined variable” 

and your logs will grow insanely…

the solution is to add in your settings.php the line

ini_set('error_reporting', 'E_ALL ^ E_NOTICE');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.