Hi,

It seems that there is a bug with how the flag relationships are being displayed in views. Proof of concept:
1. Create two flags.
2. Create a view and add flags relationship and select 2nd flag (2nd radiobox).
3. Save view - it will select and save with correct radiobox (flag) selected.
4. However, after saving (refreshing) and opening relationship modular window again the 1st flag's radiobox is selected. Thus, after pressing save button for second time, the first radiobox will be selected and saved.

Drupal core: 8.1.7

Comments

Gugols created an issue. See original summary.

davisa’s picture

Issue summary: View changes
joachim’s picture

Priority: Normal » Major
Issue tags: -Flag

Confirming the problem.

(BTW: please don't add random tags to issues. There's no need to duplicate any of the information in the other fields, such as the project name!)

joachim’s picture

The culprit appears to be this:

    $default_value = $this->options['flag'];
    if (!empty($flags)) {
      $default_value = current(array_keys($flags));
    }

If there are flags defined, set this to the first flag, and ignore the value from config! What on earth...?

And this is why code should have comments, because I can't figure out what the original author was intending to do here.

joachim’s picture

Issue tags: +Release blocker
rbayliss’s picture

Status: Active » Needs review
StatusFileSize
new710 bytes

Easy enough to fix.

joachim’s picture

+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -37,7 +37,10 @@ class FlagViewsRelationship extends RelationshipPluginBase {
+    // If no flag has been chosen yet, open the form with the first flag
+    // selected.

I do like a patch that adds comments! :)

However, looking at this again, there's a problem with our form if we're showing something as selected when the underlying config is empty. Showing the user something that doesn't match the configuration is a UI bug.

rbayliss’s picture

Ok, so this patch removes the presetting of the flag altogether. The edit form now opens with no flag selected.

  • joachim committed 971ea7b on 8.x-4.x authored by rbayliss
    Issue #2775193 by rbayliss: Fixed Views flag relationship showing wrong...
joachim’s picture

Status: Needs review » Fixed

That's great! Thanks!

Status: Fixed » Closed (fixed)

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