You are here

function pay_node_admin_node_form_alter in Pay 6

Same name and namespace in other branches
  1. 7 modules/pay_node/includes/pay_node.admin.inc \pay_node_admin_node_form_alter()

A form_alter helper for node creation forms.

1 call to pay_node_admin_node_form_alter()
pay_node_form_alter in modules/pay_node/pay_node.module
Implementation of hook_form_alter().

File

modules/pay_node/includes/pay_node.admin.inc, line 253
Menu callbacks to administrative screens for node payments.

Code

function pay_node_admin_node_form_alter(&$form, &$form_state) {

  // Settings variable suffix.
  $node = $form['#node'];
  $suffix = '_' . $form['#node']->type;

  // Don't continue if pay_node settings aren't enabled for this node type.
  if (!variable_get('pay_node_enabled' . $suffix, FALSE)) {
    return;
  }

  // Determine the payment model and verify that it's currently valid.
  $model = variable_get('pay_node_model' . $suffix, NULL);
  if (!in_array($model, variable_get('pay_node_models', array()))) {
    return;
  }

  // Add payment form settings on the node form to control how it's displayed.
  if ($model == 'view') {
    $visible = variable_get('pay_node_view_override' . $suffix, FALSE);
    $required = variable_get('pay_node_view_required' . $suffix, FALSE);

    // The default settings are overrideable, so present some settings.
    if ($visible) {
      switch (variable_get('pay_node_method' . $suffix, '')) {

        // Create a new payment form for each node using default values.
        case 'create':
          if (!($pay_form = pay_node_form_load($node))) {
            $pay_form = pay_form_load(variable_get('pay_node_form' . $suffix, ''));
          }
          if ($pay_form) {
            $group = $pay_form
              ->handler();
            $pay_form
              ->settings_form($form, $form_state);

            // Do not allow menu_path to be specified.
            $form[$group][$group]['menu_path'] = array(
              '#type' => 'value',
              '#value' => '',
            );

            // Add an after_build handler to map the pay_form to its node.
            $form['#after_build'][] = 'pay_node_admin_node_form_after_build';
          }
          break;

        // Link to an existing form.
        case 'select':
          $group = 'pay_node';

          // List of available forms.
          $options = array(
            '' => ' - None -',
          );
          foreach (pay_forms(NULL, TRUE) as $pay_form) {
            $options[$pay_form->pfid] = $pay_form
              ->title();
          }
          $pay_form_default = pay_node_form_load($node);

          // Add a selection of available payment forms to link to this node.
          $form[$group]['pay_node'] = array(
            '#type' => 'select',
            '#title' => t('Payment form'),
            '#options' => $options,
            '#required' => $required,
            '#default_value' => $pay_form_default->pfid,
          );
          break;
      }

      // Add a fieldset to differentiate this settings form.
      if (isset($group) && $form[$group]) {
        $form[$group]['#type'] = 'fieldset';
        $form[$group]['#collapsible'] = TRUE;
        $form[$group]['#title'] = t('Payment settings');
      }
    }
    else {
      switch (variable_get('pay_node_method' . $suffix, '')) {
        case 'create':
          break;

        // Store the default selected form for this node type.
        case 'select':
          $pay_form_default = pay_node_form_load($node);
          $form['pay_node'] = array(
            '#type' => 'value',
            '#value' => $pay_form_default->pfid,
          );
          break;
      }
    }
  }

  /*
  if ($pay_form = pay_node_form_load($form['#node'])) {
    $model = variable_get('pay_node_model_'. $form['#node']->type, NULL);
    $active_models = variable_get('pay_node_models', array());
    if ($active_models[$model]) {
      if ($model == 'form') {
        $pay_form->form($form, $form_state);
      }

      // Embed payment form settings into the node editing form.
      if ($model == 'view') {
        $pay_form->settings_form($form, $form_state);

        // Add an after_build handler to map the pay_form to its node.
        $form['#after_build'][] = 'pay_node_admin_node_form_after_build';

        // Add a fieldset to differentiate the settings form.
        $group = $pay_form->handler();
        if (isset($form[$group])) {
          $form[$group]['#type'] = 'fieldset';
          $form[$group]['#collapsible'] = TRUE;
          $form[$group]['#title'] = t('Payment settings');
        }
      }
    }
  }
  */
}