When a field is locked, the Field UI still shows "edit" and "delete" links for the instance under "Operations". Clicking one of those links takes you to the edit or delete form, where you get a message that the field has been locked and cannot be edited/deleted. It would be better if those links were hidden, and it appears that the Field UI module author(s) intended to do that. On line 407 of field_ui.admin.inc, we have this:
if (!empty($instance['locked'])) {
$table[$name]['edit'] = array('#value' => t('Locked'));
$table[$name]['delete'] = array();
$table[$name]['#attributes']['class'][] = 'menu-disabled';
}
... which doesn't work because "locked" is a property of the field, not the instance. Also, the "Locked" message that is supposed to replace the "edit" link should be a #markup element, not a #value. The attached patch fixes the issue by changing the first two lines to this:
if (!empty($field['locked'])) {
$table[$name]['edit'] = array('#markup' => t('Locked'));
Steps to reproduce
- In the field_config table of your database set the locked value to one of the fields to 1.
- View the field on the manage fields page of an entity type.
- Click on the edit and the delete links.
- You will then see a message that states this field is locked and cannot be deleted.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | field-ui-locked-operations-1549506-21.patch | 2.74 KB | herved |
Comments
Comment #1
jhodgdonI recently ran across this bug, and it's a very disconcerting UI bug in my opinion. The patch probably needs a test.
Comment #2
jhodgdonfield_ui_locked_operations.patch queued for re-testing.
Comment #3
pcambrafield_ui_locked_operations.patch queued for re-testing.
Comment #4
pcambraHere are some tests.
Comment #5
swentel commentedMakes sense, needs re-roll though
Comment #6
lbainbridge commentedThe form callback was moved out of the field_ui.admin.inc file, so we moved the fix accordingly, also rerolled the test.
Comment #8
swentel commented#6: 1549506-field_ui_locked_operations-6.patch queued for re-testing.
Comment #9
swentel commentedNitpick, needs a full stop.
field_create_field is deprecated, should be entity_create('field_entity', $values); now.
Same here, should be entity_create('field_instance', array $values));
Looks good other than that, after that it's RTBC!
Comment #10
swentel commentedrerolled, also removed the t() strings as we don't use them anymore in tests.
Comment #12
swentel commentedduh
Comment #13
catchCommitted/pushed to 8.x, moving to 7.x for backport.
Comment #14
swentel commentedRemoving some tags, will re-roll later this week
Comment #15
SidneyGijzen commentedComment #16
SidneyGijzen commentedI tried to port the patch to D7 (see attached), however I'm a bit stuck at the test part.
For the test part I replaced the
entity_create()calls forfield_create_field(), since AFAIKentity_create()is part of the Entity API module in D7. I assumed one should be able to run tests without any contrib modules installed.Anyway, I'm just starting with contributing to Core, so I find it a bit hard. Can someone point me in the right direction? E.g. how can I properly debug the whole testing part?
Comment #17
SidneyGijzen commentedI think I made a bit of progress. However the line
$this->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');is still failing in my manual test runs. And I don't understand why...
When I check the verbose test results, in the area for edit and delete links are both marked as "Locked". So, I guess that's what should happen. Next to the label 'Locked Field' should there be any other indication that the field is locked?
New patch attached.
Comment #21
herved commentedThe id in the html is 'field-test' (with a hyphen). So we could pass $instance['field_name'] in drupal_html_class().
Also the edit and delete td indexes in the XPath were not correct.
Here's a reroll.
Comment #22
SidneyGijzen commentedThanks for the feedback @herved!
Comment #25
kusalavan commentedI was trying to test it. But i couldn't find any steps to reproduce. If someone can add the steps to test this, it would be very helpful.
Comment #26
Christie Alcidor commentedComment #27
Christie Alcidor commentedComment #28
Christie Alcidor commented