< 172022-06-18⋎19 >

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
09:00*tool172[m] has quit (Quit: You have been kicked for being idle)
09:00*AnasHaddad[m] has quit (Quit: You have been kicked for being idle)
17:46mstenta[m]paul121: I got it working!
17:54paul121[m]Woo! What was the trick?
17:54mstenta[m]Setting `'#parents' => $element['parents']` in the `value` element
17:54mstenta[m]* => $element['#parents']` in
17:55mstenta[m]That basically tells Form API to treat the value as the element's canonical value
17:55mstenta[m]Regardless of whether or not `#tree` is ued
17:55paul121[m]Ah okay I was curious about #parents!!!
17:55mstenta[m]s/ued/used/
17:55paul121[m]Perfect
17:55mstenta[m]And then a few minor tweaks to `GeofieldWidget`
17:55mstenta[m]Just to respect the new structure
17:57mstenta[m]I actually found the ansewer in core's `Radios` element, and corresponding `OptionsWidgetBase` (for Field API)
17:58mstenta[m]the `radios` element essentially creates a single element with a bunch of single `radio` elements inside it
17:58mstenta[m]And the `OptionsWidgetBase` uses a custom `#element_validate` to then do a bit more transformation into the format that Field API needs
18:01mstenta[m][OptionsWidgetBase](git.drupalcode.org/project/drupal/-/blob)
18:01mstenta[m]s/[OptionsWidgetBase](//
18:01mstenta[m]git.drupalcode.org/project/drupal/-/blob
18:01mstenta[m]Notably, now it works regardless of `#tree`
18:02paul121[m]Wonderful!
18:04mstenta[m]Will push updated branch shorty...
18:04mstenta[m]Still need to finish up docs, but if you have a chance to check out this commit and give the rest an overall thumbs up, then I can go ahead and merge when I'm done
18:04mstenta[m]I feel pretty good about this! :-)
18:05mstenta[m]Tested parsing a KML file into geofield too
18:05mstenta[m](Would be great to get automated tests for those things... but probably won't be able to add that this round)
18:09mstenta[m]github.com/farmOS/farmOS/compare/2.x...m
18:09mstenta[m]Here is the relevant commit: github.com/farmOS/farmOS/commit/9d817873
18:14paul121[m]Hmm sorry only on my phone, but I'm surprised to see the $delta reference removed from the GeofieldWidget. It seems like that is an important part of field widgets. We don't have multivalue geometry fields so it's not a big issue there, but makes me curious about this....
18:14paul121[m]Did you try adding farm_map_input to a nested array in a quick form? Just to make sure it uses the proper parents?
18:17mstenta[m]Ah hmm - let me try that
18:17mstenta[m]And maybe I can try a multi value geometry field too - good point
18:18mstenta[m]What do you mean by "adding farm_map_input to a nested array in a quick form"? Like put it into a fieldset with #tree = TRUE?
18:18paul121[m]If it's just multivalue geometry fields that don't work that's not as big of a problem.. maybe not worth blocking
18:19mstenta[m]Yea, but you're right... and if we can support it we should. Maybe the bigger question is: do multi value geometry fields work BEFORE this change?
18:19mstenta[m]I never tested it - are you aware of any existing limitations?
18:19paul121[m]Not sure!
18:21mstenta[m]> adding farm_map_input to a nested array in a quick form... (full message at libera.ems.host/_matrix/media/r0/downloa)
18:21mstenta[m] * > adding farm\_map\_input to a nested array in a quick form... (full message at libera.ems.host/_matrix/media/r0/downloa)
18:26mstenta[m]Hmm. Well multi-value geofields do not work.... But let me try checking out 2.x and testing on that too.
18:26mstenta[m]Still - I think you're right that `$delta` should stay
18:26mstenta[m](basically just remove the `value` bit, but leave `[$field_name, $delta]` in both places
18:26mstenta[m]i'll test that on a single value field as well
18:28mstenta[m]works (with `$delta` as described) on single-value field
18:28mstenta[m]so maybe multivalue geofields are just broken... testing on 2.x now...
18:28mstenta[m]if so, i'll open a separate bug report for that and we can figure it out later
18:29paul121[m]Cool. Yeah not as worried about that
18:29paul121[m]I gtg!
18:29mstenta[m]Cool thanks for the eyes!
18:29mstenta[m]If it's alright with you paul121 I'll merge this after these bits
18:31paul121[m]Oh.. are we deleting both geofield and geofield_widget? 😁
18:31mstenta[m]No just `geofield_widget`
18:31paul121[m]Oh nvm! Renaming the geofield behavior. Great
18:32mstenta[m]github.com/farmOS/farmOS/commit/a1a015cc
18:32symbioquine[m]mstenta[m]: I'm not sure "multivalue geofields" make much sense for single records in the farmOS data model...
18:32symbioquine[m]There's definitely a use-case for something like that though in quick forms and similar where additional data can be associated with each geometry.
18:32paul121[m]mstenta[m]: Yep
18:32mstenta[m]symbioquine: I agree. And we will probably never use them. But if the widget we provide is broken on multi-value fields it means NO ONE can use it.
18:33mstenta[m]So low priority... but still technically a bug.
18:33mstenta[m]Ah yes and in quick forms it works!
18:33mstenta[m]Just Field API that seems to be broken at the moment... testing 2.x branch now...
18:33symbioquine[m]mstenta[m]: Ah, I might not have been understanding the case you were talking about then...
18:34mstenta[m]AH DANGIT lol - multivalue geofields work in 2.x 🤦
18:34mstenta[m]So this actually breaks them :-(
18:34mstenta[m]Oh well... another thing to debug then...
18:35mstenta[m]Yea sorry symbioquine - there are two contexts: Form API (eg quick forms, other custom forms, etc) and Field API (entity forms) - it's the Field API mutivalue geofields that aren't working.
18:35mstenta[m]And we don't currently use "multivalue" geofields anywhere in the farmOS data model - nor should we ever IMO
18:36mstenta[m]But someone may want to add a Geofield to their own entity and use the farmOS map widget
18:36mstenta[m]("multivalue" == "Allow unlimited values" where you can click "Add another" and another map shows up to draw on)
18:37symbioquine[m]Makes sense
18:37symbioquine[m]but it would only break if they set the cardinality to >1 or unlimited right?
18:37mstenta[m]Yep
18:38mstenta[m]Which... I just tested, and technically that does work currently (in our 2.x branch), but does not work in this new branch... so I should debug it
18:38mstenta[m]Probably something simple...
18:39symbioquine[m]worst case could be using a `hook_form_alter` to throw an error that says multi-value Geofields aren't supported in farmOS and suggest that a single geofield that produces a geometry collection might be sufficient...
18:40symbioquine[m]Little hacky, but at least it would head-off other folks troubleshooting while it's still an outstanding bug.
19:01mstenta[m]OK! Got it working. :-)
19:02mstenta[m]Actually backtracked a little bit to the way we were trying to do this originally... using the validate method of the element (NOT the geofield) to set the value. And NOT using `#parents`...
19:03mstenta[m]`#parents` was the cause of the issue in multivalue geofields... because FormAPI was automatically adding another sub-element for `_weight` and that was then getting used for the value instead of `value` (not exactly sure I understand why... but that's what was happening)
19:07mstenta[m]ahhh wait... maybe not
19:07mstenta[m]oy
19:18mstenta[m]Huh. OK. Well I did get it working... drove me a little nuts for a second there...
19:18mstenta[m]I'm not sure I love how it's working. But it is working.
19:21mstenta[m]I'm going to need to give this some more thought....
19:35mstenta[m]Eh... well... here's a new commit for review if you have time/interest paul121
19:35mstenta[m]github.com/mstenta/farmOS/commit/e70b092
19:36mstenta[m]Main differences from the previous approach:
19:36mstenta[m]- No longer using `#parents`
19:36mstenta[m]- Setting the string value in the `farm_map_input` form element's validation method
19:36mstenta[m]- Overriding `#element_validate` in `GeofieldWidget` to NOT use `farm_map_input`'s validation method 🤷
19:37mstenta[m]The last point is the only bit I feel weird about...
19:37mstenta[m]But with that, and the only minor changes (in `FarmMapInput::valueCallback()` and `GeofieldWidget`), everything appears to be working
19:37mstenta[m]s/only/other/
19:40mstenta[m]It does all make sense... not that "weird" I suppose... just a touch less elegant maybe. But that might just be the nature of these unique circumstances we're navigating.
19:40mstenta[m]Anyway - signing off. Take a look if you are able. Thanks again for helping with this! :-)

< 172022-06-18⋏19 >