Problem/Motivation
The readonly_field_widget module currently assumes that all fields are direct children of the top-level $form array. When using the Entity Browser module as a widget for a field, the form structure is different.
In readonly_field_widget_form_alter(), the code attempts to set #access like this: $form[$name]['#access'] = $items->access('view');
If the widget is an Entity Browser, the field might be nested or handled in a way that $form[$name] is not directly accessible or does not exist in the expected format at that stage of the form build.
The readonly restriction failing to apply to Entity Browser fields, leaving them editable or hidden incorrectly.
Proposed resolution
Update readonly_field_widget_form_alter() to check for the existence of the form element before applying access restrictions. Additionally, we should investigate a more robust way to target the field elements that might be nested (e.g., using Element::children or checking for the presence of the widget in the form array).
However, for full support of Entity Browser, we may need to ensure the widget is compatible with how Entity Browser handles its sub-form elements.
Remaining tasks
Confirm the form structure for Entity Browser widgets during form_alter.
Provide a patch that safely applies access to the widget regardless of the specific renderer implementation.
Issue fork readonly_field_widget-3566041
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
savkaviktor16@gmail.com commentedComment #4
astonvictor commentedI'm afraid I don't see a case when we need to fix smth.
The entity browser doesn't provide a field type. So, they won't work together for the same field. You can only select the entity browser or the read-only widget.
Upload and select widgets in entity browsers don't show entity forms. So, you cannot select the read-only widget for those displays.
The entity form widget in the entity browser always shows a form for adding/uploading new items and, in most cases, has empty fields.
Comment #5
astonvictor commented