< 062022-10-07⋎08 >

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
00:51*farmBOT has joined
11:46mstenta[m]Evan Kelley: Interesting! Just looking at the core issue you discovered in the SFI chat: www.drupal.org/project/drupal/issues/239
11:46mstenta[m]Based on quick skim of that, if adding `$form['#attached']['library'][] = 'core/drupal.form';` to the forms fixes it, then do that! I don't see any problem with that approach.
11:47mstenta[m]Remember there is a `PodsFormBase.php` which all the PODS forms inherit from, so you can probably just add it there, and it will fix all of them.
11:52mstenta[m]Evan Kelley: I'm glad you found this - we may want to look into whether or not we should add this to farmOS Quick Forms in general. I'll have to test to see if they are susceptible to this bug as well, but based on reading it sounds like they might be.
12:29evered[m]🌤️
12:30mstenta[m]Morning evered !
14:46mstenta[m]paul121 jgaehring I'm adding "GOAT Report Out" to the agenda for next week's monthly call, with a few bullet points for some of the discussions that we can highlight. Let me know if there are any that you'd like to add! I can update the agenda (or feel free to do it yourself).
14:47mstenta[m]Starting with:
14:47mstenta[m]- OFN
14:47mstenta[m]- Conventions
14:47mstenta[m]- ... (there are so many, I'm sure the list will grow)
14:51symbioquine[m]<mstenta[m]> "This comment is interesting..." <- I found this blog post which is doing something similar to what that comment suggests: www.previousnext.com.au/blog/how-create-... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
14:57mstenta[m]symbioquine: was just going to ping you :-) www.drupal.org/project/farm/issues/33141
14:57symbioquine[m]Was just looking over that issue :)
14:57symbioquine[m]Hadn't seen the new comment though
14:58mstenta[m]Don't want to lose track of this one...
14:58mstenta[m]Ah that's interesting that it uses `onFieldDefinitionCreate()` from the `field_definition.listener` class...
14:58mstenta[m]I
14:59symbioquine[m]Yeah
14:59mstenta[m]I've had to do a few things with that service recently, so I wonder if this means that service is responsible for updating the field map
15:00mstenta[m]In theory (high level) there are probably two sides to solving this...
15:00symbioquine[m]There's also www.drupal.org/project/drupal/issues/312 (though it doesn't make any proposal about where that `rebuildBundleFieldMap()` should be getting called.
15:00symbioquine[m]* getting called.)
15:01mstenta[m]1. Ensuring that OUR code (which adds `hook_farm_entity_bundle_field_info()`) rebuilds the field map when necessary (probably via `hook_modules_enabled()` so it runs whenever new modules get enabled)
15:01mstenta[m]2. Add an update hook to FIX any missing fields on existing installs
15:01symbioquine[m]Makes sense
15:02mstenta[m]I'm guessing we can do (1) in a way that will gracefully relinquish control to Drupal core if/when the issue is resolved upstream
15:02mstenta[m](check if the field is in the field map, and only add it if it's not)
15:03mstenta[m]This may not necessarily need to BLOCK the stable release... but I wanted to make sure we don't forget to consider it and ask that question
15:03mstenta[m]It's certainly a bug, but perhaps edgy enough that we can do it post-2.0.0
15:06symbioquine[m]I could go either way. I'm blocked on it, but I can understand if the intersection between current write API clients and custom fields is small enough to justify punting a bit.
15:07mstenta[m]Yea - I just mean if everything else is ready to go on 2.0.0, maybe this doesn't need to be a blocker
15:07symbioquine[m]I've at least got to find a work-around for myself, but that's my problem :)
15:08mstenta[m]Yea! I'm curious if we can hack together a simple PHP script that would just rebuild the field map on-demand
15:08mstenta[m]As a proof of concept for the ultimate fix
15:08mstenta[m]Have you ever used `drush php-script`? It's a quick way to test stuff
15:09symbioquine[m]I can't remember for sure, but I vaguely recall a past work-around involving that.
15:09symbioquine[m]Might have been for the issue where I couldn't upgrade drush so I had to call the php version of some method directly.
15:11mstenta[m]I'm gonna try something real quick...
15:12symbioquine[m]mstenta[m]: Famous last words 😬
15:15mstenta[m]symbioquine: So... we have two ways to add bundle fields... do you know if both of them are affected? Or just those added via this hook?
15:15mstenta[m](The other way is via the PHP bundle class)
15:16mstenta[m]farmos.org/development/module/entities/#
15:16mstenta[m]vs farmos.org/development/module/fields/#bu
15:16symbioquine[m]Hmmm, you mean like the "nickname" field for animals?
15:16mstenta[m](the former is for adding them to entity types defined by the same module, the latter is for adding them to entity types defined by ANOTHER module)
15:16mstenta[m]yea
15:17symbioquine[m]I don't think that's affected since I have code that sets that
15:17symbioquine[m]I can test real quick
15:17mstenta[m]ok great
15:17mstenta[m]ok yea if you can
15:17mstenta[m]that would be a much bigger issue if that didn't work
15:17symbioquine[m]Agreed
15:21symbioquine[m]This works;... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
15:21mstenta[m]Ok great
15:21symbioquine[m]github.com/farmOS/farmOS/blob/7694b2cbd3
15:22mstenta[m]Looking through farmOS core's implementations of that hook now... I see three (apart from tests):
15:22mstenta[m]1. `farm_equipment` uses it to add the `equipment` field to all log types (to specify which equipment asset performed a task)
15:22mstenta[m]2. `farm_quick` uses it to add the `quick` field to all assets and logs (to specify which quick form created a record)
15:22mstenta[m]3. `farm_sensor_listener` uses it to add a `public_key` field to `sensor` assets (for legacy v1 listeners)
15:22mstenta[m]Question: does this prevent READING (and filtering) on those fields via the API? or only writing?
15:23mstenta[m](1) and (2) are important... especially being able to WRITE the `equipment` field (1)
15:24mstenta[m]If READING isn't an issue, then (2) doesn't matter too much...
15:24mstenta[m]And (3) is very minor
15:25mstenta[m]Re: (1) and (2) I'm questioning now why we are adding those as "bundle" fields and not "base" fields - because they are being added to ALL bundles anyway
15:25mstenta[m]So we may be able to easily transition those to "base" fields to fix them
15:26symbioquine[m]Yeah, reading and filtering works fine. It's just writing that's broken.
15:26mstenta[m]I'd like to ask paul121 if he has any memory of why those are defined as "bundle" fields and not "base" fields tho...
15:26mstenta[m]Ok good to know
15:33*sent a code block: libera.ems.host/_matrix/media/r0/downloa
15:34mstenta[m]That's a start... it just loads all the bundle field definitions added via `hook_farm_entity_bundle_field_info()`
15:34mstenta[m]You can put that in `sites/all/scripts/rebuild-field-map.php` and then run it via `drush php-script sites/all/scripts/rebuild-field-map.php`
15:34mstenta[m]So I'd be curious if we can figure out how to manually update the field map...
15:34mstenta[m]Using this to test it
15:36symbioquine[m]Cool!
15:36mstenta[m]Maybe just:... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
15:36mstenta[m]Maybe you could test that?
15:36mstenta[m](Might want to backup your `db` dir first)
15:37symbioquine[m]yeah
15:37mstenta[m](So you can reset)
15:37symbioquine[m]I'll test that shortly here...
15:38mstenta[m]Cool! I'm going to do a little more research on the issue overall... curious to understand how this relates to core vs `entity` module
15:38mstenta[m]Because that will inform how we ultimately should fix it
15:39mstenta[m]It *sounds* like it's just a core issue related to `hook_entity_bundle_field_info()`... and NOT related to `entity` module's "bundle plugin" stuff (which is what allows us to define bundle fields in the bundle PHP classes)
15:40mstenta[m]The `hook_farm_entity_bundle_field_info()` hook that we added in farmOS core was added so that we could allow OTHER modules to add to those, basically...
15:40mstenta[m]And Drupal core's `hook_entity_bundle_field_info()` does not do that, IIRC... And there's also an open issue that suggested that hook is going to change, so we decided to make our own to provide a forward-thinking BC layer (again IIRC)
15:41mstenta[m]www.drupal.org/node/2346347
15:41mstenta[m]Related tracking issue in our queue: www.drupal.org/project/farm/issues/31942
15:42mstenta[m]We are definitely pushing the envelope a little bit with these bundle fields... using `entity` module + our custom hook as additional layers on top of Drupal core's field system, which didn't fully support bundle fields the way we wanted
15:42mstenta[m]So I'm optimistic that we can fix this bug in our layer
15:43mstenta[m]If you can confirm that the script above fixes it, then I think the next steps might be pretty clear cut...
15:44mstenta[m](Hmm although I wonder if that `onFieldDefinitionCreate()` is also going to try to CREATE the field...)
15:44mstenta[m](We might need to dig into that method and isolate the field map bit only)
15:44symbioquine[m]Maybe a dumb question, but couldn't the `buildFieldDefinitions` method just invoke a hook that lets modules add bundle fields in the way that already works?
15:44mstenta[m](Or dig deeper into the `entity` module to figure out why it's not being called for these fields)
15:45mstenta[m]What `buildFieldDefinitions` method?
15:45mstenta[m]Oh you mean in the bundle classes?
15:46mstenta[m]> (Or dig deeper into the `entity` module to figure out why it's not being called for these fields)
15:46mstenta[m]Yea! That might be what I mean by this ^
15:46symbioquine[m]mstenta[m]: e.g. in github.com/farmOS/farmOS/blob/04bf771d91
15:46mstenta[m]The `entity` module is responsible for calling all of those `buildFieldDefinitions()` methods...
15:47mstenta[m]BUT we're doing some tricky stuff to add MORE definitions via our `hook_farm_entity_bundle_field_info()`... so it seems those are being missed
15:47symbioquine[m]symbioquine[m]: or maybe github.com/farmOS/farmOS/blob/04bf771d91
15:47mstenta[m]github.com/farmOS/farmOS/blob/2.x/module
15:48*sent a code block: libera.ems.host/_matrix/media/r0/downloa
15:48mstenta[m]So to summarize: `entity` (contrib) module adds the ability to define bundle fields in those PHP classes via `buildFieldDefinitions()`... but our custom code is responsible for adding more fields to that via `hook_farm_entity_bundle_field_info()`
15:49mstenta[m]So I think this is our fault (or oversight)
15:49mstenta[m]Maybe we need something else in our `class FarmEntityBundlePluginHandler extends BundlePluginHandler`
15:49mstenta[m]To get them into the field map
15:50mstenta[m]Digging into `entity` module code now to refresh on how all that works...
15:56mstenta[m]Here is where `entity` calls: `onFieldDefinitionCreate()`
15:56mstenta[m]git.drupalcode.org/project/entity/-/blob
15:58mstenta[m]Hmm... seems like this should be working... 🤔
15:58mstenta[m]Oh wait maybe not!
16:02symbioquine[m]In that script, the `\Drupal::service('field_definition.listener')->onFieldDefinitionCreate($bundle_field);` line fails with;
16:02*uploaded an image: (5KiB) < libera.ems.host/_matrix/media/r0/downloa >
16:03symbioquine[m]Haven't gotten to the bottom of that yet...
16:04mstenta[m]Oh hmm
16:04mstenta[m]Try adding this right above the `onFieldDefinitionCreate()` line:
16:04mstenta[m]`$bundle_field->setTargetEntityTypeId($entity_type);`
16:04mstenta[m]Might also need:
16:04symbioquine[m]Ah, yeah I was wondering if it might need something like that
16:04mstenta[m]`$bundle_field->setTargetBundle($bundle);`
16:05mstenta[m]Yea I'm guessing our hook doesn't add that kind of info to the definition, but it is needed (and gets added downstream by `entity` module somewhere)
16:06mstenta[m]I'm going to have to jump off to take over with my daughter in a bit... but currently setting up a test module so I can step through the existing code w/ debugger
16:06symbioquine[m]Cool, take care
16:20mstenta[m]Well, didn't make it super far, but it does seem that `onFieldDefinitionCreate()` in `entity` module is NOT running for the field in my test module
16:20mstenta[m]Next step is to figure out why...
16:21mstenta[m]I think you've successfully nerd-sniped me with this symbioquine 😅
16:21symbioquine[m]Got it working...
16:21*sent a php code block: libera.ems.host/_matrix/media/r0/downloa
16:21symbioquine[m]followed by a `drush cr`
16:22*uploaded an image: (98KiB) < libera.ems.host/_matrix/media/r0/downloa >
16:22symbioquine[m]^ Note the `quick` field is set
16:23symbioquine[m]> <@symbioquine:matrix.org> Able to reproduce it with the quick module enabled;... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
16:24symbioquine[m]mstenta[m]: Could it be because the field definition doesn't have the name (or those other attributes) set?
16:26mstenta[m]Awesome!!
16:26mstenta[m]grokking...
16:26mstenta[m]so you also had to set the name? that makes sense too
16:27symbioquine[m]Yeah
16:27mstenta[m]> Could it be because the field definition doesn't have the name (or those other attributes) set?
16:27mstenta[m]Maybe
16:27symbioquine[m]and I took `\Drupal::keyValue('entity.definitions.bundle_field_map')->deleteAll();` from www.drupal.org/project/drupal/issues/312
16:27symbioquine[m]Which was (especially?) important because I'd run it previously without some of those attributes set.
16:27mstenta[m]Oh yea, so that just clears the field map?
16:27symbioquine[m]yep
16:28mstenta[m]Not sure I understand why that's necessary... 🤔
16:28symbioquine[m]Even then, it didn't take effect until I cleared the cache also
16:28symbioquine[m]mstenta[m]: I suspect it wouldn't be if I was starting from scratch...
16:28mstenta[m]ok
16:28symbioquine[m]But I didn't like seeing
16:28*uploaded an image: (45KiB) < libera.ems.host/_matrix/media/r0/downloa >
16:29symbioquine[m]^ that entry with the empty string key :)
16:29mstenta[m]Well I'm going to focus a bit of time stepping through the `entity` (and `farm_entity`) module code to see if I can see where/why it isn't getting added...
16:30mstenta[m]Ahh hmm actually I think I know why...
16:31mstenta[m]`onFieldDefinitionCreate()` gets called by `BundlePluginInstaller::installBundles()`... but that only happens when NEW bundles are being installed
16:31mstenta[m]NOT when fields are being added to existing bundles
16:31mstenta[m]So yea... this all makes sense
16:31mstenta[m]And suggests we need to add some logic to `farm_entity` to cover this
16:32mstenta[m](and ideally an automated test)
16:32symbioquine[m]So we might be back to the solution of using `hook_modules_enabled` and comparing whether the field is already in the field map?
16:32mstenta[m]Maybe... unless there's a class in `entity` that we can override/extend
16:33mstenta[m]Like we're doing with some of the others
16:33symbioquine[m]I see
16:33mstenta[m]That feels like the "right" solution
16:33symbioquine[m]Makes sense
16:33mstenta[m]But... it may be that `entity` doesn't handle this AT ALL
16:33mstenta[m](updates to existing bundles)
16:34mstenta[m]I'm not seeing anything that suggests it does...
16:34mstenta[m]> So we might be back to the solution of using `hook_modules_enabled` and comparing whether the field is already in the field map?
16:34mstenta[m]So yea... this might be the only way
16:35mstenta[m]I'm curious if we can add a simple automated test for this to show that it fails currently
16:35mstenta[m]I haven't done any tests that use the API yet... but I think we have some...
16:35symbioquine[m]The corresponding removal case on module disable sounds harder
16:35mstenta[m]Mmmmm yea good point
16:36mstenta[m]Well... there is also `hook_modules_uninstalled()` I think
16:36mstenta[m]api.drupal.org/api/drupal/core%21lib%21D
16:36symbioquine[m]but we'd need a way to tell which of the fields came from `farm_entity_bundle_field_info` and now need to be removed right?
16:37mstenta[m]So maybe we just need a generic function that compares the field map against the list of bundle fields, and updates the map accordingly
16:37mstenta[m]Yea
16:37symbioquine[m]Maybe just clear it and rebuild?
16:37mstenta[m]Yea maybe that's easiest
16:37symbioquine[m]That script that starts with clearing seems to work - though I don't know if there would be any unintended side-effects
16:38symbioquine[m]Seems like the most obvious one is that two such hooks couldn't co-exist
16:38mstenta[m]What do you mean?
16:38mstenta[m]Oh two hooks that cleared/rebuilt?
16:38symbioquine[m]yeah
16:38mstenta[m]Gotcha
16:39symbioquine[m]If they rebuilt using different sources of information, whichever one ran second would win
16:39mstenta[m]True
16:39symbioquine[m]The base and normal bundle fields would survive, but the fields they added after that wouldn't be safe.
16:39mstenta[m]I think we are deep enough into farmOS-y edge cases here that that would be pretty unlikely :-)
16:39symbioquine[m]Might not be a big deal assuming there's only those two ways in farmOS for bundle fields to be added.
16:40mstenta[m]Yea
17:04symbioquine[m]So it turns out that `\Drupal::keyValue('entity.definitions.bundle_field_map')->deleteAll();` is dangerous and we shouldn't do that...
17:04symbioquine[m]It was wiping out fields like `plant_type` on the `seed` asset.
17:04mstenta[m]Okedoke!
17:05symbioquine[m]For future reference here's a one liner to get the field map for assets; `drush php-eval 'print_r(array_keys(\Drupal::service("entity_field.manager")->getFieldMap()["asset"]))'`
17:06symbioquine[m]I restored an older DB backup and then the following script worked...
17:06*sent a php code block: libera.ems.host/_matrix/media/r0/downloa
17:07mstenta[m]Ok
17:07mstenta[m]So... I realized: I don't know how these bundle fields are being installed in the first place 🤔
17:07mstenta[m]Trying to figure that out now... because obviously they are being INSTALLED (not only when the bundle itself is installed)
17:08mstenta[m]So maybe there is still an opportunity to jump in at that point
17:08symbioquine[m]mstenta[m]: Yeah, that seems especially clear now that I've found that they don't come back after `\Drupal::keyValue('entity.definitions.bundle_field_map')->deleteAll()`
17:09symbioquine[m]symbioquine[m]: whereas some of the fields do get automatically re-added to the field map somehow
17:09symbioquine[m](might only be base fields)
17:09mstenta[m]So yea actually... I think this really does just boil down to the core issue you found originally...
17:09mstenta[m]I think the `entity` module is just calling core hooks to get the bundle fields to be installed... but delegating to core to install them
17:10mstenta[m]But core is not adding bundle fields to the field map
17:10symbioquine[m]Sounds right
17:10mstenta[m]So yea... maybe coming back to `hook_modules_installed()` :-)
17:10mstenta[m](as a general solution to that)
17:11symbioquine[m]It doesn't seem to hurt anything (that I've run into yet) to call `\Drupal::service('field_definition.listener')->onFieldDefinitionCreate($bundle_field);` redundantly
17:12mstenta[m]ok that's good
17:12symbioquine[m]As a work-around, couldn't I just put that in my `hook_farm_entity_bundle_field_info`?
17:12symbioquine[m]I mean the script probably is also a viable work-around for me, but I'm just asking...
17:13mstenta[m]Hmm I don't think that would work... because `hook_farm_entity_bundle_field_info()` is just defining the fields... it isn't installing them yet... so if you run `onFieldDefinitionCreate()` in that hook then it may run before the field is actually installed
17:14mstenta[m]Maybe it would work, depending on how all the downstream code works, but feels risky
17:14symbioquine[m]oh
17:14mstenta[m]Oh and also: `hook_farm_entity_bundle_field_info()` is run for other things besides installing the fields...
17:14mstenta[m]So that would mean it would run that in places where fields aren't being installed
17:18mstenta[m]> The corresponding removal case on module disable sounds harder
17:18mstenta[m]This is still the bit that might be challenging I think...
17:19mstenta[m]`hook_modules_uninstalled()` runs after the module is installed, so we won't have access to the `hook_farm_entity_bundle_field_info` provided by it
17:20mstenta[m]but maybe we can figure out how to run that hook even after it has been uninstalled
17:20mstenta[m]and then just remove those fields from the field map
17:21symbioquine[m]Can we use the `provider` attribute of the field definition? api.drupal.org/api/drupal/core%21lib%21D
17:21mstenta[m]OH!
17:21mstenta[m]Good idea!
17:21symbioquine[m]Or maybe we just need to set that and core will take care of removing it on uninstallation?
17:21mstenta[m]Goooooood question! We DO set that!
17:22mstenta[m]github.com/farmOS/farmOS/blob/7694b2cbd3
17:22mstenta[m]I remember paul121 added that
17:22symbioquine[m]Ah, I see it github.com/farmOS/farmOS/blob/c92d181c45
17:23mstenta[m] // Set the provider for each field the module provided.
17:23mstenta[m] // This is required so that field storage definitions are created in the
17:23mstenta[m] // database when the module is installed.
17:23mstenta[m]yea!
17:23mstenta[m]I wonder if it handles uninstall already
17:23symbioquine[m]But I'd need to set that in the script also...
17:23mstenta[m]Well let's give something a try... I'm sketching up the `hook_modules_installed()` right now...
17:23mstenta[m]So maybe we can test this without the script
17:30*sent a code block: libera.ems.host/_matrix/media/r0/downloa
17:30mstenta[m]Completely untested... this should go at the top of `farm_entity.module`
17:30symbioquine[m]Any idea why `invokeAllWith` wouldn't be available when calling it from `drush php-script`?
17:30mstenta[m]Hmm not sure
17:31symbioquine[m]k, no worries
17:31mstenta[m]The above hook intends to update the field map for modules when they are installed... but will not update existing fields
17:31mstenta[m]So you may need to test by uninstalling and reinstalling your module (or make a test module)
17:32mstenta[m]I'm going to test with my test module to see if it works...
17:32symbioquine[m]Yeah, I'll probably uninstall/reinstall the farm_quick module to test
17:34symbioquine[m]> <@mstenta:matrix.org> ```... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
17:34mstenta[m]oops broken...
17:34mstenta[m]Hmm not sure that's necessary
17:34mstenta[m]Because we're setting it elsewhere
17:34mstenta[m]But I guess we'll see
17:34symbioquine[m]Makes sense
17:35symbioquine[m]Depends where the bundle field uninstallation logic sources that value I guess.
17:36mstenta[m] * ```... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
17:36mstenta[m]I'll update my paste above as I test this...
17:38mstenta[m]i think it worked!
17:39symbioquine[m]I don't see that `hasImplementations` method in api.drupal.org/api/drupal/core%21lib%21D
17:39symbioquine[m]Am I missing something?
17:43symbioquine[m]Ah, I see
17:43symbioquine[m]It should be `->getModule($module)->hasImplementations(...)`
17:43mstenta[m]Oh... it was added in Drupal 9.4
17:44symbioquine[m]symbioquine[m]: nvm, it's not that ^
17:44mstenta[m]www.drupal.org/node/3000490
17:45mstenta[m]You might still be on 9.3?
17:46symbioquine[m]Maybe something like;... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
17:46symbioquine[m]Would be backwards compatible (if that matters)
17:46mstenta[m]Yea that's the old way
17:46mstenta[m]Well farmOS `2.x` is on Drupal 9.4, so we don't need BC
17:46symbioquine[m]mstenta[m]: Yeah, I have an outstanding todo to get my dev environment updated 😒
17:47symbioquine[m]Might have to bump that up the priorities...
17:48symbioquine[m]Was trying to get ready to inventory a whole bunch of seeds first, but it might actually be blocked on this
17:48mstenta[m]Maybe you can help me test the update hook instead
17:48mstenta[m]I don't think that will need `hasImplementations` because it will try to update ALL modules
17:49mstenta[m]Lemme see if I can give that a quick pass
17:49mstenta[m]FYI this is what I see after I install my `farm_bundle_test` module, which adds a `test_field` to activity logs
17:49*sent a code block: libera.ems.host/_matrix/media/r0/downloa
17:50symbioquine[m]> <@mstenta:matrix.org> ```... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
17:50mstenta[m]oh will it? didn't think of that
17:50symbioquine[m]Yeah I think `\Drupal::service('entity_type.manager')->getDefinition($entity_type);` fails
17:51symbioquine[m]Gotta go feed the dog/chickens... back in a few
17:51mstenta[m]I'll add:... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
17:53mstenta[m]ah dang... well... uninstalling does not remove the field from the field map :-(
17:53mstenta[m]so we need that too
18:53symbioquine[m]Here's my working `hook_modules_installed`;... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
18:53mstenta[m]Yea same
18:53mstenta[m]Testing now...
18:53mstenta[m]I'm actually just about done sketching up the uninstall bit too (generalized the logic into a helper that just swaps out the method call depending on install/uninstall)
18:54symbioquine[m]> <@mstenta:matrix.org> I'll add:... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
18:54symbioquine[m]mstenta[m]: Awesome!
18:54mstenta[m]Oh really? 🤔
18:54mstenta[m]Did you get an error?
18:54symbioquine[m]It wasn't returning null, it was throwing an error;
18:54*uploaded an image: (6KiB) < libera.ems.host/_matrix/media/r0/downloa >
18:55symbioquine[m]Instead I ended up doing;... (full message at <libera.ems.host/_matrix/media/r0/downloa>)
18:55mstenta[m]Oh your function is different than mine
18:55symbioquine[m]Could be another Drupal version difference?
18:56mstenta[m]`$entity_type_definition = \Drupal::service('entity_type.manager')->getDefinition($entity_type);` should return `NULL` if the type doesn't exist (I think)
18:56mstenta[m]did you find that was not the case?
18:56mstenta[m]or did you just refactor everything so it wasn't using `hasImplementations()` and so that didn't matter anymore?
18:56symbioquine[m]I think so, but can test again...
18:57symbioquine[m]mstenta[m]: I think that's a different issue
18:57mstenta[m]sorry i think we've forked a bit :-)
18:57mstenta[m]but it will be hard for you to test on 9.3
18:58symbioquine[m]I'll get myself updated here shortly...
18:58mstenta[m]ok cool
18:58mstenta[m]i have to leave in a few minutes, but testing install/uninstall now...
18:58symbioquine[m]mstenta[m]: If I add `\Drupal::service('entity_type.manager')->getDefinition('plan');` near the top of that hook it fails like so;
18:58*uploaded an image: (6KiB) < libera.ems.host/_matrix/media/r0/downloa >
18:59mstenta[m]oh ok
18:59mstenta[m]good to know
18:59symbioquine[m]If I comment it out, it works.
18:59mstenta[m]so then yea, i'll probably need to adapt to use your approach
18:59symbioquine[m]Unless that's also a Drupal 9.4 behavior difference
18:59mstenta[m]oh i doubt that
18:59symbioquine[m]In which case you could leave it
18:59symbioquine[m]k
18:59mstenta[m]i haven't tested without `plan`
19:00mstenta[m]but my uninstall test just failed :-(
19:00mstenta[m]gotta leave to get my son, will have to pause this
19:00mstenta[m]i think i know what the next steps are though
19:00mstenta[m]should have some time to work on it this weekend
19:00symbioquine[m]Awesome, thanks for the help on this!
19:00mstenta[m]yea! same to you!
19:01mstenta[m]i think we may need to replicate some of the logic in `onFieldDefinitionCreate()` and `onFieldDefinitionDelete()` but not all of it (just the field map stuff basically)
19:02mstenta[m]because it's trying to delete the field in `onFieldDefinitionDelete()` but can't find the table
19:02symbioquine[m]mstenta[m]: Hmmm
19:02mstenta[m](since it's already been uninstalled)
19:02symbioquine[m]mstenta[m]: ah, bummer
19:02mstenta[m]so i think we just need a field map update method basically
19:02mstenta[m]more targetted
19:03mstenta[m]shame, was hoping we could just call the core code
19:03mstenta[m]but it's a bit intertwined
19:03symbioquine[m]Or contribute a patch that provides some way for it to work without the table there
19:03symbioquine[m]Seems pretty important for code to be able to clean up that field map even after a module is removed
19:03mstenta[m]perhaps... but then maybe we should juts contribute a patch to fix the overall issue
19:04symbioquine[m]haha yeah, slippery slope argument invoked
19:04mstenta[m]haha yea
19:04mstenta[m]ok well until next time!
23:11mstenta[m]symbioquine: jeez i dunno... maybe it is worth a drupal core patch 😬
23:12mstenta[m]i get nervous copying all this logic for maintaining the field maps... if drupal core ever changes it for whatever reason, and we don't follow suit, it could break
23:15symbioquine[m]Yeah
23:15mstenta[m]Reading the core issue in more detail now...
23:15mstenta[m]But at least we're on the right track I think :-)
23:16symbioquine[m]Especially as it pertains to that caching
23:17mstenta[m]It's interesting... I'm curious what else the field maps are used for
23:17mstenta[m]Surprised we didn't notice this earlier
23:18mstenta[m]But I guess it's just not used for most normal bundle field logic (UI, Views, etc all work fine)
23:23mstenta[m]I think the issue makes sense... I'm adding a comment now
23:23mstenta[m]A patch might not be too hard actually...
23:24mstenta[m]The bigger question is what's the "right" way to solve it. @joachim suggested one, but it feels a little ugly. It should work effectively in theory though.
23:24mstenta[m]This bit:
23:24mstenta[m]> I guess we could get a list of each implementation from the module manager, and skip field module's implementation? That feels pretty ugly though.
23:25mstenta[m]I'm summarizing better in my comment... standby :-)

< 062022-10-07⋏08 >