This is related to #2841067: Exposed flag filter can't show unflagged nodes when I set up a flag relationship I can also setup a "Flagged" filter. I can set it to not be required. All great. But I cannot set its default value to "". I can only set the default value to True or False. Other boolean filters like sticky allow an Any option when exposed:

CommentFileSizeAuthor
FlagAnyMissing.png36.47 KBgábor hojtsy

Issue fork flag-2993178

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Gábor Hojtsy created an issue. See original summary.

gábor hojtsy’s picture

BTW we are trying to build the "My favorite sessions" exposed filter for Drupal Europe daily schedule :)

joachim’s picture

1. Argh, I thought this had been fixed.

2. Argh, why are you using Flag? The use case is right, but Flag is ***NOT READY FOR PRODUCTION***. There are a ton of issues, including major issues around render caching and performance.

joachim’s picture

Are you sure you have the latest version?

In FlagViewsFilter:

    $form['value']['#options'] = [
      'All' => t('All'),
      1 => $this->t('Flagged'),
      0 => $this->t('Not flagged'),
    ];
joachim’s picture

Status: Active » Postponed (maintainer needs more info)
Y Pham’s picture

Default value is set 1. Use this patch to change to 'All' value.

in/views/filter/FlagViewsFilter.php
index 9b7f2ebe..281a9aa5 100644
--- a/modules/contrib/flag/src/Plugin/views/filter/FlagViewsFilter.php
+++ b/modules/contrib/flag/src/Plugin/views/filter/FlagViewsFilter.php
@@ -17,7 +17,7 @@ class FlagViewsFilter extends BooleanOperator {
*/
public function defineOptions() {
$options = parent::defineOptions();
- $options['value'] = ['default' => 1];
+ $options['value'] = ['default' => 'All'];
$options['relationship'] = ['default' => 'flag_relationship'];

return $options;

http://prntscr.com/krjpnf

ptmkenny’s picture

Status: Postponed (maintainer needs more info) » Needs work

Changing status to "Needs work" because #6 provides a solution but not a formal patch that can be tested on drupal.org.

ivnish’s picture

Issue tags: +Needs tests, +Needs reroll

mahima_mathur23 made their first commit to this issue’s fork.

mahima_mathur23’s picture

Resolved all PHPCS Issues.

ivnish’s picture

Issue tags: -Needs reroll
ivnish’s picture

Version: 8.x-4.x-dev » 5.x-dev
deaom’s picture

Status: Needs work » Needs review

Like mentioned in comment #4 this is already part of the module and works. When filter is exposed to visitors, the "required " check box needs to be removed. If the filter is not exposed to visitors, the default value is set to true. Don't think that changing it to All does anything.

The thing that this MR changes is the default value is no longer true, but All. Everything else stays the same. So not sure if this needs to be merged at all. Will rebase branch in case the desire is there to merge it.

ivnish’s picture

Status: Needs review » Needs work

Still needs tests

deaom’s picture

Status: Needs work » Needs review

Added a test that sets the exposed filter for flagging and checked that the - Any - options is visible on the actual page. Ready for review.

ivnish’s picture

Issue tags: -Needs tests
ivnish’s picture

Status: Needs review » Needs work

@deaom I tested this patch manually. It doesn't work as expected. When I selected "All" I get flagged nodes anyway. I think needs to extend the test and check which nodes were filtered

deaom’s picture

When you select All you should get flagged and unflagged, so not quite understanding what does not work when manually testing. Will try and extend the test.

deaom’s picture

Status: Needs work » Needs review

Updated the test to test that flagged and unflagged content is listed/displayed, now that Drupal is back, tests also passing. Ready for review.

ivnish’s picture

I forgot to remove "status" filter like this

$this->drupalGet('/admin/structure/views/nojs/handler/flag_bookmark/page_1/filter/status');
$this->assertSession()->elementExists('css', '#edit-remove');
$this->submitForm([], 'Remove');

(facepalm)

Tested again, it works as expected

ivnish’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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