I have Content Type A, which represents individual product preview tiles on my site. I also have Content Type B, which represents individual pages on my site for which individual product tiles are displayed on.

For Content Type B (creating/editing a page), I have entity reference fields (field_tile_1, field_tile_2, field_tile_3) in the create/edit form that let me select any combination of 3 tiles (representing node instances of Content Type A) to be displayed in the rendered output (node) of Content Type B.

I'd like to programmatically set field_tile_1 whenever the node is loaded, in the case that the selected entity has been deleted from the DB.

I can get a node reference via node_view()but it's not wrapped like an entity reference field populated with the content form is wrapped.

Is there a way to programmatically populate an entity reference field on node load, the same as if it was entered manually in the content form?