从Rules元素返回drupal_get_form

时间:2012-09-10 20:46:22

标签: drupal

我正在尝试创建一个模块,该模块在逻辑位置创建commerc_paypal_wps表单的简单副本,因此用户无需查看规则表单或元素。

我无法拉入表单值然后保存它们。

我的代码是:

<?php

//Create the admin page
function sb_paypal_settings_menu() {

$items['admin/commerce/config/paypal'] = array(
  'title' => 'Paypal settings',
  //'description' => 'Set values for your site such as site name.',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('site_settings_admin_1'),
  'access arguments' => array('administer paypal settings'),
  'file path' => drupal_get_path('module', 'rules_admin'),
  'file' => 'rules_admin.inc',
  'type' => MENU_NORMAL_ITEM,
);
return $items;

}

//Valid permissions for this module
function sb_paypal_settings_permission() {
return array(
'administer paypal settings' => array(
  'title' => t('Administer Paypal settings')      
),
);
}

//Create the form
function site_settings_admin_1() {

$form = drupal_get_form('commerce_paypal_wps_settings_form');


unset($form['ipn_logging']);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);

return($form);

}

模块的代码位于:http://drupalcontrib.org/api/drupal/contributions!commerce_paypal!modules!wps!commerce_paypal_wps.module/function/commerce_paypal_wps_settings_form/7

表单所需的信息存储在rules_config表中。

1 个答案:

答案 0 :(得分:0)

解决方案是创建一个模块来改变w值。 .module文件的代码如下:

<?php
// $Id$

//Create the admin page
function paypal_settings_menu() {
$items['admin/commerce/config/paypal_settings'] = array(
  'title' => 'Paypal payment settings',
  'description' => 'Add your paypal email address',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('paypal_settings_admin'),
  'access arguments' => array('administer paypal payment settings'),
  'file path' => drupal_get_path('module', 'rules_admin'),
  'file' => 'rules_admin.inc',
  'type' => MENU_NORMAL_ITEM,
);
return $items;
}

//Valid permissions for this module
function paypal_settings_permission() {
return array(
'administer paypal payment settings' => array(
  'title' => t('Administer Paypal payment settings')      
),
);
}

//Create the form
function paypal_settings_admin() {

$query = db_query("SELECT * FROM rules_config WHERE name='commerce_payment_paypal_wps'")->fetchAll();
if (count($query) == 1) {
$settings = unserialize($query[0]->data);
}


$pay_settings;

$actions = $settings->actions();

foreach ( $actions as $action ) {
$pay_settings = &$action->settings['payment_method']['settings'];
break;
} 

$saveval = serialize($settings);

$form['business_email'] = array(
'#type' => 'textfield',
'#title' => t('PayPal e-mail address'),
'#description' => t('The e-mail address you use for the PayPal account you want to receive payments.'),
'#default_value' => $pay_settings['business'],
'#required' => TRUE,
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);  
$form['#submit'][] = 'paypal_settings_form_submit';
return $form;

}

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

$query = db_query("SELECT * FROM rules_config WHERE name='commerce_payment_paypal_wps'")->fetchAll();

if (count($query) == 1) {
$settings = unserialize($query[0]->data);
}

$pay_settings = null;

$actions = $settings->actions();

foreach ( $actions as $action ) {
$pay_settings = &$action->settings['payment_method']['settings'];
break;
}

$pay_settings['business'] = $form_state['values']['business_email'];  

$insertquery = db_update('rules_config')
->fields(array(
'data' => serialize($settings),
))
->condition('name', 'commerce_payment_paypal_wps')
->execute();

}