I have been trying to create a Flag using a YAML file with information taken from the Patterns Form Helper & Drupal for Firebug. I've tried everything I could think of, but I'm at a loss.

Any help will be greatly appreciated.

info:
  title: Flag module setup (YAML)
  description: Setup options for Flag module
  author: Christopher Gervais
  author_email: ergonlogic@gmail.com
  category: Module Configuration

modules: 
  - flag
  - flag_actions

actions:
  - tag: form
      form_id: flag_form
      name: test_flag1
      title: Test Title
      flag_short: Flag Text
      unflag_short: Unflag Text
      types:
        0: page
      args:
        - add/node/test_flag1

The error occurs when the progress bar flashes "Initializing", but doesn't look like a normal Patterns error. Rather than reporting the error on the Patterns page, with some helpful notes, it results in an error on the Processing page, and dumps the HTML of the flag form:

Processing pattern Flag module setup (YAML)

An error has occurred.
Please continue to the error page

An error occurred. /batch?id=46&op=do <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">  <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />  <link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/admin_menu/admin_menu.css?r" /> <link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?r" /> <link type="text/css" rel="stylesheet"....

Comments

ergonlogic’s picture

Also, when I click the "error page" link, I am returned to the Patterns page, where the usual "Pattern ran successfully" message appears, and the status shows as "Enabled".

Which seems odd.

vaish’s picture

Title: Trying to use form tag in yaml file for flag.module » Flag module and Patterns compatibility
Project: Patterns » Flag
Version: 6.x-1.x-dev » 6.x-1.2
Component: Code » Flag core

Flag module is not compatible with the way how patterns work because it's using drupal_goto() instead of $form['redirect] in flag_add_form_submit(). That's causing HTML dump you've described in your issue above. I'm putting this issue under flag project in case module's author is interested to update the submit function.

Besides that, your pattern needs some adjustments as well. This is how the pattern action should look finally:

  - tag: form
      form_id: flag_add_form
      include:
        module: flag
        file: includes/flag.admin.inc
      name: test_flag
      type: node
  - tag: form
      form_id: flag_form
      include:
        module: flag
        file: includes/flag.admin.inc
      name: test_flag
      title: Test Title
      flag_short: Flag Text
      unflag_short: Unflag Text
      types:
        0: page
      args:
        name: test_flag
        type: node
quicksketch’s picture

Title: Flag module and Patterns compatibility » Flag module and Patterns compatibility (remove drupal_goto())
Category: support » bug
Priority: Normal » Minor

Weird, I wouldn't think we'd be using drupal_goto() in a submit handler. If we are, I think it qualifies as a bug.

ergonlogic’s picture

So this should use form_state['redirect'] then, as per http://drupal.org/node/310513 and http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6, correct?

quicksketch’s picture

Yes that's right.

ergonlogic’s picture

Status: Active » Needs review
StatusFileSize
new753 bytes
new764 bytes

So, that seems simple enough:

function flag_add_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'admin/build/flags/add/'. $form_state['values']['type'] .'/'. $form_state['values']['name'];
}

I've attached patches against the CVS versions of the two 6.x branches.

It appears to work just fine, though I haven't yet tested it in the use case that initiated this thread, i.e. creating flags with Patterns.

ergonlogic’s picture

I have now tested the 6--2 patch with the Patterns module, as per the original use case, with pattern actions defined as per #2. It worked without a hitch. Assuming the patches pass muster, I'd say this bug report can be closed.

@Vaish: Thanks for the help with the pattern. I must have tried 20 variations on passing arguments without success. Of course, in retrospect, even had I hit on the proper format, with the bug in flag.module, I never would have known...

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, I'll add it in next time I'm working on Flag.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Committed ergonlogic's #6 to both branches. Thanks!

Status: Fixed » Closed (fixed)

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