IRC logs for #farmOS, 2022-09-23 (GMT)

2022-09-22
2022-09-24
TimeNickMessage
[22:03:20]<evered[m]>Thanks y'all. Love and blessings to the team. Botanic Gardens was "lovely" today.
[02:12:24]<skipper_is[m]>It was because it had started life as a quickform, and had the farm_quick name, changed it and straight away worked
[08:57:28]<mstenta[m]>Ah great! Glad you figured it out skipper_is
[12:13:25]<skipper_is[m]>Yea, id10t error :)
[14:05:36]<skipper_is[m]>Trying to pull out the tag_ids. trying
[14:05:36]<skipper_is[m]>> $tag_id = $entity_wrapper_field_farm_animal_tag_id->value();
[14:05:36]<skipper_is[m]> Is this the right approach? Or is it an entity metadata wrapper?
[14:08:25]<skipper_is[m]>(I've made a typo, it should be $entity_wrapper->field*
[14:15:56]<skipper_is[m]>Or should I use farm_asset_property_get on `field_farm_animal_tag_id_value` ?
[14:39:20]<mstenta[m]>skipper_is: I have deleted the 1.x code from my brain to free up space 😅
[14:40:09]<mstenta[m]>ID tags were a "field collection" iirc
[14:40:43]<mstenta[m]>Which means they were technically a separate entity referenced by the animal asset
[14:41:09]<mstenta[m]>(If that helps at all. im on my phone so cant look closer right now)
[14:41:36]<skipper_is[m]>No worries. I'm now trying to figure out how to handle a field collection :)
[14:47:18]<mstenta[m]>field_collection_load($id) should work... just need the id
[14:47:26]<mstenta[m]>Which is referenced from the animal
[14:47:44]<mstenta[m]>Maybe grep for other examples of that
[14:48:20]<skipper_is[m]>The $id of the asset? or the field collection id?
[14:49:37]<mstenta[m]>FC
[14:49:40]<mstenta[m]>Not asset
[15:05:18]<skipper_is[m]>And to get the id of the fc, is that through the entity metadata wrapper of the asset?
[15:06:18]<mstenta[m]>Yea should be able to
[15:06:36]<mstenta[m]>There might be an easier way I forget
[15:07:11]<mstenta[m]>One sec gonna see if I can find an example... on my phone waiting to pick up kid from school :-)
[15:12:08]<mstenta[m]>Something like that
[15:12:09]<mstenta[m]>https://github.com/farmOS/farmOS/blob/509cfb2e928ef7537977a0f53eb93ee12a...
[15:12:09]<mstenta[m]>That's for loading a movement field collection, but same idea
[15:15:17]<skipper_is[m]>Gotcha, so field_collection_item_load($entity_metadata_wrapper->field_farm_animal_tag),
[15:15:46]<skipper_is[m]>Just need to find what sub-arrays its under
[15:34:23]<skipper_is[m]>Debug:
[15:34:23]<skipper_is[m]>'UK175206 141'
[15:34:24]<skipper_is[m]>Yes!
[16:10:29]<skipper_is[m]>And now it exports CSV! Good times! Right, leave it on a roll! Goodnight all
[16:16:18]* farmBOT has joined #farmos
[18:38:39]<paul121[m]>symbioquine mstenta curious if either of you have thoughts on this AJAX map chunk loading issue: https://www.drupal.org/project/farm/issues/3243922
[18:39:00]<symbioquine[m]>I've thought about it some...
[18:39:06]<paul121[m]>it was some time ago when we first discovered and there isn't much in the issue about potential solutions :-)
[18:40:43]<symbioquine[m]>The strategy I'm using for Asset Link may be an option. i.e. using a controller to dynamically set the path from which the chunks should be loaded as part of serving the JS library.
[18:41:39]<symbioquine[m]>The problem is I'm not sure how to do it without forcing all consumers of the library to use a similar strategy
[18:43:02]<symbioquine[m]>https://github.com/symbioquine/farmOS_asset_link/blob/77ccda2c1bf4c0c4ff...
[18:43:02]<symbioquine[m]>https://github.com/symbioquine/farmOS_asset_link/blob/77ccda2c1bf4c0c4ff...
[18:45:07]<paul121[m]>so `"/__THIS_GETS_REPLACED_AT_RUNTIME_BY_THE_DRUPAL_CONTROLLER__/"` ends up in the built JS?
[18:45:39]<symbioquine[m]>I also didn't see an easy way to use Drupal's library system out of the box. i.e. how do you say "this library entry-point is served by this controller/route" and have it take into account the current base path of the site
[18:45:46]<symbioquine[m]>paul121[m]: yes
[18:46:05]<symbioquine[m]>and gets replaced by the PHP code as it serves the JS entry-point/chunks
[18:47:04]<paul121[m]>ah yea, it needs to do it in each chunk
[18:47:12]<symbioquine[m]>symbioquine[m]: `.libraries.yml` clearly allows you to specify a URL for the library, but I didn't see a way to make it relative to the site's base path
[18:47:44]<symbioquine[m]>paul121[m]: maybe, I'm not totally sure if the path gets embedded into chunks other than the entry-point
[18:47:54]<paul121[m]>symbioquine[m]: ahhh interesting! the URL property might only be picked up if you set `external: true`
[18:48:07]<paul121[m]>that would be a clever approach
[18:49:00]<symbioquine[m]>Yeah, I thought so. But the documentation is pretty lacking as to if/how the url can point at the current site or a PHP controller therein
[18:52:25]<symbioquine[m]>symbioquine[m]: It looks like it gets embedded in a number of files that I'm pretty sure aren't entry-points
[18:52:42]<paul121[m]>I imagine you have read this, just sharing here... "Dynamically generated css and js" https://www.drupal.org/docs/creating-modules/adding-assets-css-js-to-a-d...
[18:53:44]<paul121[m]>> In the case of dynamic JS: please consider using configurable JavaScript instead, that is almost always the much better choice.
[18:54:25]<paul121[m]>could we write something that lets `publicPath` be configured in global JS?
[18:55:06]<paul121[m]>and let the `farm_map.js` specify the value?
[18:57:39]<symbioquine[m]>Supposedly, there's a way to set the public path at runtime by setting `__webpack_public_path__` but I haven't succeeded when I've experimented with it in the past...
[18:58:04]<symbioquine[m]>https://stackoverflow.com/questions/39879680/example-of-setting-webpack-...
[18:58:10]<paul121[m]>ohh just came across that
[18:58:18]<symbioquine[m]>https://webpack.js.org/guides/public-path/#on-the-fly
[19:13:44]<paul121[m]><symbioquine[m]> "Supposedly, there's a way to set..." <- https://stackoverflow.com/a/51245153
[19:13:44]<paul121[m]>seems like explicitly setting that in `app.js` is important. do you know if you tried that?
[19:13:49]<paul121[m]>I can give it a spin
[19:14:31]<paul121[m]>`app.js` == `main.js` for farmOS-map I believe
[19:16:00]<symbioquine[m]>I can't recall exactly what approaches I've tried, just that I remember experimenting with it in the past.
[19:31:49]<paul121[m]>okay, here is a start... adding this to line 1 of `main.js` works!
[19:31:49]<paul121[m]>```
[19:31:49]<paul121[m]>__webpack_public_path__ = '/libraries/farmOS-map/';
[19:31:49]<paul121[m]>```
[19:33:19]<paul121[m]>now to try something like:... (full message at <https://libera.ems.host/_matrix/media/r0/download/libera.chat/f62eebd5b9...)
[19:35:08]<paul121[m]>Seems to be working!!
[19:37:09]<symbioquine[m]>Huh, that's cool
[19:43:40]<paul121[m]>and we can populate this with a simple drupal JS library that the real `farmOS-map.js` entrypoint library depends on:... (full message at <https://libera.ems.host/_matrix/media/r0/download/libera.chat/33ee1bdea5...)
[19:44:47]<symbioquine[m]>Two problems with that part...
[19:44:51]<paul121[m]>now to not hard-code the `/libraries-farmOS-map/` ... Drupal must have a way to get that path, know off the top of your head?
[19:45:09]<symbioquine[m]>No :(
[19:45:59]<symbioquine[m]>The Drupal base path could be different and maybe even the library install path.
[19:47:18]<symbioquine[m]>That's why the controller strategy seems pretty elegant - is sidesteps those issues
[19:48:16]<paul121[m]>That's true
[19:50:57]<paul121[m]>I wonder if you could define a route in its place?
[19:51:32]<paul121[m]>Still make the library definition, but then override the path with a route/controller?
[19:52:38]<paul121[m]><paul121[m]> "I imagine you have read this..." <- they say here:
[19:52:38]<paul121[m]>> If the dynamic CSS/JS is built for each request, then you enter the truly advanced territory. This is hard, and for a good reason: per-request dynamic assets have to be built on every single request and therefore slow Drupal down. We want to make it hard to make Drupal slow down, so this is why we don't offer a nice API for this — since we don't want you to do it.
[19:52:38]<paul121[m]>It is possible though. In the case of dynamic JS: please consider using configurable JavaScript instead, that is almost always the much better choice.
[19:56:24]<mstenta[m]>What if we cache the path to the library file in Drupal state, and use that wherever we load the lib. Then it would point to the static file so Drupal wouldn't be used to fetch it (faster load) but it would still allow for dynamically determining the path to the file.
[19:58:26]<mstenta[m]>I don't know *how* exactly we "use that wherever we load the lib"... :-)