Use custom value on symfony2 choice form type using choice_list - symfony

I'm trying to use custom values in a choice form type which gets its data from a database query that needs post-processing. For this reason I opted to use the choice_list option and extending Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList\ChoiceList. The problem is that I need custom index/value for the resulting dropdown instead of the default 0-indexed style. 0-index doesn't work form me as I will access the values using Javascript and need the data I retrieved from the database.
I already tried replacing the createIndex() method in the ChoiceList class but to no avail :-(
Any tips?

I can't believe it...I have tried the whole day and couldn't find the answer. 5 Minutes after having published the question, I solved it.
For future research:
You need to overwrite the createValue() method in the Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList class.

Related

Algolia - WordPress - how can I get the actual query into JS variable to work with it further in the hits template?

I would like to do some interesting stuff with the hits that are being displayed based on the search query that user is not only typing into search box but actually filtering using the instant search filters. I have filter based on hierarchical events_location taxonomy. Based on what user selected I would get the info in JS variable that I can then further use to do other operations in the hits div, specifically on each hit card.
So my URL when searching updates like this:
/what-to-see/?q=&idx=sdbeta_posts_events&p=0&hFR%5Btaxonomies_hierarchical.events_calendar.lvl0%5D%5B0%5D=JUL%204&hFR%5Btaxonomies_hierarchical.events_category.lvl0%5D%5B0%5D=All&hFR%5Btaxonomies_hierarchical.events_locations.lvl0%5D%5B0%5D=Paddock%20Stage
I could potentially take the URL and extract the data from it, but I am sure there is more elegant way of working with the query.
In InstantSearch.js, the state is managed by another library called the algoliasearch-helper. Through this library you can read and write the search parameters.
The cleanest to access the helper is to build a custom widget, which is a plain object with lifecycle hooks (initial rendering and the other renderings). You can read more about custom widgets there.
Once you've accessed the helper, you can read and write with the helper API.
This can be found under search.searchParameters
So:
console.log(search.searchParameters);
Will give you whole object that you can then work with.
There is however one issue with this and that is that it works only on initial load. I was unable to make this work or get any data after starting to selecting categories. So if anyone knows how to use this so it updates after each selection please comment bellow.

How can I use the field I've added to the field group? AX7 Dynamics 365

All of my codes are in extensions.
I've added a field into the table, and also added that field into the assigned field group.
Now it is visible on my Design.
and I want to place a code into the event of it where it is modified.
So I've created a new class, then get the event handler.
But when I paste it, there's an error and I checked the intelisense and it can't see the field I placed, well in fact, it is there:
How can I use my newly added field? Is there something I am missing?
I can reproduce this problem in Platform Update 8. It seems to be a limitation of the product when working with controls added through field groups.
Nevertheless the solution is simple - use Modified event of the datasource field, not the individual control. That's what you should do in most cases anyway, because one field may be displayed at several places, but it should do the same thing when modified from either of them.
You can use the registerExtensionInstance method as described in this blog post and register override of the required control's method from method new.
You can see how the registerExtensionInstance pattern is used in a number of classes in AX:
CaseDetailEventHandler
DirPartyQuickCreateFormApplicationSuiteEventHandlers
EssWorkspaceFormExtensionAppSuiteEventHandler
EssWorkspaceFormExtensionExpenseEventHandler
FormControlQuickPersonalizationTileExtension
HCMCaseDetailCreateEventHandler
HCMCaseDetailEventHandler
HcmCaseDetailEventHandler_HcmWL
HcmEnrollmentDateManagerFormExtensionEventHandler
HcmJobFormExtensionRetailHandler
HcmPositionActionDetailFormExtensionPayrollHandler
HcmPositionDateManagerFormExtensionPayrollHandler
HcmPositionFormExtensionPayrollHandler
HcmPositionMassUpdateFormEventHandler
HcmWorkerDateManagerFormExtensionPayrollHandler
HcmWorkerEnrollmentFormExtensionPayrollEventHandler
HcmWorkerFormExtensionPayrollHandler
HierarchyDetailEventHandler
HRMCourseInstructorFormExtensionAppSuiteHandler
smmActivitiesEventHandler
smmContactPersonFormApplicationSuiteEventHandlers
SysGenBlankWorkspaceOptionsPowerBIExtension

2sxc List.Presentation in General View

I have an entity type "Post" and I would like to create a view that will show one random Post with a given category. I created a Data pipeline that grabs all posts and I created a view with ListPresentation = a "TemplateSettings" entity type that lets me choose categories.
I planned to use the Razor template to filter the items for those matching the categories in List.Presentation.Categories. But, I can't seem to reference List.Presentation.Categories. I get an error that System.Collections.Generic.List doesn't contain an entry for "Presentation". When I use #ListPresentation, the whole object in null... so #ListPresentation.Toolbar, etc. all throw errors, despite me having set a "Demo Item".
Can anybody see what would be wrong with this setup? How do I reference List Presentation stuff in Razor?
Thanks.
I figured this out... The direct thing seems to be "ListPresentation", but the snippets use "List.Presentation". Still, it wasn't working in my case because I was using a data query that didn't include the module data. So, I had to modify that query to include the module data as well as the full list of entities, regardless of the module. Then, I got the full list from one data stream, and the ListPresentation fields were available.
Note also that you can use ListContent.Presentation - that would be the newest, most consistent API which always places Presentation information as a property of the entity it's describing.

Add to Form Results from External Form

Is there an API for adding to the Form Results that results from standard Forms are added to from an External Form?
I want to try avoid adding to the tables btform, btformanswers, etc. manually
No.
See https://github.com/concrete5/concrete5/blob/master/web/concrete/core/controllers/blocks/form.php#L354-L415 -- the core's form block updates the table manually.
As johjoh says, you could theoretically mimic a post to a form block, by instantiating it and then calling action_submit_form(), but that's just as fraught with difficulty, too... you'd have to keep the "form" in sync with your data, and possibly worry about the token and block ID and all that....
What's your exact use case? New block type? Some sort of external API? The form viewing interface in the dashboard is nice, but nothing that special. I think most people want to get data out of it, not in....

How to add variable filters to Drupal 6 views via URL?

I'm currently using Drupal Views 2 to build custom views. This works fine so far, if there wasn't a feature needed: One should be able to filter the results by different fields via URL, in the form of:
http://domain/node/M/[key]:[value],[key2]:[value2],...,[keyN]:[valueN]
The key names are fixed and may not be altered.
I tried hooking hook_views_query_alter() and hook_views_pre_render() to generalize this for all views, evaluating the given filterset, but to no satisfying end, as i could not get hold of the query used to build the view (I could not alter it in the proper way, as i do not know the field names in the query).
The question is, if there is a nicer way to implement such a filterset.
thanks in advance,
flo
Looking at the comments you seem to want not only url arguments but url arguments in a custom format.
I would firstly urge you to drop your format and use the standard views argument format, this will be more standards compliant and save you a lot of headache.
If you want to use that paticular format you are going to have to write some custom code in a module.
Register a callback using hook_menu().
In that callback use arg() and decode your arguments.
Pass the arguments to views_embed_view(). as shown here

Resources