Trying to edit a locked field in the UI throws a WSOD

Created on 26 April 2024, 4 months ago
Updated 6 August 2024, about 1 month ago

Problem/Motivation

Trying to edit a locked field in the field UI throws a WSOD page.
This shouldn't be the case, in my opinion at least a 403 should be thrown, or a page showing a clear message that this action is not permissible.

TypeError: Drupal\Core\Form\SubformState::createForSubform(): Argument #1 ($subform) must be of type array, null given, called in /var/web/vd17831/vib-conferences/release/web/core/modules/field_ui/field_ui.module on line 299 in Drupal\Core\Form\SubformState::createForSubform() (line 60 of core/lib/Drupal/Core/Form/SubformState.php).
field_ui_form_field_config_edit_form_alter(Array, Object, 'field_config_edit_form') (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'field_config_edit_form') (Line: 841)
Drupal\Core\Form\FormBuilder->prepareForm('field_config_edit_form', Array, Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)

Steps to reproduce

  • Start with a clean D10 and enable layout builder on a node type
  • Edit the body field, and replace `body` in the URL with the layout field name: `layout_builder__layout`
  • See the WSOD thrown

Proposed resolution

I have not had the time to look into a proper fix, but if I can I will create a MR.

Remaining tasks

Create MR.

User interface changes

Throw a 403, or show a clear message that this action is not permissible.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Field UIΒ  β†’

Last updated 5 days ago

Created by

πŸ‡§πŸ‡ͺBelgium RandalV

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @RandalV
  • πŸ‡«πŸ‡·France federiko_

    "Edit the body field, and replace `body` in the URL with the layout field name: `layout_builder__layout`"

    I am not sure to understand what is meaned there. Is it possible to have more details ?

  • πŸ‡§πŸ‡ͺBelgium RandalV

    Hi frederiko_,

    Certainly!
    Editing the "body"-field will lead you to a URL like:
    /admin/structure/types/manage/page/fields/node.page.body

    Replace the last part (the field's machine name, in this case 'body'), with the locked field's machine name, for example:
    /admin/structure/types/manage/page/fields/node.page.layout_builder__layout

    And it'll give you the WSOD.

  • πŸ‡ΊπŸ‡ΈUnited States cilefen
  • πŸ‡§πŸ‡ͺBelgium RandalV

    The problem seems to be that in file core/modules/field_ui/field_ui.module,
    The $form['field_storage']['subform'] doesn't seem to exist, in the function below.
    I don't know what the correct solution would be.. I'd say the form still needs to be alterable, and we still need to trigger the alter hooks on the bottom.

    /**
     * Implements hook_form_FORM_ID_alter() for field_config_edit_form.
     */
    function field_ui_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {
      if (!isset($form['field_storage']['subform'])) {
        return;
      }
    
      $field_config = $form_state->getFormObject()->getEntity();
      assert($field_config instanceof FieldConfigInterface);
    
      $form_id = 'field_storage_config_edit_form';
      $hook = 'form_' . $form_id;
    
      $field_storage_form = \Drupal::entityTypeManager()->getFormObject('field_storage_config', $form_state->getFormObject()->getOperation());
      $field_storage_form->setEntity($field_config->getFieldStorageDefinition());
      $subform_state = SubformState::createForSubform($form['field_storage']['subform'], $form, $form_state, $field_storage_form);
    
      \Drupal::moduleHandler()->alterDeprecated('Use hook_form_field_config_edit_form_alter() instead. See https://www.drupal.org/node/3386675.', $hook, $form['field_storage']['subform'], $subform_state, $form_id);
      \Drupal::theme()->alter($hook, $form['field_storage']['subform'], $subform_state, $form_id);
    }
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    This needs to be fixed on 11.x (main) first.

  • Status changed to Needs review about 1 month ago
  • πŸ‡―πŸ‡΅Japan kazuko.murata

    I tried to work around this issue, and it seems to be resolved in Drupal 11.0.0 with fix πŸ“Œ Remove deprecated code from field_ui Fixed .

    The function field_ui_form_field_config_edit_form_alter(), which caused an error, has been removed by fix #3442361, and now displays "The field Layout is locked and cannot be edited".

    I have attached a screenshot of the operation check, so I would be happy if anyone could verify it.

  • Status changed to Needs work about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    For the tests

  • Status changed to Active about 1 month ago
Production build 0.71.5 2024