Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting default values in the quick form using url params #9

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

wotnak
Copy link
Contributor

@wotnak wotnak commented Jun 20, 2023

Adds option of setting default values in the quick form using url params. This can be useful for creating an action or link for a specific asset that will redirect to the egg harvest quick form with the asset preselected. It can also be used for example to generate qr code that can be printed and placed next to a specific chicken coop that will open the egg harvest form for a specific flock.

Supported url params:
assets=<id>,<id>,...
quantity=<number>

@mstenta
Copy link
Member

mstenta commented Sep 13, 2023

I wonder if we could leverage the new "configurable quick forms" concept that will be included in farmOS v2.2.0 instead. That will allow this quick form to be made "configurable", which means we can declare configuration for it (such as default values), and save that to configuration entities. This will also allow multiple "instances" of the quick form to be created (eg: one for each set of configuration that you want), and there can be multiple dedicated URLs for each quick form configuration (eg: /quick/eggs1, /quick/eggs2, etc).

Would that accomplish the same goal, I wonder?

@mstenta
Copy link
Member

mstenta commented Sep 13, 2023

@wotnak
Copy link
Contributor Author

wotnak commented Sep 13, 2023

If the goal is to set static default values, then creating configuration sets for them could work. Although, depending on the amount of the configuration sets needed, just having a single form instance with the ability to dynamically override defaults may be more convenient than creating multiple instances where each one has a different url and menu item. Another use case that query param based default values overrides could be useful would be to create some dynamic links/actions for use in the context of assets designated as laying eggs.
Making this quickform configurable with the ability to among other options provide default values would be nice but even then having an option to dynamically override the default values using query params would be in my opinion a useful option.

@wotnak
Copy link
Contributor Author

wotnak commented Sep 13, 2023

I'm currently using this for adding 'Record egg harvest' actions in a few places:

  • bulk action on assets list view,
  • button next to 'Produces eggs' field display on asset page,
  • local action on asset pages.

wotnak@b8872fa

@mstenta
Copy link
Member

mstenta commented Oct 19, 2023

@wotnak I've been meaning to follow up on this (I have it marked unread in my inbox so I don't forget). I agree this would be a good addition.

What I'm thinking now is: it would be great if we could solve this in a generalized way. I brought this up on a call with @paul121 today and an idea emerged...

Currently farmOS includes a QuickPrepopulateTrait::getPrepopulatedEntities() method, which I think could be used as-is to cover the asset reference portion of this PR. However, we do not have a method for handling prepopulated "values" more generally (only entity references).

So what if we add a new QuickPrepopulateTrait::getPrepopulatedValue() method in farmOS core, which can be used for any string value, and then this PR can be simplified to just add use QuickPrepopulateTrait; at the top of the class, and '#default_value' => $this->getPrepopulatedValue() and '#default_value' => $this->getPrepopulatedEntities() in the buildForm() method?

Notably, @paul121 pointed out that QuickPrepopulateTrait::initPrepoluatedEntities() checks for input from BOTH the query string AND private temporary storage. The latter is used for populating quick forms from bulk actions. See https://farmos.org/development/module/quick/#providing-a-quick-form-action

So, we could also consider a followup PR here that adds a "Record egg harvest" bulk action, and it would be a simple next step. Although maybe there are other considerations there (we don't want that showing up on all asset types, for instance).

What do you think about this idea @wotnak?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants