创建一个页面以编辑自定义内容类型中的所有字段(D7)

时间:2011-11-29 17:21:27

标签: drupal drupal-7 cck

我有一个自定义内容类型,其中包含一个名为[stock]

的自定义字段

我想有一个页面显示列表中的所有节点[stock]值,并允许我更改值。这可能吗?

非常感谢任何建议

2 个答案:

答案 0 :(得分:3)

好吧,我打算给这个写一个模块,但像往常一样,Drupal有人打败了我!

您应该下载并安装Views,以及(非常坦率的)Slick Grid module。它提供了一个视图类型(Slick Grid),它将创建一个内容表,并为字段启用内联编辑。对于更复杂的字段类型,它提供了一个用于编辑的模态弹出窗口。

使用以下输出创建视图花了我10分钟,这让我可以通过双击单元格直接在表格中编辑字段:

Views Output

当您再次单击编辑单元格时,内容会自动保存到数据库中,并且所有内容都通过AJAX处理,这使得使用起来非常愉快。

您可以在网格中添加任意数量的字段,因此我认为这正是您所追求的:)

答案 1 :(得分:1)

是的,我做了类似的事情才能让它发挥作用。在您的情况下,您将不得不修改SQL查询以获取自定义字段。您还需要修改$headers$rows数组以包含您需要显示的内容,但我认为您明白这一点。

 // first I create my own module hooking the menu
 function custom_menu() {
    $items['admin/custom-content'] = array(
        'title' => t('Custom Content'),
        'type' => MENU_NORMAL_ITEM,     
        'access arguments' => array('access content'), 
    );
    $items['admin/custom-content/product'] = array(
        'title' => t('Products'),
        'type' => MENU_NORMAL_ITEM,
        'access arguments' => array('access content'),
        'page callback' => 'custom_view_products'
    );
            return $items;
  }
  // the above will add a new admin menu link called Custom Content
  // then I have a callback method for the menu item
  function custom_view_products() {
         // setup the header for the form
         $headers = array(
        array('data' => 'Title', 'field' => 'title', 'sort' => 'asc'),
        array('data' => 'Published')
     );
         //
         $query = "SELECT n.* FROM {node} n ". 
                  "WHERE n.type = 'product' ORDER BY n.title ASC";

     //
     $rows = array(); 
     if(($results = db_query($query)->fetchAll())) {
        foreach ($results as $node) {
            $rows[] = array(
                'data' => array(
                l($node->title, 'node/'. $node->nid .'/edit'),
                $node->status
                ), 'class' => array('published')
            );
        }
         }
     $html = theme('table',
        array(
            'header' => $headers,
            'rows'=>$rows,
            'caption' => '',
            'sticky' => FALSE,
            'empty' => 'No products located...',
        )
    );
    return $html;
}
相关问题