Cybercampbell
Cybercampbell

Reputation: 2606

Create a page to edit all fields from a custom content type (D7)

I have a custom content type that has a custom field called [stock]

I would like to have a single page that shows me ALL nodes [stock] values in a list and allows me to change the value. Is this possible?

Any advice would be much appreciated

Upvotes: 3

Views: 1481

Answers (2)

Clive
Clive

Reputation: 36956

Well I was going to write a module to this but as usual with Drupal someone beat me to it!

You should download and install Views, and also the (quite frankly excellent) Slick Grid module. It provides a view type (Slick Grid) that will create a table of content, with inline editing enabled for fields. For more complex field types it provides a modal popup for editing instead.

It took me 10 minutes to create a view with the following output, which lets me edit fields directly in the table by double clicking on the cell:

Views Output

The content is saved automatically to the database when you click off the edit cell again, and it's all handled via AJAX which makes it very pleasant to use.

You can add as many fields as you like to the grid so I think this is exactly what you're after :)

Upvotes: 3

Cyclonecode
Cyclonecode

Reputation: 30001

Yes it is I have done something like this to get it working. In your case you would have to modify the sql query to fetch your custom field. You also would need to modify the $headers and the $rows array(s) to include what you need to display, but I think you get the idea.

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

Upvotes: 1

Related Questions