wrapper for accordion content is getting added from JS. Check the below code for reference.
if (!this.usegroupheader) {
$(this).siblings().wrapAll('<div></div>');
row_count++;
}
This works fine out of the box. However it creates issues in some other use cases mentioned below:
Issues:
- In case of multiple grouping of fields, The h3 and div structure gets messed up.
- When extending the views_accordion plugin, The JS produces unwanted HTML structure. Hence making the extensibility of the views_accordion plugin difficult.
Possible Solution:
- Instead of adding this
element from JS, Add it in TWIG file views-accordion-view.html.twig.
This will help the extensibility easy.
Comments
Comment #2
kunalkursija commentedComment #3
kunalkursija commentedAdding Patch.
Comment #4
kunalkursija commentedComment #5
manuel garcia commentedThanks @kunal.kursija for this.
I am opened to this idea, and it is true that multiple grouping is a unsolved problem right now.
Quick review of the patch:
The JS only adds the wrapping div if
this.usegroupheaderis false (if that setting is off), so we'll have to do the same on the twig side, or using the group header as the accordion header will break.About extending the plugin, I never really thought about it other than to override specific things, so I can't see how this gets affected by what you describe (I'd appreciate an example).
Comment #6
kunalkursija commentedHi @Manuel Garcia,
Yes, I noticed the todo comments w.r.t multiple grouping inside the plugin file.
Agreed with the conditional adding of wrapping div. However, i noticed that
this.usegroupingis always true for both single and multiple grouping.Reference- Check below code in
public function preRender($result)The above piece of code makes the 'usegroupheader' as always TRUE, because of which the div tags from JS gets added every time.
Yes, I came across this issue when porting the
views_nested_Accordionmodule to D8. A little bit about that module:So during my porting exercise, I noticed that the 'div' getting added from JS was causing an issue.
Please let me know what do you think.
Also for reference: Here is the issue regarding the D8 port of views nested accordion: https://www.drupal.org/node/2893497
Comment #7
manuel garcia commentedThanks for kindly explaining the issue @kunal.kursija
This is not correct,

usegroupheaderis only TRUE if there is at least 1 grouping configured, AND if the option Use the group header as the Accordion header is enabled. Otherwise its always FALSE, since the optionuse-grouping-headerdefaults to 0.So we do need to take into consideration this setting when we are printing the
div;-)Comment #8
manuel garcia commentedWe now have some basic test coverage, so triggering the tests here.
Comment #9
manuel garcia commentedSetting it back to needs work based on #5 & #7.
Comment #10
manuel garcia commentedComment #11
manuel garcia commentedAdded some test coverage for field grouping on #3035375: Add test coverage for field grouping, let's see how the patch tests with it.