Problem/Motivation
Currently claro_preprocess_field_multiple_value_form() assumes the table header structure created by template_preprocess_field_multiple_value_form(). But other extensions may change the structure of it (e.g. by adding sub-items in that particular cell). , The Paragraphs module e.g. does this for its action buttons in the table header. This has been no problem yet, because its preprocess hook was last in line, due to the fact, that the other core themes did not implement one on their own.
With Claro as the new admin theme though, this acts on top of the changes the Paragraphs module makes and reverts it back to the "default" structure for adding its custom CSS class on the field label.
Proposed resolution
- Fix the issue in the following places:
template_preprocess_field_multiple_value_form(). Convert the title to ahtml_tag#typeclaro_preprocess_field_multiple_value_form()- Make appropriate changes to Claro's CSS to ensure consistency and BC
Remaining tasks
Review
User interface changes
n/a
API changes
- A potentially new variable structure for the table header cell, if a solution is chosen that changes the structure on core level
Data model changes
n/a
Release notes snippet
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #60 | 3099026-60-9.5.x.patch | 3.96 KB | mherchel |
| #59 | interdiff-51-59.txt | 918 bytes | mherchel |
| #59 | 3099026-59.patch | 3.98 KB | mherchel |
| #57 | Screen Shot 2023-03-07 at 8.16.25 PM.png | 73.98 KB | smustgrave |
| #57 | Screen Shot 2023-03-07 at 8.15.57 PM.png | 68.91 KB | smustgrave |
Comments
Comment #2
hctomComment #3
hctomThinking more about it, I'd say the fix/preparation for this has to be done in core.
template_preprocess_field_multiple_value_form()should be changed like this:With this approach by adding the
field_labelkey (or whatever it should be named) allows others to target that specific output structure. Claro then may act on it inclaro_preprocess_field_multiple_value_form()like this:...and Paragraphs may add its buttons in
paragraphs_preprocess_field_multiple_value_form()without completely rewriting the structure via:What do you think? If this is the way to go, I'd love to provide a patch for these changes.
Comment #4
hctomHere is a patch that changes the initial table header structure by using a
field_labelkey for the field label part of the header cell. Claro'sclaro_preprocess_field_multiple_value_form()also gets adjusted for that.Let's see what happens ;)
Comment #5
taiger commentedHey I tried that patch in #4 but the issue persists.
A little extra css fixes it for me:
Edit: this is for a different issue.
Comment #6
hctom@Taiger, is it possible that you added your comment to the wrong issue? ;) I see no CSS issues here so far... and the patch in #4 does only "solve" the actual problem by changing the structure of the cell data, so it is easier to alter/extend.
Comment #7
taiger commentedYes, you are right @hctom. The issue I am seeing is that dropbutton multiple is visually broken on Claro. I will create a new issue and a patch.
Comment #8
bartlangelaanI have applied the patch from #4, but when testing this with the Paragraphs module it showed a new bug: the title was duplicated. This is because Claro expects there to be a field_label, while the paragraphs module actually moves that key to another place. This means that the title is now both in the place that Paragraphs moves it to, and in the re-definition done by Claro.
I think a better approach is moving the repeated logic from Claro to core. This means that the improvements in structure already built in Claro (so it's easier to extend attributes in a table header) are implemented in core, and Claro only has to extend the attributes.
This doesn't involve a new (nested) variable structure, which should limit the adjustments needed by contrib modules (if any).
Patch is attached.
Comment #9
bartlangelaanOops, created the patch on the core subtree split instead of the drupal git. This is the same patch with a different root.
Comment #10
jwilson3Before:
After:
Before:
After:
The reason is that Classy theme has a CSS rule, that affects the layout of the
<h4 class="label">inside the table header:But Claro uses its own
.form-item__labelclass on the h4 instead of the "label" class. And the analogous CSS snippet for the display is different:What's more is that Paragraphs module is overriding that class and setting it back to
label, however this has no effect because even though Claro's base theme is Classy, it overrides and disables the form.css from classy/base library.In conclusion, I think that making any additional modifications regarding point 3 is out of scope of this issue. The visual aberrations pointed out in 3 only happen with contrib module. Core by itself is unaffected. Possibly, yes, a follow-up core issue could be filed to restore the expected inline display style for form labels, but an issue like that might not make it anywhere quickly. Instead, I think the responsibility of fixing the table header layout issues lies with the Paragraphs module in a patch on the related contrib issue #3099024: Paragraphs actions button are removed when Claro admin theme is used.
Thanks @hctom for your work identifying the original issue from Paragraphs, for filing the core issue with patch!, and @bartlangelaan for improving the patch.
RTBC.
Comment #12
lauriiiSeems like unrelated random failure
Comment #13
lauriiiI discussed with @alexpott about backporting this to 8.8.x. He recommended not backporting this to 8.8.x because this imposes some risk on contrib modules. I did some research in the contrib environment and it seems like there's another module that is making similar alterations with Claro. Committing this wouldn't directly break the module, but it will remain incompatible with Claro until they've made some changes.
I made some minor documentation improvements to the patch.
Now that we're not overriding the attributes, the
labelclass added bytemplate_preprocess_field_multiple_value_formfunction is now rendered in Claro. I think we should remove that to make sure this doesn't have any impact to what is rendered in the UI.Comment #15
lukusI saw this issue initially through use of paragraphs - some of the head actions had been incorrectly removed.
Patch #13 works well to rectify.
Comment #16
nicolas s. commentedPatch #13 works for me, button Edit All / Collapse All is now visible
Comment #17
saschaeggiComment #18
saschaeggiComment #19
lauriiiAddressed #13.
Comment #20
saschaeggiWorks for me on 8.9.x
Comment #21
bnjmnmI found two modules with evidence of current usage that have a
preprocess_field_multiple_value_formthat effectively undoes the change this patch makes to theme.inchttps://www.drupal.org/project/paragraphs_sets | usage: http://grep.xnddx.ru/node/30426268
https://www.drupal.org/project/require_on_publish | usage http://grep.xnddx.ru/node/30435042
It would be good to either
#prefixclaro_preprocess_field_multiple_value_formapply in instances where those modules are installed.I believe the patch is good to go other than that.
Comment #22
hctomI just looked through the changes in the new patches apart from my initial patch in #4. As we are changing the structure here and contrib modules like paragraphs or the ones stated in #21 definitely have to react on those changes, why don't we group the new render array structure under a dedicated array key as I did in my first path in #4?
With the current proposed solution, contrib modules still have to "hack" that column by either prefixing/suffixing the actual
<h4>element to add custom stuff. It would be way cleaner to have the<h4>element for the title in a self-contained render array item, so new items may be added or the title even removed completely.Of course this may lead to problems with duplicate output right now (as said in #8 with paragraphs module), but the contrib modules will have to react on this change anyway, so they may also be faced with a better render array structure that is easier to customize. If we don't do it that way, we don't solve the problem here, we only change the actual problem.
Of course there has to be a change record for this change then...
What do you think?
Comment #23
bnjmnmRe #22:
#8 points out that this results in duplicating the title in his setup. This would also happen with the modules mentioned in #21. It is true these module undo the fix in #19, they would also undo the fix with patch #4 AND the title would be duplicated.
What modules in #21 are doing this is completely unnecessary and inefficient since they duplicate (literally pasted) steps from
template_preprocess_field_multiple_value_form(). It's not an ideal approach, but these modules are have enough usage to justify alerting them of this change (particularly paragraphs_sets, which is already D9 compatible).Comment #24
hctomYes they duplicate the code, because they are forced to do so currently - there is no other way to add attributes without duplicating that code. That's one of the reasons why I opened up this issue.
The current proposed solution (changing the element to a pure render array approach) helps a little, but with title's render array structure still at the root of the cell's data array, contrib modules, themers etc. will continue to be be forced to "hack" their changes into the cell when not only wanting to add/change an attribute.
Paragraphs module is a really good example for this: It rewrites the cell's data array structure, so the title added by core is found under
titlekey and the module's own buttons are added under the newbuttonkey.My question right now is, why we do not provide the title under a dedicated key right from the beginning in core. All other modules/themes would then be able to add any number of new elements to the data array, without having to juggle around the initial structure or at worst have to pre-render their custom markup to add it to
#prefix/#suffixof the actual title's render array structure.Of course this will have duplicate titles here and there, but it is an easy fix for the contrib modules and that's what change records are for: To inform about changes that may need work on the contrib/custom side.
Comment #25
rdeboerJust to say that for those on D8.9.x the patch from comment #9 is still working very nicely for me, today 12 Sep 2020.
In fact the patch works great in combo with another paragraph/Claro D8.9.x patch at comment #89 in this issue: https://www.drupal.org/project/drupal/issues/3092181
Together these 2 patches solve all my Claro+paragraphs troubles in D8.9.x !
Comment #27
johan den hollander commentedAlso here to confirm the #9 patch still applies to 8.9.11 and fixes the missing paragraphs dropdown for me which is needed for the drag and drop functionality.
Comment #28
bnjmnmRe #24
I've seen committers reject patches with BC-breaking changes far less severe than what could happen here, it's unlikely the currently solution would be accepted into core. It doesn't really meet the "We will take reasonable efforts to not break code that developers may be relying on." part of Drupal's Backwards Compatibility Policy, particularity since it's a solution for a Claro-specific problem that impacts all sites regardless of the themes in use. I think there are untapped "reasonable efforts" that can provide a backwards compatible version of this solution.
I have some suggested alternate approaches. None of them are ideal, but preferable to a BC break, and 2/3 of them are specific to Claro - the only theme that requires this change. Someone may be able to figure out a way to do one of these more cleanly.
@@ -797,26 +797,15 @@ function claro_preprocess_field_multiple_value_form(&$variables) {
+ $variables['table']['#header'][0]['data']['#attributes']['class'][] = 'form-item__label';
+ $variables['table']['#header'][0]['data']['#attributes']['class'][] = 'form-item__label--multiple-value-form';
This problem is happening because Claro is adding/removing few presentation-changing classes from the header of a multivalue form. This class addition/removal logic could be removed from claro_preprocess_field_multiple_value_form altogether, and the styles could be applied via different selectors. If it deviates from Claro's conventions a comment could explain why this is preferable to a BC break.
I agree that this should have been implemented differently in the first place, and it's not pleasant to support BC for a non-ideal implementation. However, it's hard to justify BC breaks unless it's clear all options have been exhausted, and I think some options (however odd) still exist.
Comment #29
hctom@bnjmnm: Thanks for your detailed feedback. I'm totally with you regarding the BC issues with my initial approach, but I still worry that the current solution from #19 will not finally fix the actual issue and there may be similar issues in the future with other modules trying to change the header.
So here are my two cents to your suggested approaches:
template_preprocess_field_multiple_value_form()has been changed drastically somewhere in between which sound a little impossible. Especially because some other module/theme might even change the order of preprocess hooks being firedI still advocate to change the actual render array structure by moving the heading under a dedicated array key and provide a change record for that. In my opinion that is the only way to really solve this issue forever.
I guess with this, we actually have a case, where implementation detail code has to be changed to make a real improvement...
Comment #30
saschaeggiComment #32
timohuismanThis is probably not the right solution, but it works in our situation. I've used the patch from #17 and added a few lines of css to make it work with the paragraph module.
Comment #34
jwineichen commented#32 patch worked for me as well (with the specific goal of getting the paragraphs actions links to appear)
Comment #35
stefank commentedHi @timohuisman,
Thanks for the patch. I can confirm #32 works as expected. I was wondering, if a paragraph has a sub-paragraph if that should be expended as well.
Comment #37
gilmordwrong issue, removed my comment
Comment #38
robcarrPatch at #32 worked for me to solve problems with Paragraphs Table module
Comment #40
ericdsd commentedHi, Patch #32 worked for me over core 9.4.7.
Comment #41
ravi.shankar commentedAdded reroll of patch #32 on Drupal 10.1.x.
Comment #42
pradhumanjain2311 commentedTry to fix yarn run errors.
Comment #43
robcarr+1 for RTBC on patch #42
Comment #44
maskedjellybeanPatch #42 works great for me, thanks!
I agree with the comment in #10 that the height of the table header should be shorter. The H4 on the left and the buttons/options on the right do not need to be stacked vertically. One possible solution with the current markup (at least on a Paragraph field) would be
.field-multiple-table thead label { display: inline-block; }.Comment #45
tcrawford commentedPatch #42 works great for me, also (tested 9.4.x). Thank you very much.
Comment #46
tcrawford commentedMoving to RTBC due to the positive feedback.
Comment #47
lauriiiWe could technically add support for array type of attributes too if that increases the chances of this working
Can we add comment explaining that this is to try to keep the styles working even when there are modules overriding the markup
Comment #48
mherchelPatch updated per #47. Creating CR shortly.
Note that I also tried to make the CSS a bit more resilient, but in doing so, it negatively impacts Paragraph's CSS. So, IMO the current CSS is correct because of BC.
Comment #49
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #50
mherchelCR created at https://www.drupal.org/node/3344342. Please double check this, I'm not entirely positive that what I wrote is 100% correct.
Comment #51
mherchelComment #52
smustgrave commentedCould the Issue summary be updated some? The proposed solution mentions there needs to be discussion. If a decision has already been made can it be documented there please.
Thanks!
Comment #53
mherchelAgree. Adding the "Needs issue summary update" tag.
Note that since the patch has been created and still needs review, I'm setting this back to "Needs Review". Please see the documentation at https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...
"Needs work" is only for:
Comment #54
smustgrave commentedWill leave in review but if the proposed solution isn't clear any reviewer can't review the patch to see if the approach being proposed is being followed.
Comment #55
smustgrave commentedSince it's been about a week moving back to NW as the issue summary does need to be updated.
Don't want it to rot away in the review queue.
Comment #56
mherchelComment #57
smustgrave commentedActually turned into a great improvement for paragraphs
Tested by installing paragraphs and making a dummy bundle with just a simple boolean field
Without the patch. I can't drag and drop the header
With the patch I can!
Comment #58
lauriiiIsn't the isset check here sufficient?
What I was thinking of doing here originally was something like:
However, I'm not certain we need to because it looks like we have other instances where we are already assuming that #attributes are instances of
\Drupal\Core\Template\Attribute. Because of this, it's probably fine to just remove the second second condition from here.Comment #59
mherchelRemoved the second condition per #58. Patch interdiff attached. Thanks!
Comment #60
mherchelAttached is the same patch as above but for 9.5.x.
IMO this bug is a major usability issue when paired with the popular Paragraphs module (which is why I'm working on this), and should be ported to 9.5.x.
Comment #61
smustgrave commentedGet the same results still using #59 so marking it again.
And agree with the comment made in #60 that this makes paragraphs better as it shows a feature that I actually didn't know existed.
Comment #63
lauriiiWe are allowed to change the render arrays in minor releases based on https://www.drupal.org/about/core/policies/core-change-policies/frontend... so we don't have to implement a BC layer for this. However, we cannot backport this to 9.5.x because of the potential BC concerns.
Committed 90897af and pushed to 10.1.x. Thanks!