< 122023-07-13⋎14 >

Topic for #farmOS is: farmOS (farmos.org) is a free and open source, web-based farm management system. User guide: farmos.org/guide/ - Forum: farmOS.discourse.groupSet by mstenta on 2021-06-15 at 12:52
15:50symbioquine[m]farmOS dev call in about 10 minutes. All are welcome!
15:50symbioquine[m]Join: meet.jit.si/farmos-dev
17:05paul121[m]The thing I wanted to share is re: taxonomy term bundle fields. Right now we have a bit of an unsolved issue where it is possible for contrib modules to add bundle fields to a taxonomy term, but it is challenging for this contrib module to manage the form & view display of their bundle fields for this taxonomy term
17:06paul121[m]Well, it actually could be simple for a single contrib module to manage this, but the challenge is when multiple contrib modules want to provide & manage bundle fields to the same taxonomy vocabulary
17:07mstenta[m](Semi related: www.drupal.org/project/farm/issues/31908)
17:07paul121[m]This issue does not exist for assets/logs because they use bundle plugins, but it seems quite challenging to enable this for taxonomy terms
17:07paul121[m]^ yes!
17:08paul121[m]SO I think I've found an alternative solution for managing the default form/view display for taxonomy terms
17:08mstenta[m]Yea I ended up closing that issue as "won't fix" ... we could reconsidder, but yea:
17:08mstenta[m]> This is a more invasive change to Drupal core functionality (taxonomy terms), so it may require more testing than our other primary asset types did.
17:09paul121[m]via hook_entity_form/view_display_alter and the View/FormDisplay::setComponent() method
17:10paul121[m]it's possible to detect if the `default` entity view/form display has been saved into configuration via its entity `$entity->isNew()`
17:11paul121[m]so basically... a module can add bundle fields to a taxonomy, implement hook_entity_view_display_alter and add their own bundle fields to the default display as desired
17:12paul121[m]but only do so if the default display has not been saved or modified into configuration. The default displays are not saved by default
17:13paul121[m]This came up because I'm needing to do this for the farm_product module adding 2 bundle fields to units taxonomy terms
17:13*uploaded an image: (49KiB) < libera.ems.host/_matrix/media/v3/downloa >
17:14paul121[m]here is the view display configuration for units. Notice that the package bundle fields are hidden...
17:14*uploaded an image: (56KiB) < libera.ems.host/_matrix/media/v3/downloa >
17:15paul121[m]yet when you actually view a unit term, these bundle fields are displayed. That is because of the alter hook.
17:15*uploaded an image: (14KiB) < libera.ems.host/_matrix/media/v3/downloa >
17:16paul121[m]paul121[m]: But importantly, once you click "Save" on this "Manage display" form, the `default` view mode is then saved & will behave as expected
17:19paul121[m]So there is some weird UX in these screenshots because the "Manage display/form" may not actually behave as seen, but this is only for super farmOS admins. We could add a message to this page saying "This entity display has not been saved and may be altered by other modules" & also provide a button to "reset" these view/form displays back to their original configuration (surprised drupal doesn't already have this)
17:23paul121[m]I kinda wonder if we could use this same approach for the default view/form displays of assets/logs as well, they have a similar issue where it is challenging to completely modify the default display. But less of a concern. For taxonomy this is actually something I need to figure out soon :-)
17:24paul121[m]code example:... (full message at <libera.ems.host/_matrix/media/v3/downloa>)
17:25paul121[m]oh also... taxonomy terms are weird because the default view display mode is actually called full. but their form mode is default 🤷
17:45mstenta[m]Interesting!
17:46mstenta[m]What would we need to do in farmOS core (if anything)?
17:56paul121[m]Well the above works without changes to farmOS core
17:56paul121[m]But I think we could remove the default view/form displays we provide for a few of our taxonomies & update to this approach
17:56mstenta[m]Ahh
17:56mstenta[m]Love it!
17:57mstenta[m]I suppose that would also mean deleting existing saved config for those... but of course we'd want to make sure they were not overridden already
17:57paul121[m]I just happen to not be modifying one of the taxonomies that has the display committed...
17:57mstenta[m](in an update hook)
17:58paul121[m]Right, but to simplify that, can we just check if farm_update is/is not enabled?
17:58mstenta[m]I was just thinking something like that too :-)
17:58paul121[m]Maybe make sure the specific config item isn't excluded as well
17:58mstenta[m]Oh yea

< 122023-07-13⋏14 >