Problem/Motivation
When editing a view I can only add an attachment display type, regardless of what I select.
1. Edit existing view
2. Add -> block
Expected to add a Block display type,
Result is it adds an Attachment type.
Any selection under +Add creates an Attachment display instead of what was selected.
Proposed resolution
The problem for that is $elements['#values'] is now an array of TranslatableMarkup, so strict comparison fails.
The proposed solution is to cast each element to a string, before the comparision.
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
larowlanComment #3
longwaveBisected this to 0cd35ba0d0ccec12b11c5bc89809dd1712d0b03c which points to #2571673: Convert Views t() usage where it is used as an attribute value.
Debugging this further it seems that in FormBuilder::buttonWasClicked() the buttonvalue sent by the browser is "Block", but the form element value is "Add Block". As none of the submit buttons match this falls back to the first element by default, which is the attachment display.
views_ui_form_button_was_clicked() is supposed to override this behaviour for these buttons, but it has apparently stopped working.
Comment #4
longwaveIn views_ui_form_button_was_clicked(), $element['#values'] is now an array of TranslatableMarkup objects, but we compare this to a string with the third parameter of in_array() set to TRUE, so the comparison never succeeded. Removing the third parameter and letting in_array() cast the values instead allows the buttons to work again.
Comment #5
juxelle commentedTested the patch and it fixes the issue.
I tested adding every type of display to a view and they all work now after applying the patch.
Comment #6
juxelle commentedComment #7
tim.plunkettThis seems testable. Sorry for unRTBCing.
Comment #8
longwaveUnsure how to test this, as the button text is modified in JavaScript (see Drupal.behaviors.viewsUiRenderAddViewButton). drupalPostForm() needs the original button text to be able to find the correct form element. I tried this and a few variations but I could not get SimpleTest to post the form successfully:
Comment #9
longwaveFixing component
Comment #10
dawehnerLet me try my luck with a test.
Comment #11
alexpottThis makes one of the most common tasks in the views ui completely unusable.
Comment #12
alexpottLet's cast to string here. Also this is actually more complex as we need to decode HTML entities too. See #2571673: Convert Views t() usage where it is used as an attribute value
Comment #13
dawehnerHere is a test with a little bit of explanation what we do there. Yes, its tricky, no question.
Comment #15
longwaveSeems there is a way to do this in drupalPostForm() alone.
Comment #16
alexpottI think it is
element['#values']where we need to string cast. And then we can use strict typing for thein_array()again.Comment #17
dawehnerAh nice, much better.
Comment #18
longwaveI am not sure why the TRUE parameter was there at all, seems a bit overzealous, and the original commit offers no explanation: http://cgit.drupalcode.org/views/commit/?id=651a0da
But it is easy enough to explicitly cast, see attached.
Comment #21
dawehnerYeah I'm pretty sure that alex is super sensitive in some of his changes.
Comment #24
dawehnerAdded a better issue summary.
Comment #25
dawehnerI think this is ready to fly. Hit me, but I like if we break things so we end up with more test coverage.
Comment #26
webchickHoly hell, great work catching this one. :\
I've seen similar casting patches necessary in e.g. Drupal Module Upgrader, and I'm growing more concerned that we might have introduced a lot of these subtle and hard-to-track-down bugs by the recent changes in lieu of SafeMarkup. :\
Looks like alexpott's feedback has been addressed, so...
Committed and pushed to 8.0.x. Thanks!