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.

Command icon 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

savkaviktor16@gmail.com’s picture

Issue summary: View changes

astonvictor made their first commit to this issue’s fork.

astonvictor’s picture

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

astonvictor’s picture

Status: Active » Closed (cannot reproduce)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.