Editview

Editview is a plugin for the Views module. It allows you to create a view in which the nodes are editable, and new nodes can be created. Editview uses AJAX to speed things up, but will still work on browsers with javascript disabled.

Update - 25th November 2008

A new 5.x development release!! This release has had a significant change to the way in which field ID's a generated for each of the forms down an editview page. This should mean that javascript will work much better than before, at least initially. The way in which javascript actions work however means than when you click update on a node you'll get a form back with only the javascript functions enabled that this module reattaches to the new HTML. So if you need some more javascript reattached, just place it in the issue queue.

This release needs your help for testing so we can make it a full release.

Installation

  1. Ensure that the Views module is installed and enabled.
  2. If installing on Drupal 5, install this patch to provide form validation. Skip this step if installing on Drupal 6.
  3. Download and unpack the latest Editview tarball in your drupal modules directory.
  4. Enable the Editview module on your drupal admin/modules page.

Usage

Editviews are created just like any other type of view, with a few caveats.

Select the View Type

Normal views allow you to choose whether they are one of:

  • Full Nodes
  • Teaser List
  • Table View
  • List View
  • Editview - table
  • Editview - compressed

If you select any of these options then your view is an Editview.

Caveat 1

Editview assumes that your view is filtered to display only one node type. This is so that the Editview knows what type to make any nodes it adds.

Caveat 2

You should include any 'required' fields in the view, otherwise adding new nodes will be impossible, since any nodes you try to add will fail their validation.

Caveat 3

You should provide a Sort Criteria of 'Created time' -> 'descending' so that when adding new nodes, they appear where users expect them to appear.

Cookbook

Make a view that allows you to edit and create pages on your site

This Editview will show an editable table of page nodes. You can edit their title and body fields, save your changes, delete pages (with confirmation), and create new pages which are then added to the view.

Steps:

  1. Create a new view, giving it a name and limiting access to roles who are able to create and edit pages.
  2. Check the 'Provide Page View' box, and give your view an easy-to-remember url.
  3. In 'View Type', select 'Edit View'.
  4. In the 'Fields' section, add 'Node: Title', and 'Node: Body'
  5. In the 'Filters' section, add a 'Node: Type' filter, and select 'page' as the value.
  6. In the 'Sort Criteria' section, add a 'Node: Created Time' field, and select 'Descending' as the order.
  7. Save the view and visit its url.

View, edit, and add 'child' nodes on a 'parent' node page

This view uses cck, views, and editview to add the ability to see and edit a table of 'child' nodes on a 'parent' node page. We'll relate children to parents using a cck node reference field to the child node type.

Steps:

  1. Create the parent and child node types. In this example we'll make 'organisation' the parent type, and 'employee' the child type.
    1. Create 'organisation' as a cck node type, giving it whatever fields you like.
    2. Create 'employee' as a cck node type. One of its fields should be a node reference which you should limit to only be able to access nodes of type 'organisation'. Make sure the node reference is a select list, not an auto-complete text field. We'll be relying on not having to enter the reference manually.
    3. At this point you may want to create a few test organisations and assign each one a few employees.
  2. Make a new table view listing employees, that will appear on the organisation view page:
    1. Create the view as a block of type 'Table View'.
    2. The view's fields should be the employee type's fields, without the organisation node reference.
    3. Add the organisation node reference as an argument. Put the following as the argument code:
      if (arg(0) == 'node' && is_numeric(arg(1))) {
          $organisation = node_load(arg(1));
          if ($organisation->nid) {
              return array($organisation->nid);
          }
      }
         

      This will make sure the view only shows employees of the current organisation being viewed.
    4. Save the view, and enable it as a block on the admin/block page.
    5. Configure the block, putting the following code in the 'Page specific visibility settings':
      <?php
      if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
         
      $node = node_load(arg(1));
          if (
      $node->type == 'content_organisation') {
              return
      true;
          }
      }
      return
      false;
      ?>

      This will make sure that the view is only displayed on the view tab of organisation nodes.
  3. Create our edit view, which will appear on the edit tab of organisation nodes.
    • Go back to the views page and clone the view you just made. Change the type of the new view to 'Edit View' and save it.
    • Go to the blocks admin page and enable the edit view as a block, putting
      the following as its code (note the similarity (and minor (but important) difference) to above):
      <?php
      if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
         
      $node = node_load(arg(1));
          if (
      $node->type == 'content_organisation') {
              return
      true;
          }
      }
      return
      false;
      ?>

Now when you go to an organisation node, you will see a table listing all of that organisation's employees, and when you click on its 'edit' tab, the list of employees will become editable as well.

More Cookbook Examples?

If you find another useful way to use an Editview, write a quick description and I'll add it here.

Todo

  • Access control - display a table view when users can't edit nodes. Currently unprivileged users can't edit nodes using editview, but the node editing forms are still loaded and displayed.
  • Javascript libraries loaded alongside editview.js may be loaded more than
    once. For instance, the jscalendar library that comes with the jstools module will load a new jscalendar button every time you add or edit a node, and you end up with multiple buttons per row instead of just one. The best fix would be to make sure all js libraries are idempotent.
  • Table headings/labels should show a required indicator if the field is 'required'
  • Table headings should use content types field labels when views labels are left blank

About the Developers

This project is maintained by Agileware Pty Ltd, http://www.agileware.net. Please contact us if you require a Drupal theme, custom Drupal module development, Drupal systems integration or have a complex Drupal project. We love Drupal!

Releases

Official releasesDateSizeLinksStatus
6.x-1.0-beta12009-May-0414.09 KBRecommended for 6.xThis is currently the recommended release for 6.x.
5.x-1.02009-Jan-2620.36 KBRecommended for 5.xThis is currently the recommended release for 5.x.
Development snapshotsDateSizeLinksStatus
6.x-1.x-dev2009-Jun-0414.17 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.
5.x-1.x-dev2009-May-0622.96 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.