Problem/Motivation
We have a site using the Highcharts.js submodule and request from the website admins to disable all but the Pie and Donut chart types because they do not want their teams using the more exotic charts. (Less is more on a marketing site for a University with 10s of vetted content editors and marketers).
I had a look to try to disable the chart types on my own, but quickly found that nothing I tried worked, including a hook_form_alter() and even registering a #prerender and #after_build function.
Fundamentally, the problem is that :
- The hook_form_alter is called before #prerender has had a chance to run. Since all the extra fields are added in a #prerender there is nothing there to edit from the hook_form_alter
- Registering a #prerender from the hook_form_alter runs before the #prerender tasks added by the charts module, so again there is nothing to alter.
- Registering an #after_build from the hook_form_alter executes after the entire form has been rendered, so too late to be able to alter the items.
I'm looking for a documented approach to be able to disable or otherwise manipulate the Highcharts form elements, either programatically or via settings screen.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork charts-3426704
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jwilson3Comment #3
jwilson3After trying several things, this was my last attempt before giving up and writing up this ticket.
I don't know if this was on the right path or not, but we ran out of time and budget to keep pushing on this at the end of the sprint.
THIS CODE DOES NOT WORK.
Comment #4
andileco commentedThanks for sharing your work! We'll take a look.
Comment #8
andileco commentedThis is fixed. In this situation, you would use code like this in MYMODULE.module:
This new hook, which is added to charts.api.php, could also allow you to add additional chart types.
Comment #9
jwilson3This is fantastic. Thank you so much for your responsiveness here and for introducing the new hook as a solution to alter the charts.
Unfortunately there were other changes we were hoping to make to the edit forms as well. It seems like it's still impossible to alter the form presentation to do things like collapse the chart details element wrapper when data is already provided.