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

  1. In the field_config table of your database set the locked value to one of the fields to 1.
  2. View the field on the manage fields page of an entity type.
  3. Click on the edit and the delete links.
  4. You will then see a message that states this field is locked and cannot be deleted.

Comments

jhodgdon’s picture

Issue tags: +Needs tests, +user interface bug, +#d8ux, +Needs backport to D7

I recently ran across this bug, and it's a very disconcerting UI bug in my opinion. The patch probably needs a test.

jhodgdon’s picture

Issue tags: -Needs tests, -user interface bug, -#d8ux, -Needs backport to D7

field_ui_locked_operations.patch queued for re-testing.

pcambra’s picture

Issue tags: +Needs tests, +user interface bug, +#d8ux, +Needs backport to D7

field_ui_locked_operations.patch queued for re-testing.

pcambra’s picture

Issue tags: -Needs tests
StatusFileSize
new2.59 KB

Here are some tests.

swentel’s picture

Status: Needs review » Needs work
Issue tags: +Novice, +Field API

Makes sense, needs re-roll though

lbainbridge’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB

The form callback was moved out of the field_ui.admin.inc file, so we moved the fix accordingly, also rerolled the test.

Status: Needs review » Needs work
Issue tags: -Novice, -user interface bug, -#d8ux, -Needs backport to D7, -Field API

The last submitted patch, 1549506-field_ui_locked_operations-6.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
Issue tags: +Novice, +user interface bug, +#d8ux, +Needs backport to D7, +Field API
swentel’s picture

Status: Needs review » Needs work
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.phpundefined
@@ -342,6 +342,39 @@ function testDeleteField() {
+   * Test that Field UI respects locked field

Nitpick, needs a full stop.

+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.phpundefined
@@ -342,6 +342,39 @@ function testDeleteField() {
+    field_create_field($field);

field_create_field is deprecated, should be entity_create('field_entity', $values); now.

+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.phpundefined
@@ -342,6 +342,39 @@ function testDeleteField() {
+    field_create_instance($instance);

Same here, should be entity_create('field_instance', array $values));

Looks good other than that, after that it's RTBC!

swentel’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.72 KB
new2.7 KB

rerolled, also removed the t() strings as we don't use them anymore in tests.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1549506-field_ui_locked_operations-10.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.73 KB
new2.68 KB

duh

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.x, moving to 7.x for backport.

swentel’s picture

Issue tags: -#d8ux, -Field API

Removing some tags, will re-roll later this week

SidneyGijzen’s picture

Assigned: Unassigned » SidneyGijzen
Issue summary: View changes
SidneyGijzen’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new2.62 KB

I 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 for field_create_field(), since AFAIK entity_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?

SidneyGijzen’s picture

StatusFileSize
new2.72 KB

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

  • catch committed b47ddcc on 8.3.x
    Issue #1549506 by swentel, pcambra, lbainbridge, muriqui: Fixed Edit and...

  • catch committed b47ddcc on 8.3.x
    Issue #1549506 by swentel, pcambra, lbainbridge, muriqui: Fixed Edit and...
herved’s picture

+++ b/modules/field_ui/field_ui.test
@@ -378,6 +378,38 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase {
+    $locked = $this->xpath('//tr[@id=:field_name]/td[5]', array(':field_name' => $instance['field_name']));
+    $this->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');
+    $edit_link = $this->xpath('//tr[@id=:field_name]/td[5]', array(':field_name' => $instance['field_name']));
+    $this->assertFalse(in_array('edit', $edit_link), 'Edit option for locked field is not present the UI');
+    $delete_link = $this->xpath('//tr[@id=:field_name]/td[6]', array(':field_name' => $instance['field_name']));

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

SidneyGijzen’s picture

Assigned: SidneyGijzen » Unassigned

Thanks for the feedback @herved!

  • catch committed b47ddcc on 8.4.x
    Issue #1549506 by swentel, pcambra, lbainbridge, muriqui: Fixed Edit and...

  • catch committed b47ddcc on 8.4.x
    Issue #1549506 by swentel, pcambra, lbainbridge, muriqui: Fixed Edit and...
kusalavan’s picture

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

Christie Alcidor’s picture

Issue summary: View changes
Christie Alcidor’s picture

Christie Alcidor’s picture

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.