2

我有一个数据表,其中填充了与 drupal 内容无关的数据(来自第三方系统)。这些数据与必须被批准/标记为不合适的照片有关。

所以我正在编写一个 Drupal 管理模块,它应该管理这些内容。到目前为止,我已经使用 theme('table',...) 构建了一个表格,每行显示 1 张照片,以及一些其他元数据。我现在想在表格中包含一些表单按钮并构建一些由这些按钮触发的 Ajax 操作。

这篇文章看起来很相关http://drupal.org/node/112358但我担心这不是 Drupal 6 的做事方式。

任何人都可以就如何最好地解决这个问题提供一些建议 - 最好使用核心模块/表单覆盖功能。Drupal 版本是 6.14。

4

3 回答 3

2

自定义主题功能允许您以完全自定义的方式呈现内容。您还可以为您的内容创建自定义模板,这可能包括按钮。

hook_theme()将允许您创建自己的内容类型以添加​​到主题功能中,这样您就可以拥有theme('moderatedimages').

一种解决方法是将中等按钮的 HTML 放入表数据中,以便由主题表输出。这将使您不必编写自己的主题功能。

对于 AJAX 调用,您需要使用hook_menu()自定义函数构建自己的菜单回调。(代码片段来自教程。)

<?php
function mymodule_products_menu() {

  $items = array();

  $items['products/get'] = array(
    'title' => 'mymodule callback',
    'page callback' => 'mymodule_myfunction',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );

  return $items;
}

这将调用函数mymodule_myfunction()。关于此函数要记住的一件事是您要打印结果并退出。您可能希望使用drupal_json()对响应进行编码。

于 2009-11-23T06:36:10.953 回答
1

你为什么使用标准的 theme_table() 函数?只需制作您自己的主题功能,其中包括您需要的表单元素。更多关于主题功能的信息在这里这里

于 2009-11-20T15:58:45.213 回答
1

我有同样的问题。我在 drupal-directory/modules/menu/menu.admin.inc 中找到了解决方案。仅使用 Form-API 和主题!

实现: - 使用 scheme-api 编写查询(我认为你已经为你的主题('table',...) ) - 为每一行创建一个这样的表单: $form[$row->id][ 'column_name_1'] = array(...here description of the column -> checkbox, textfield...); $form[$row->id]['column_name_2'] = array(...); - 编写您自己的主题功能,使用 hook_theme_table(您已经这样做了,您只需将一些单元格更改为复选框或其他表单元素。)

我现在写了一个提交函数,但它不起作用:-) 有关更多信息,请参阅菜单模块。

继承我的代码:

/**   
  * Form for editing the event types.
  *  
  * @ingroup forms  
  */
  function mymodule_event_type_overview_form() {  
    $vid = variable_get('mymodule_category_vocabulary', '');
    $sql = "SELECT term_data.tid AS tid,
      term_data.name AS tname,
      term_data.vid AS vid,
      term_site_config.color AS color,
      term_site_config.site_enabled AS site_enabled,
      term_site_config.site_shown AS site_shown
      FROM {term_data} term_data
      INNER JOIN {term_site_config} term_site_config 
      ON term_data.tid = term_site_config.tid
      WHERE term_data.vid = %d";

    $result = db_query(db_rewrite_sql($sql), $vid);

  $form = array();   while ($term = db_fetch_object($result)) {
    $form[$term->tid]['tname'] = array(
      '#type' => 'value',
      '#value' => $term->tname,
    );
    $form[$term->tid]['color'] = array(
      '#type' => 'value',
      '#value' => $term->color,
    );
    $form[$term->tid]['enabled'] = array(
      '#type' => 'checkbox',
      '#default_value' => $term->site_enabled,
    );
    $form[$term->tid]['shown'] = array(
      '#type' => 'checkbox',
      '#default_value' => $term->site_shown,
    );

    // Build a list of operations.
    $operations = array();
    $operations['delete'] = l(t('delete'), 'admin/settings/mymodule/eventtype/'. $term->tid .'/delete');
    $operations['edit'] = l(t('edit'), 'admin/settings/mymodule/eventtype/'. $term->tid .'/edit');

    $form[$term->tid]['operations'] = array();
    foreach ($operations as $op => $value) {
      $form[$term->tid]['operations'][$op] = array('#value' => $value);
    }   }
     if (element_children($form)) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
    );
    if (!empty($_POST) && form_get_errors()) {
      drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
    }   }else {
    $form['empty'] = array('#value' => t('There are no event types yet.'));   }
     return $form; }

/**  
  * Theme the event type overview form into a table.  
  *
  * @ingroup themeable  
  */
function theme_mymodule_event_type_overview_form($form) {

  $header = array(
    t('Event type'),
    t('Color'),
    array('data' => t('Enabled'), 'class' => 'checkbox'),
    array('data' => t('Shown'), 'class' => 'checkbox'),
    array('data' => t('Operations'), 'colspan' => '2'),   );

  $rows = array();   foreach (element_children($form) as $id) {
    $element = &$form[$id];
    if (isset($element['tname'])) {
      $row = array(
        t($element['tname']['#value']),
        t($element['color']['#value']),
        array('data' => drupal_render($element['enabled']), 'class' => 'checkbox'),
        array('data' => drupal_render($element['shown']), 'class' => 'checkbox'),
        array('data' => drupal_render($element['operations']['delete'])),
        array('data' => drupal_render($element['operations']['edit'])),
      );

    $rows[] = $row;   }   }   $output = '';   if ($rows) {
    $output .= theme('table', $header, $rows);   }   
    $output .= drupal_render($form);   
    return $output; 

}

You will get the html-code of the form if you call drupal_get_form('mymodule_event_type_overview_form');

and don't forget co write following function in mymodule.module:

/** * hook_theme() 的实现。*/ function mymodule_theme() {
return array( 'mymodule_event_type_overview_form' => array( 'arguments' => array(), ), ); }

玩得开心:-) 卡佳

于 2010-06-10T15:34:37.720 回答