phpformsdrupaldatatabledrupal-fapi

How to include drupal form elements in a data table


I have a data table which is populated with data unrelated to drupal content (from a third party system). The data relates to photos which must be approved / flagged as inappropriate.

So I'm writing a Drupal admin module which should moderate this content. So far, I have built a table using theme('table',...) which shows 1 photo per row, along with some other meta data. I now want to include some form buttons in the table and build some Ajax actions which are triggered by those buttons.

This article looks relevant http://drupal.org/node/112358 but I'm concerned this isn't the Drupal 6 way of doing things.

Can anyone offer some advice on how best to approach this problem - preferably using core modules / form override functions. Drupal version is 6.14.


Solution

  • Custom theme functions allow you to render content in a completely custom way. You can also create a custom template for your content, this could include the buttons.

    hook_theme() will allow you to create your own content type to add to the theme function so you could have theme('moderatedimages').

    A workaround would be to put the HTML for the moderate buttons into the table data so that it is output by theme table. This would save you having to write your own theme function.

    For the AJAX calls you will need to build your own menu callback using hook_menu() and a custom function. (Code snippets are from this tutorial.)

    <?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;
    }
    

    This will call the function mymodule_myfunction(). One thing to remember about this function is that you want to print the result and exit. You may want to use drupal_json() to encode the response.