IRC logs for #farmOS, 2022-02-08 (GMT)

2022-02-07
2022-02-09
TimeNickMessage
[15:20:20]<MarcosCarballal[>Hey all! I'm trying to export a few terms in taxonomies that I have populated by hand. I have tried using both the menu at http://localhost/admin/config/development/configuration and `drush cex` to get at these terms, but terms do not seem to get included in that export.
[15:20:21]<MarcosCarballal[>My understanding is that is happening because the terms aren't considered to be part of the configuration, rather they are treated as content.
[15:20:38]<MarcosCarballal[>Is there a better way to approach this? Most of our taxonomies will only have 4/5 terms, but we may need support for 100+ terms in the future.
[15:22:16]<paul121[m]>> My understanding is that is happening because the terms aren't considered to be part of the configuration, rather they are treated as content.
[15:22:16]<paul121[m]>Bingo! That is correct
[15:57:58]<MarcosCarballal[>Our lead Drupal dev pointed me to this module (https://www.drupal.org/project/structure_sync), which seems to allow us to export these terms. I just want to check that this seems like a good way to go about it
[15:59:23]<paul121[m]>Sorry had to jump off for a sec
[15:59:47]<paul121[m]>I had not heard of structure_sync, interesting
[16:00:18]<paul121[m]>We are a bit familiar with the default_content module which seems similar: https://www.drupal.org/project/default_content
[16:01:11]<paul121[m]>Another option may be to auto-create those terms in `hook_install()`
[16:01:35]<paul121[m]>(that's basically what these default_content/structure_sync modules do)
[16:03:46]<MarcosCarballal[>Interesting, could I just make a reference csv file and write a `hook_install()` which reads in this csv and populates the appropriate taxonomies?
[16:04:10]<paul121[m]>since this is a custom module I think that makes sense. for a more general/contributed module it's not "best practice" to do this sort of thing
[16:04:17]<mstenta[m]>Hey! Just got back from picking up the kiddos - I second the `default_content` recommendation!
[16:04:19]<paul121[m]>yup, exactly
[16:04:31]<mstenta[m]>I haven't used it myself, but I know someone who has - for the exact same reason (taxonomy terms)
[16:05:20]<mstenta[m]>But `hook_install()` works too! Either way - `default_content` might be more "automated" - although I can't speak from experience
[16:06:21]<MarcosCarballal[>I'll definitely check out the default_content module, I'm not sure that it has the "import/export" functionality that I need, though.
[16:07:01]<paul121[m]>Yeah. Just reading default_content a bit closer, it has built in support for drupal normalization and serialization - which is great when your content entities have many fields, different types, entity references, etc. But if your taxonomy is pretty simple, a simple csv or json list might be sufficient
[16:08:40]<mstenta[m]>Come to think of it... Marcos Carballal this might be helpful: https://github.com/farmOS/farmOS/blob/65879166fdbd9b59d4de5e2952406ea83f...
[16:09:03]<mstenta[m]>That's from farmOS 1.x (so might not work for 2.x!) but could serve as an example for loading from a CSV file
[16:09:08]<paul121[m]>if you need import/export support, you could make a `drush` command fairly easily too I think
[16:09:35]<mstenta[m]>In 1.x, the `farm_soil_nrcs` module imported a list of "STIR Operations" from this file: https://github.com/farmOS/farmOS/blob/7.x-1.x/modules/farm/farm_soil/far...
[16:09:53]<mstenta[m]>NOT into taxonomy terms... but maybe the CSV reading parts of that code would be useful at the very least
[16:10:25]<mstenta[m]>I'll dig up the other place where I know `default_content` was used... one sec...
[16:10:43]<MarcosCarballal[>Well I have been using `drush cex` and `drush cim` to get a feel for what these config files actually look like.
[16:10:43]<MarcosCarballal[>I was hoping for some magical `taxonomy.terms.{taxonomy_name}.yml` file or something similar.
[16:10:54]<mstenta[m]>https://github.com/mstenta/farm_nfa/tree/2.x/web/modules/custom/farm_nfa...
[16:11:14]<mstenta[m]>(that in this module: https://github.com/mstenta/farm_nfa/tree/2.x/web/modules/custom/farm_nfa)
[16:11:46]<mstenta[m]>the module depends on `default_content`: https://github.com/mstenta/farm_nfa/blob/9c272b0091b487a4a233b678b86542e...
[16:12:03]<mstenta[m]>so maybe that's all you need to do (export YML files, put them in the correct directory, and depend on `default_content`)
[16:13:01]<MarcosCarballal[>By "depend on `default_content`)", do you mean that we should add `default_content:default_content` to our list of dependencies for the module?
[16:13:29]<mstenta[m]>I think that would be necessary in order for `default_content` to be installed and find your term YML files
[16:13:51]<mstenta[m]>but you could potentially put that stuff in a sub-module that you only turn on for initial install and then turn them off again...
[16:14:01]<mstenta[m]>if you don't want to have default_content running on prod
[16:14:23]<MarcosCarballal[>Okay, stupid question, how would I install Drupal Module not present in the Admin > Extend section?
[16:14:23]<MarcosCarballal[>I tried `drush en {moduleName}` earlier, but it said that it could not find the module
[16:14:57]<mstenta[m]>oh yea - if you do `composer require drupal/default_content` that will download it to `web/modules`
[16:15:12]<mstenta[m]>and then it will appear in Admin > Extend, where you can install it
[16:15:27]<MarcosCarballal[>Awesome, I will make a note of that.
[16:15:53]<mstenta[m]>All of the above said... a simple CSV import via `hook_install()` would definitely be the lowest overhead overall - especially if you just have a list of terms to create, but those terms don't have additional metadata on them (like fields)
[16:16:29]<mstenta[m]>So those are the two ways you could explore :-)
[16:16:43]<mstenta[m]>Let us know what you go with! We've been talking about using `default_content` to create a `farm_demo` module - for prepopulating a demo instance with content to demonstrate to new users how things work
[16:18:11]<MarcosCarballal[>Yeah, I will try to parse through the CSV code example you gave. I am a bit hesitant making a custom CSV driven solution, but that also has the advantage of being easily replicable.
[16:35:19]<skipper_is[m]>Anyone connected a sewage treatment plant up to their FarmOS/Sensor? That's this week's project!
[16:37:34]<paul121[m]>sounds messy 🤣
[16:46:20]<mstenta[m]>Hahaha
[16:48:02]<mstenta[m]>@donblair did some stuff with depth sensors at one point (eg measuring stock/water tanks) maybe relevant?
[16:56:47]<skipper_is[m]>I'm trying to interface with the existing fault/alarm system on the plant, and to record rotation rates, and when the pumps are active that kind of thing
[16:57:03]<skipper_is[m]>It's all 24v though
[16:57:15]<mstenta[m]>Oh interesting