【发布时间】:2017-02-05 18:03:11
【问题描述】:
我使用模块为视图创建了一个自定义字段。为了在此处更好地进行可视化,我对其进行了简化:自定义字段仅生成一个介于 1 和 10 之间的随机数。
我想对这个随机数进行“排序”。但是,在视图中使用此设置时,我收到以下错误:
SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列 'my_custom_field'
我很难在我的代码中找到错误。
感谢您在我的模块代码中提供的任何帮助!!
这是我的文件:
my_custom_module.info
name = My Custom Module
description = Implement random number in views.
core = 7.x
files[] = includes/views_handler_my_custom_field.inc
my_custom_module.module
<?php
/**
* Implements hook_views_api().
*/
function my_custom_module_views_api() {
return array(
'api' => 3,
);
}
my_custom_module.views.inc
<?php
/**
* Implements hook_views_data().
*/
function my_custom_module_views_data() {
$data['my_custom_module']['table']['group'] = t('My custom module');
$data['my_custom_module']['table']['join'] = array(
// Exist in all views.
'#global' => array(),
);
$data['my_custom_module']['my_custom_field'] = array(
'title' => t('My custom field'),
'help' => t('My custom field displays a random number.'),
'field' => array(
'handler' => 'views_handler_my_custom_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
return $data;
}
views_handler_my_custom_field.inc
<?php
/**
* @file
* Custom views handler definition.
*/
/**
* Custom handler class.
*
* @ingroup views_field_handlers
*/
class views_handler_my_custom_field extends views_handler_field {
/**
* {@inheritdoc}
*
* Perform any database or cache data retrieval here. In this example there is
* none.
*/
function query() {
}
/**
* {@inheritdoc}
*
* Modify any end user views settings here. Debug $options to view the field
* settings you can change.
*/
function option_definition() {
$options = parent::option_definition();
return $options;
}
/**
* {@inheritdoc}
*
* Make changes to the field settings form seen by the end user when adding
* your field.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
}
/**
* Render the random field.
*/
public function render($values) {
$random = rand(1, 10);
return $random;
}
}
【问题讨论】:
标签: drupal drupal-7 drupal-views