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

2022-05-22
2022-05-24
TimeNickMessage
[22:58:24]* coralgoat has quit (Remote host closed the connection)
[22:58:36]* coralgoat has joined #farmos
[12:25:22]<MarcosCarballal[>ACTION uploaded an image: (197KiB) < https://libera.ems.host/_matrix/media/r0/download/matrix.org/jOUARhFEPIj... >
[12:25:24]<MarcosCarballal[>Hi all, we are wondering if there is a nice way to remove the map and filter from these asset list pages
[12:25:40]<MarcosCarballal[>I am imagining some `hook_page_altar` kind of logic.
[12:25:48]<MarcosCarballal[>s/hook_page_altar/hook_page_alter/
[12:27:54]<paul121[m]>Hi! Good question. For reference the map is added to those pages right here: https://github.com/farmOS/farmOS/blob/76a6fdf56326b4412623f106d9500119cd...
[12:28:36]<paul121[m]>We also dynamically add fields and filters to the `farm_asset`/`farm_log` and `farm_plan` views: https://github.com/farmOS/farmOS/blob/76a6fdf56326b4412623f106d9500119cd...
[12:28:55]<paul121[m]>So... rather than doing an alter, to undo the alter that we are doing...
[12:29:49]<paul121[m]>I think it would be easier to create a new view that overrides the path of our default views. It looks like your screenshot might be at `/assets/producer`
[12:30:23]<paul121[m]>So you could create a new table view of only producer assets and set the URL for `/assets/producer` and then get full control
[12:30:41]<paul121[m]>We have used this approach on a few projects
[12:32:55]<MarcosCarballal[>Gotcha, yeah I think that may be the way to go about it, but we haven't made any custom views yet. Do you have any resources on that?
[12:33:57]<paul121[m]>Here is the core `views` module docs: https://www.drupal.org/docs/8/core/modules/views
[12:34:24]<paul121[m]>You would enable the `views_ui` module to build the views via the UI and then export configuration
[12:36:21]<paul121[m]>There are some gotchas & considerations here - for example, if you include field(s) added by certain modules in your views (eg: `farm_equipment` adds the `equipment` field), then your view will now require that this module is installed. So some thought needs to be given to ensure that a view will work on all the sites you want to use it on
[12:37:00]<paul121[m]>I'm not familiar with the specifics of your project so mstenta might have thoughts in that regard :-)
[12:53:00]<MarcosCarballal[>Got it, I am imagining an incredible simple view for each of our assets which is just that bottom list of the assets with an edit button. And we would also need to concern ourselves with setting the edit route to our custom form, not the default form.
[12:53:56]<mstenta[m]>Agreed a custom View is the perfect way to do that!
[12:54:13]<mstenta[m]>Just go to /admin/structure/views and "Add View"
[12:55:00]<mstenta[m]>Views have different "displays" - so you'll want to start by adding a "Page" display
[12:55:19]<mstenta[m]>That will let you set the path you want (eg: `/assets/producers`), which should then override the default farmOS View
[12:55:25]<mstenta[m]>if it doesn't... let me know...
[12:55:56]<mstenta[m]>(by "override" I mean when you go to `/assets/producers` you'll see your View. without needing to edit/alter the farmOS View at all)
[12:58:35]<mstenta[m]>(I'm not super familiar with the precedence logic... so if it doesn't seem to override as expected then might need to fiddle with module weight and/or the machine name of the View... not sure. paul121 have you ever had trouble or did it "just work"? i wonder if "more specific" paths override "wildcard" paths, or if it has to do with weight)
[13:00:55]<MarcosCarballal[>I just tested out manually setting the path, unfortunately it is not taking precedence.
[13:02:16]<mstenta[m]>Just to be sure, did you "Save" the View?
[13:02:23]<mstenta[m]>(I sometimes forget to do that :-P)
[13:02:29]<MarcosCarballal[>I'm embarassed to say :{
[13:02:30]<MarcosCarballal[>Lol
[13:02:33]<MarcosCarballal[>Yes I just saved it
[13:02:35]<MarcosCarballal[>It worked
[13:02:41]<mstenta[m]>Woohoo!
[13:02:47]<mstenta[m]>:-D
[13:04:49]<MarcosCarballal[>Let me share that with the team
[13:05:43]<mstenta[m]>You can refer to the core farmOS View to see how that's set up (if you want to mimic some of the fields/filters)
[13:06:29]<mstenta[m]>FYI Views is basically just a fancy SQL query builder UI
[13:06:50]<mstenta[m]>So if you are familiar with writing SQL queries, then it should make some intuitive sense once you grok the UI
[13:07:04]<mstenta[m]>You can add fields, filters, sorts, and more advanced stuff
[13:07:25]<mstenta[m]>And control how it's displayed (eg: in a table with fields as columns)
[13:07:32]<mstenta[m]>Super powerful
[13:07:46]<mstenta[m]>And the View you create is basically just another YML config file
[13:07:55]<mstenta[m]>So it can be checked into source control in your custom module
[13:08:58]<mstenta[m]>All the options you see in the Views UI are provided by plugins of different types too... so if you need it to do something that it doesn't provide out of the box, chances are you can write a plugin for it
[13:09:08]<mstenta[m]>That's definitely an "advanced" topic... but that's how it works ;-)
[13:09:20]<paul121[m]>Yes and as mstenta has suggested before you can actually "duplicate" existing views! So it could be easier to duplicate the existing `farm_asset` view and delete all but the `page_type` display... but it is a bit overwhelming when you're starting out.
[13:11:38]<MarcosCarballal[>I had some very brief exposure to the views module. Looks like it could be simple. I dislike that the route is hidden away in the config file but oh well.
[13:12:33]<mstenta[m]>Yea that's just kinda how it works by default... If you really wanted to you could also create your own controller w/ traditional route in `*.routing.yml` and "embed" the View in that...
[13:12:45]<mstenta[m]>But I tend to just let the Views module handle it for me :-)
[13:14:48]<paul121[m]><mstenta[m]> "(I'm not super familiar with the..." <- reading a bit on this right now.... its a question of the routing system more generally. Drupal page views use the same routing system that forms and controllers use. Basically, Drupal will resolve a request to the most specific route available. So if you have `/assets/{asset_type}` (general, dynamic) and also `/assets/producer` (specific), the more specific one will be used.
[13:14:48]<paul121[m]>So creating custom views with a hard-coded path feels pretty safe! This would get more complex if you wanted to take-over the dynamic `/assets/{asset_type}` path in either a custom view or controller. In that case you might need to use an alter hook and/or disable the conflicting view.
[13:15:14]<paul121[m]>> <@mstenta:matrix.org> (I'm not super familiar with the precedence logic... so if it doesn't seem to override as expected then might need to fiddle with module weight and/or the machine name of the View... not sure. paul121 have you ever had trouble or did it "just work"? i wonder if "more specific" paths override "wildcard" paths, or if it has to do with weight)
[13:15:14]<paul121[m]> * reading a bit on this right now.... its a question of the routing system more generally. Drupal *views with a page display use the same routing system that forms and controllers use. Basically, Drupal will resolve a request to the most specific route available. So if you have `/assets/{asset_type}` (general, dynamic) and also `/assets/producer` (specific), the more specific one will be used.
[13:15:14]<paul121[m]>So creating custom views with a hard-coded path feels pretty safe! This would get more complex if you wanted to take-over the dynamic `/assets/{asset_type}` path in either a custom view or controller. In that case you might need to use an alter hook and/or disable the conflicting view.
[13:16:36]<paul121[m]>I think mstenta recorded a video of this process for farmOS 1.x... there are some differences but all the views concepts (and even the views UI) is largely the same!
[13:20:16]<mstenta[m]>Oh that's great - I was hoping "specific takes precedence" was the way it worked :-)
[13:20:42]<mstenta[m]>Ha I don't remember that video, but I wouldn't be surprised! 😅
[13:31:36]* coralgoat has quit (Remote host closed the connection)
[13:32:05]* coralgoat has joined #farmos