Problem

When Flag is turned on an error appears when configuring contextual filters in Views, making it impossible to update the contextual filter configuration.
The config screen displays the message An illegal choice has been detected. Please contact the site administrator. The on-site log says Illegal choice *relationship* in Flag element.

It seems that Flag tries to force the relationship to use a flag, even when there is none (or that relationship is not applicable).

Proposed resolution

See #2

Original report by skizzo

When I try to configure a node view's contextual filter (Content: Has taxonomy term ID, Specify validation criteria, Taxonomy Term) I get the following errors

- An illegal choice has been detected. Please contact the site administrator.
- log report: Illegal choice *relationship* in Flag element.

If I disable the Flag module then I can edit and save the View configuration without any problem. My flag configuration includes only a node-type flag, not global, applied to the same content type selected by the View.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Itangalo’s picture

Title: Illegal choice *relationship* in Flag element » Illegal choice *relationship* in Flag element causes Views contextual filters to fail
Version: 7.x-2.0-beta6 » 7.x-2.x-dev

Confirming this issue (and updating the title).
Bug also confirmed in latest dev version (as of April 2nd 2012).

Itangalo’s picture

Status: Active » Needs review
FileSize
709 bytes

Ok, attached is a patch that solves this for me.

It appears that the problem is not the relationships, but the argument validator. It introduces a select list in the validation options that can't be set when you don't have any flags relationships in the view. The default choice has the value *relationship*, and form API complains that this is not a valid choice.

I think the patch solves the problem, but maybe it should be solved in a more robust way. (This feels like a work-around.)

Itangalo’s picture

Issue summary: View changes

Updated the issue with a 'proper' issue summary – with guidelines from http://drupal.org/node/1155816.

kaztur’s picture

Such error. Unfortunately the patch didn't solved the trouble. Here is an export of view: http://kazan-doktor.ru/sites/default/files/my_view_with_flag_error.txt (sorry for russian in the file).

Matthew Davidson’s picture

I can't testify to the "Right"-ness of the solution, but the patch at #2 works for me.

citricguy’s picture

The patch in #2 works for me as well.

noslokire’s picture

#2 works for me

ohthehugemanatee’s picture

Priority: Normal » Critical

patch from #2 works for me, too.

Upping the priority to "critical", because breaking basic Views functionality is a pretty huge bug.

More than a month without anyone rewriting the patch... and it works for several people. I'd say it's a strong argument to have it committed to dev, even if only as a temporary solution.

dgastudio’s picture

works for me too.

nicholasyonko’s picture

Patch works for me as well.

mansspams’s picture

Status: Needs review » Reviewed & tested by the community
kaztur’s picture

Upd for #3:

Now #2 works for me too.

Sorry, seems to have mistook before adding the patch.

Great thanks, Itangalo!

Yusuf.Fidan’s picture

works for me too.

Funksmaname’s picture

I didn't even know this problem was related to flags - found it from this issue: http://drupal.org/node/1559512
However, I can confirm that #2 fixed the problem for me!

hoporr’s picture

Confirming: patch in #2 fixes the problem.

mansspams’s picture

After applying patch #2 I noticed there is still some trouble removing flag relationship with Remove button from relationship overlay/modal. Removal only possible via rearrange overlay/modal.

Not sure if I should post it here or open new issue and how does it influence RTBC status.

Ignigena’s picture

Experienced the same issue which caused Views to break completely and wouldn't allow creating contextual filters.

Patch #2 worked for me.

nagiek’s picture

Man, look at all the replies. Just goes to show how important Views is for all of us. :)

Any chance of a -dev release with this commit?

Babymaggie’s picture

Think this needs serious attention. Seems to be broke when I try to change any contextual filter on a bundled user relationships view as well.

So flag might not be the offender!

Hope this major bug is stamped out quick!

Babymaggie’s picture

Could someone please attach the file with the patch included for me as I am unsure how to apply patches.

This would be awesome - Thanks.

kaztur’s picture

For Babymaggie patched file from the curremt last Flag version (7.x-2.0-beta6, no 7.x-2.x-dev)

Babymaggie’s picture

Hi Kaztur, Awesome The patched file is working great! :)

Thanks a lot for the file and for the fast response.

Best wishes

Scott Ellis’s picture

Thank you. #2 / #20 worked for me too. Cheers.

mariusz.slonina’s picture

#2. Thank You, Thank You, Thank You

-enzo-’s picture

I had the same problem with a relation between feed and feed items, I have to uninstall flag module.

joshuautley’s picture

I can confirm that with Drupal 7.14 and Flag 2.0-beta6 the patch provided in #2 works! (=

Good job Itangalo!

jenlampton’s picture

patch in #2 works for me as well.

kitkat13’s picture

I can confirm that with Drupal 7.14 and Flag 2.0-beta6 the patch provided in #2 works for me too

quinns’s picture

Confirmed the patch in #2 works for us also.

jeff.maes’s picture

I confirm patch #2 works with Drupal 7.14 and Flag 2.0-beta6.

Seems to be worth releasing Flag 2.0-beta7 for this one since it blocks many views and there is no Flag 2.0-dev version available for downloading.

fraweg’s picture

Confirmed the patch in #2 an #20 works.

Thanks a lot!
Frank

quicksketch’s picture

Priority: Critical » Major
Status: Reviewed & tested by the community » Fixed

Thanks guys, committed #2 to the 2.x branches.

joshuautley’s picture

Hurray! (=

petednz’s picture

good work guys - so this is only going to be available via git for a while or is there another release imminent?

quicksketch’s picture

I'll hopefully make a new release shortly.

pipicom’s picture

#2 definitely works..

maerys’s picture

Works for me as well. Thanks!

zhuber’s picture

+1 for #2

Thanks @Itangalo

Alan D.’s picture

Just resolved this locally before finding this thread. My solution was slightly different. Setting #access = FALSE also bypasses the error:

  function options_form(&$form, &$form_state) {
    $options = $this->flags_options();
    $form[$this->_option_name('flag_name')] = array(
      ...
    );
    if (!$options) {
      $form[$this->_option_name('flag_name')]['#access'] = FALSE;
      $form[$this->_option_name('flag_name') . '_warning']['#markup'] = '<p class="warning">' . t('No %type flags exist. You must first <a href="@create-url">create a %type flag</a> before being able to use one.', array('%type' => $this->flag_type, '@create-url' => FLAG_ADMIN_PATH)) . '</p>';
    }

In saying that, I never saw the warning either of this sub-form component nor anything about Flags for that matter. So #2 looks like a better solution, unless this text is actually used somewhere...

caesar9171’s picture

My website is hosted by GoDaddy, and they don't give me full SSH access. I, therefore, cannot apply patches to anything on my drupal site. So far I have been able to avoid patching anything, but this Flag project issue with contextual filters in Views is preventing me from reaching the functionality level I would like.

So, does anybody have any suggestions about what I can do?
Maybe use kaztur's file in #20?
Or Alan D.'s solution in #38?

If it's one of these 2 solutions, could somebody please instruct me how to implement the solution?

I am pretty green when it comes to writing code.

Thanks for your time!

Alan D.’s picture

Use the code from #2 - This is what was committed!

In the file "flag/includes/flag_plugin_argument_validate_flaggability.inc" (probably in sites/all/modules) find this code:

  function options_form(&$form, &$form_state) {
    $options = $this->flags_options();

and replace with:

  function options_form(&$form, &$form_state) {
    // If there are no flag relationships set, skip this form of validation.
    $flags = flag_get_flags($this->flag_type);
    if (!$flags) {
      return array();
    }
    $options = $this->flags_options();

This adds all of those lines from the patch with the + to the file. If lines in the patch started with -, these would be deleted.

Good practice to backup a file from the server first, then FTP the modified one over the version that is on the server.

caesar9171’s picture

It seems to have worked! Thank you so much! I really appreciate it!

priapurnama’s picture

Patch #2 also works for me, would someone update this already :\

Simon Georges’s picture

@priapurnama, the fix has been committed and is available on 2.x-dev version of flag.

Yuri’s picture

#43: 2.x-dev version of flag?? Where can I find that? I see only old releases on their project page

Alan D.’s picture

http://drupal.org/node/887398 - DEV so use at your own risk.

ntigh52’s picture

I have the same problem,
Why if it major bug report, there is no new release.
I dont know how to apply patch.
can anyone help me please?
Nathan (quicksketch) please release new ver.. ( there is a reason why not? )
Thanks a lot.

dgastudio’s picture

ntigh52’s picture

Hi Alex ( kervi )
thanks a lot about the link, but why it is DEV and not a new release?!
When I choose to use dev It come with risk...
it is a major bug report.
Hope that will be new release s soon as possible.
Thanks

Itangalo’s picture

ntigh52: I think the reason is lack of time. Flag needs some more maintainers, to take care of the work that needs to be done. Most people maintaining Drupal projects do so on their spare time, and sometimes that time is just not enough.

ivars211’s picture

#2 worked for me. This should be included in flag description.

sw3b’s picture

#2 work for me too... thanks !

ntigh52’s picture

Thanks Johan Falk,
#2 is work but hopefully for new release...

oxrc’s picture

FileSize
709 bytes

Here's the patch for the current 2.x_beta06 version in case someone needs it.

franzkewd’s picture

Thanks ffingers. Just what I was looking for.

tripper54’s picture

Thanks Johan and ffingerz. #53 worked for me.

quicksketch’s picture

sozonov’s picture

#2 cool! thanks!

Status: Fixed » Closed (fixed)

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

sk8erboi’s picture

#2 Cool and Thumbs up! Worked for me!

royerd’s picture

Same system message as many others, but my fix was even easier--I replaced the "Filter identifier" text with something other than what was showing as default.

SharonD214@aol.com’s picture

Thanks! Works great!
Sharon

sajalsoni’s picture

#2 worked for me. Thanks.

sajalsoni’s picture

Issue summary: View changes

rafamd, updated to reflect Itangalo's solution