Adding assets to a log, 2.x

The mother asset is added with just a search box.
Directly under that the children asset brings up a popup with filtering abilities and displays a list to select from.
Were these design choices to selecting assets differently though farmOS?

Good question @BOTLFarm - it was more of a “default” design choice than an “intentional” one - and certainly one we can iterate on!

Jotting down some related history/considerations…

The mother field is added to birth logs here: https://github.com/farmOS/farmOS/blob/8a562d673e59e8fd405bc2bcc40a257e649ff4d5/modules/log/birth/src/Plugin/Log/LogType/Birth.php#L34

It uses the FarmFieldFactory class/service to build an entity_reference field definition. This service sketches up some default configuration for the field definition, based on the type. For entity_reference fields, the default “widget” (form element) is entity_autocomplete which is the “search box” you’re referring to.

Here is where that happens: https://github.com/farmOS/farmOS/blob/8a562d673e59e8fd405bc2bcc40a257e649ff4d5/modules/core/field/src/FarmFieldFactory.php#L279

So in other words: by default, entity reference fields are rendered as autocomplete search fields.

As for the “Children” field on birth logs… this is actually the same asset entity reference field as all other log types - we just change the label of it from “Assets” to “Children” on Birth logs (idea being: birth is what’s happening to the children). This asset field is added to all log types (as a base field) here: https://github.com/farmOS/farmOS/blob/8a562d673e59e8fd405bc2bcc40a257e649ff4d5/modules/core/log/modules/asset/farm_log_asset.module#L32

And by the same logic, by default, that field would have the same autocomplete search widget.

But… we override it to use the “Entity Browser” widget here: https://github.com/farmOS/farmOS/blob/8a562d673e59e8fd405bc2bcc40a257e649ff4d5/modules/core/ui/views/farm_ui_views.module#L185

The reason that happens in the farm_ui_views module is, well, because farm_ui_views is the module that provides the farm_asset View, which is what we see in the Entity Browser.

So… loooong story short… we could probably make all entity_reference fields (including “Mother” on Birth logs) use the Entity Browser by default, instead of the autocomplete search widget.

Or… make it an option that modules can decide between, via FarmFieldFactory.

If we made Entity Browser the default, we would want to review all the fields that would be affected by that (probably in both farmOS core and known contrib modules) to see if that would adversely affect any of them.

One that comes to mind: the “Location” reference field on Logs (for referencing location Assets) currently displays as an autocomplete search. Should that also change to Entity Browser?