Pass node object to signup_user_form theming function (for context). Would you consider applying this path so custom theming functions will know for what node they are creating a signup form?

CommentFileSizeAuthor
signup.module.patch472 bytesAnonymous (not verified)

Comments

Anonymous’s picture

Status: Active » Needs review
dww’s picture

Status: Needs review » Needs work

Perhaps, but only if you also fixed theme_signup_user_form() in signup.theme to add the argument and a properly formatted PHPDoc comment. ;)

dww’s picture

Version: 5.x-2.5 » 5.x-2.x-dev
Assigned: Unassigned » dww
Status: Needs work » Fixed

Fixed theme_signup_user_form(), ported to HEAD (needed to modify the record for 'signup_user_form' in hook_theme()), tested, and committed to both HEAD and DRUPAL-5--2. Thanks.

dww’s picture

Title: Pass node object to theming function » Pass node object to signup_user_form theming function
scottrigby’s picture

Hi dww, I have two questions:

1. I followed from here #29568: Flexible number and type of fields where the proposed patch allowed form fields that could be specified per-node, or per-node-property (like taxonomy term), in theme_signup_user_form($node). There you said you committed a basically identical change - so I'm wondering if the per-node-property fields (such as checkbox and radio widgets) are now possible in the current commit to HEAD?

2. Second Q (please let me know if this shoudl be a separate issue)... is there a way to take advantage of other CCK fields in the Signup form using a similar method? For example, the Phone field in theme_signup_user_form($node) is a textfield:

  $form['signup_form_data']['Phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone'),
    '#size' => 40, '#maxlength' => 64,
  );

Could this for instance be a phonefield instead (taking advantage of that module's validation, etc) -- or other specific cck field modules? If so, do you have any recommendations on how to go about adding them?

scottrigby’s picture

Version: 5.x-2.x-dev » 6.x-1.x-dev

@dww: One further thought about Q2 above...

Is there any possibility of drawing specific CCK fields from the node-type itself? For instance, could there be a way to specify a particular fieldset in the node form to hold all the cck fields we want to include in the Signup form? These fields could then be hidden on the node-form using content permissions or something, and selected on a per-node basis using cck option widgets? This would allow node-type & node-specific fields to on the Signup form, and take advantage of things like not only phone validation, but location fields, etc.

dww’s picture

@scottrigby: The answer to most of what you're talking about is: "No. Read http://groups.drupal.org/node/3430 -- none of that is implemented yet".

All I committed is a change that passes the $node object into theme_signup_user_form() for context. You could mostly do this yourself already by checking arg(), but it's cleaner this way. What I committed allows you to do stuff like this in your template.php file:

function phptemplate_signup_user_form($node) {
  // --------------------
  // The usual stuff...
  // --------------------
  global $user;
  $form = array();

  // If this function is providing any extra fields at all, the following       
  // line is required for form form to work -- DO NOT EDIT OR REMOVE.           
  $form['signup_form_data']['#tree'] = TRUE;

  $form['signup_form_data']['Name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 40, '#maxlength' => 64,
    '#required' => TRUE,
  );
  $form['signup_form_data']['Phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone'),
    '#size' => 40, '#maxlength' => 64,
  );

  // If the user is logged in, fill in their name by default.                   
  if ($user->uid) {
    $form['signup_form_data']['Name']['#default_value'] = $user->name;
  }

  // ----------------------
  // Per-node type stuff
  // ----------------------
  switch ($node->type) {
    case 'event':
      $form['signup_form_data']['Event notes'] = array(
        '#type' => 'textarea',
        '#title' => t('Event notes'),
      );
      break;

    case 'rehearsal':
      $form['signup_form_data']['Instruments'] = array(
        '#title' => t('Instruments'),
        '#type' => 'textfield',
        '#description' => t('What instruments are you bringing to the rehearsal?'),
      );
      break;
  }

  // -------------------------
  // Per-node stuff (hack!)
  // -------------------------
  switch ($node->nid) {
    case '11':
      $form['signup_form_data']['Want to buy a CD'] = array(
        '#type' => 'checkbox',
        '#title' => t('I want to buy a CD at the release party'),
        '#description' => t("If you're coming to %title, you can specify here if we should have a CD for you to buy at the door.", array('%title' => $node->title)),
      );
      break;
  }

  return $form;
}

Status: Fixed » Closed (fixed)

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