我编写了代码,其核心模块名为user,角色函数。 我的" user_admin_types"就像" user_admin_roles"。如果你简要看一下" user.admin.inc"文件你会明白我已经在这些基础上替换了我的函数和变量:
" user_roles" =" user_types"
"作用" ="输入"
"去掉" =" ut_id"
"名称" =" ut_label"
我所做的一切都与Core已经完成的相同,但我在页面中发出了此警告:Warning: Illegal offset type in isset or empty in element_info
。
我已检查过每一行,但我无法找到原因和方法,我可以将其消失。
`function user_admin_types($form, $form_state) {
$types = user_types();
$form['types'] = array(
'#tree' => TRUE,
);
$order = 0;
foreach ($types as $ut_id => $ut_label) {
$form['types'][$ut_id]['#type'] = (object) array(
'ut_id' => $ut_id,
'ut_label' => $ut_label,
'ut_weight' => $order,
);
$form['types'][$ut_id]['#weight'] = $order;
$form['types'][$ut_id]['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight for @title', array('@title' => $ut_label)),
'#title_display' => 'invisible',
'#size' => 4,
'#default_value' => $order,
'#attributes' => array('class' => array('type-weight')),
);
$order++;
}
$form['ut_label'] = array(
'#type' => 'textfield',
'#title' => t('User Type'),
'#title_display' => 'invisible',
'#size' => 32,
'#maxlength' => 64,
);
$form['add'] = array(
'#type' => 'submit',
'#value' => t('Add type'),
'#validate' => array('user_admin_type_validate'),
'#submit' => array('user_admin_type_submit'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save order'),
'#submit' => array('user_admin_types_order_submit'),
);
return $form;
}
/**
* Form submit function. Update the type weights.
*/
function user_admin_types_order_submit($form, &$form_state) {
foreach ($form_state['values']['types'] as $ut_id => $type_values) {
$type = $form['types'][$ut_id]['#type'];
$type->ut_weight = $type_values['weight'];
user_type_save($type);
}
drupal_set_message(t('The type order have been updated.'));
}
function user_types() {
$query = db_select('users_types', 'ut');
$query->addTag('translatable');
$query->fields('ut', array('ut_id', 'ut_label'));
$query->orderBy('ut_weight');
$query->orderBy('ut_label');
$result = $query->execute();
$types = array();
foreach ($result as $key => $type) {
switch ($type->ut_id) {
// We only translate the built in type names
case WEBNOVIN_CUSTOMER_UT_ID:
$types[$type->ut_id] = t($type->ut_label);
break;
case WEBNOVIN_PREFERRED_CUSTOMER_UT_ID:
$types[$type->ut_id] = t($type->ut_label);
break;
case WEBNOVIN_SALES_AGENT_UT_ID:
$types[$type->ut_id] = t($type->ut_label);
break;
default:
$types[$type->ut_id] = $type->ut_label;
}
}
return $types;
}`