- Issue created by @pfrenssen
- 🇧🇬Bulgaria pfrenssen Sofia
Thanks for the review! I agree that it looks suspicious that we are changing the form state in this callback, but that's a supported way to set values in the form state during form processing.
To put your mind at ease here is an example from Drupal core that shows the use of the
#after_build
callback to alter the form state in core. It is determining if CKEditor should be the activated on the page: assessActiveTextEditorAfterBuild.The Form API has been designed almost 20 years ago (introduced in Drupal 4.7) and it was already revolutionary to use an object for the form state rather than an associative array :) There are some long-term plans to refactor the Form API (which is a part of the Render API) to become object oriented, but since the scope of this task is insanely huge there is nobody actually working on it (ref. #2821399: [meta] Theme System Modernization Initiative → ).
- 🇧🇬Bulgaria pfrenssen Sofia
If I read the code correctly, the $element variable never gets used except at the return of the function.
That is intentional,
$element
should be returned, changed or unchanged. Here is an example in the API docs that shows this pattern: EntityForm::afterBuild(). -
pfrenssen →
committed f7c3d78d on 1.0.x
Issue #3499601 by pfrenssen, hazn: Overriding auto-generated bundle...
-
pfrenssen →
committed f7c3d78d on 1.0.x
Automatically closed - issue fixed for 2 weeks with no activity.