Problem/Motivation

https://www.drupal.org/project/field_readonly is a module which alters each entity form, to disable some of the form fields.
It used to have hook_field_attach_form for that.

Sadly there is no such hook in Drupal8, though there is \Drupal::moduleHandler()->alter('entity_display_build', $build_list[$key], $context);

Proposed resolution

Add \Drupal::moduleHandler()->alter('entity_form_build', $form, $context); into \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm

Remaining tasks

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

swim’s picture

Status: Active » Needs review
StatusFileSize
new660 bytes

Here's a patch that addresses the issue outlined in the summary.

dawehner’s picture

Some kind of test coverage would be nice, I think.

swim’s picture

Hey dawehner,

I'm sorry but I don't know the most appropriate location to write the test coverage. Because Entity is not a module should the test coverage live in core/modules/system/src/Tests/Common/AlterTest.php?

dawehner’s picture

For hook_entity_display_build_alter() we have core/modules/field/tests/src/Kernel/DisplayApiTest.php:156 currently, so maybe opening up a FormDisplayTest in there would be the right way. ON top of that then add something like \field_test_entity_display_build_alter for your new hook maybe.

Note: We also have to add documentation to entity.api.php

swentel’s picture

swentel’s picture

Status: Needs review » Closed (duplicate)