Drupal发送错误的参数来提交函数

时间:2016-04-19 12:32:24

标签: php drupal drupal-7

我有表中的用户(实体)列表,由视图(模块视图)生成。我需要添加一个带有该用户删除链接的字段。

实体表:

function conference_register_schema(){
    $schema = array();

    $schema['conference_register_list'] = array(
        'description' => 'Список людей, що зареєструвались на конференцію.',
        'fields' => array(
            'id' => array(
                'type' => 'serial',
                'unsigned' => TRUE,
                'description' => 'ID of registered person',
                'not null' => TRUE,
            ),
            'name_surname' => array(
                'type' => 'varchar',
                'length' => '100',
                'description' => 'User name and surname',
                'not null' => TRUE,
            ),
            'email' => array(
                'type' => 'varchar',
                'length' => 100,
                'description' => 'User email',
                'not null' => TRUE,
            ),
            'phone_number' => array(
                'type' => 'varchar',
                'length' => 20,
                'description' => 'User phone number',
                'not null' => TRUE,
            ),
        ),
        'primary key' => array('id'),
    );

    return $schema;
}

查看API以创建新字段:

function delete_link_views_data() {
    global $user;
    if ($user->uid == 1) {
        $data['delete_link']['table']['group'] = t('My custom module');
        $data['delete_link']['table']['join'] = array(
            // Exist in all views.
            '#global' => array(),
        );

        $data['delete_link']['delete_link'] = array(
            'title' => t('Delete from list'),
            'help' => t('Only admin can delete.'),
            'field' => array(
                'handler' => 'delete_link_handler',
            ),
        );

        return $data;
    }
}

我的handler.inc:

class delete_link_handler extends views_handler_field {
  function query() {
  }
  function option_definition() {
    $options = parent::option_definition();
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
  }
  function render($fields) {
    $user_id_to_delete = $fields->id;
    return drupal_get_form('delete_user_from_list_form', $user_id_to_delete);
  }
}


function delete_user_from_list_form($form, $form_state, $user_id_to_delete){
    $form = array();

    $form['register_user_id'] = array(
        '#type' => 'value',
        '#value' => $user_id_to_delete,
    );

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

    return $form;
}

function delete_user_from_list_form_submit($form, &$form_state){
    $user_id_to_delete = trim($form_state['values']['register_user_id']);
    dpm(print_r($user_id_to_delete)); // here is a problem

    global $user;
    if ($user->uid == 1) {
        // entity_delete('conference_register', $user_id_to_delete);
    }
}

当我点击任何删除按钮时,它会删除列表中的第一个元素。当我打印用户ID:'dpm(print_r($ user_id_to_delete))'它每次打印1

该怎么做???

0 个答案:

没有答案