I am currently porting a custom field module from Drupal 7 to 8. The field (Topic Access) has 3 select fields, typically about 10 to 20 items per field, and uses a custom widget. When the form is loaded, I typically insert several "inherited" items to the field before displaying it. When saving, only the items that vary from the inherited ones are actually saved to the database.
In Drupal 7, I used hook_field_load()
to add these "inherited" items to the form. As explained on Dynamic/Virtual field values using computed field property classes, that hook has been removed from Drupal 8 in favor of computed field properties.
I can't see an elegant way to manipulate the list of items. I could use hook_form_alter()
on the forms that contain the field to update $form['field_topic_access']['widget']
. However, it would end up duplicating code from the widget and have to specifically pick out the fields by name.
Is there a hook that could manipulate the list of field items before the field is built?
hook_field_widget_form_alter()
. From where are the inherited values taken from?