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

juxe created an issue. See original summary.

larowlan’s picture

Priority: Normal » Major
longwave’s picture

Bisected 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.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new1.11 KB

In 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.

juxelle’s picture

Tested 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.

juxelle’s picture

Status: Needs review » Reviewed & tested by the community
tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This seems testable. Sorry for unRTBCing.

longwave’s picture

Unsure 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:

    $this->drupalPostForm('admin/structure/views/view/test_display/edit/block_1', array(), 'Block'));
longwave’s picture

Component: views.module » views_ui.module

Fixing component

dawehner’s picture

Let me try my luck with a test.

alexpott’s picture

Priority: Major » Critical

This makes one of the most common tasks in the views ui completely unusable.

alexpott’s picture

+++ b/core/modules/views_ui/admin.inc
@@ -315,7 +315,7 @@ function views_ui_build_form_url(FormStateInterface $form_state) {
-  if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array($user_input[$element['#name']], $element['#values'], TRUE)) {
+  if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array($user_input[$element['#name']], $element['#values'])) {

Let'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

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests +D8 Accelerate
StatusFileSize
new1.53 KB
new2.64 KB

Here is a test with a little bit of explanation what we do there. Yes, its tricky, no question.

The last submitted patch, 13: 2579615-13-test.patch, failed testing.

longwave’s picture

StatusFileSize
new1.1 KB
new2.21 KB
new1.72 KB

Seems there is a way to do this in drupalPostForm() alone.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/views_ui/admin.inc
@@ -315,7 +315,7 @@ function views_ui_build_form_url(FormStateInterface $form_state) {
+  if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array((string) $user_input[$element['#name']], $element['#values'])) {

I think it is element['#values'] where we need to string cast. And then we can use strict typing for the in_array() again.

dawehner’s picture

Ah nice, much better.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB
new1.14 KB

I 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.

The last submitted patch, 15: 2579615-15-test-only.patch, failed testing.

The last submitted patch, 15: 2579615-15-test-only.patch, failed testing.

dawehner’s picture

Yeah I'm pretty sure that alex is super sensitive in some of his changes.

The last submitted patch, 13: 2579615-13-test.patch, failed testing.

The last submitted patch, 13: 2579615-13.patch, failed testing.

dawehner’s picture

Issue summary: View changes

Added a better issue summary.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I think this is ready to fly. Hit me, but I like if we break things so we end up with more test coverage.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Holy 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!

  • webchick committed 1e4c4c3 on 8.0.x
    Issue #2579615 by longwave, dawehner, juxe, alexpott: Views only able to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.