Last updated April 11, 2013. Created on March 15, 2013.
Edited by joachim. Log in to edit this page.
The Editable Views module allows you to turn a view into a form, where fields on entities can be edited and saved.
Each FieldAPI field provides an editable field handler to Views. These must be used with a special editable style plugin: currently this only exists for tables.
Usage
- Set the view to use the 'Editable table' style
- Add one or more editable fields. You can also add normal, non-editable fields which will function normally.
- If your view has relationships, you can add editable fields on those too. However, relationships which are not set to 'required' have special considerations: see below
- You can now save your view and use it to edit entities. If your view has exposed filters, these will work normally alongside the view edit form.
Non-required relationships
A relationship that is not set to 'required' can produce a result row in the view where there is data on the view's base, but not in the fields on the relationship: part of the view table will have a gap. If these fields are editable, then they will still show form elements: these allow the creation of a new entity. When the view form is saved, the original gap will be filled with the newly saved entity.
However, there are limitations of this:
- The bundle of the entity to create must be specified in the 'Editable table' settings. This is because while the entity type for the new entity is given by the relationship, there is no simple way to determine automatically what the bundle of the new entities should be.
- If the editable fields on the entity to create have default values (set in Field admin) then new entities will always be created. This is because there is no way to determine whether the user has set a value or not.
- Only relationships on Entity Reference fields are supported for now. Further relationships may be supported by setting the required properties: see the developer documentation.
Developer documentation
Editable field handlers
An editable field handler for an entity can be a subclass of any field handler: this allows the FieldAPI field editable handler to inherit useful methods to do with FieldAPI fields, and the node title handler likewise.
To provide an editable field, a field handler must implement:
- edit_form($entity_type, $entity, &$element, &$form_state): alter the form element to place the handler's form element on it, for the given entity
- edit_form_validate($entity_type, $entity, &$element, &$form_state): perform form validation on the handler's form element
- edit_form_submit($entity_type, $entity, &$element, &$form_state): extract the handler's value from the form state values, and place it on the entity
Entity creating relationships
For a relationship to support entity creation, its definition in hook_views_data() must have the following extra properties:
- 'editableviews_direction': One of 'forward' or 'reverse', according to which entity in the relationship has the value that points to the other. If the first entity points to the entity the relationship brings (or creates), the relationship is 'forward'. If the relationship entity points back, the relationship is 'reverse'.
- 'field_name': The name of the Entity API Metadata property to use to set on one entity to make it point to the other.
Editable style plugins
Currently only the Editable Table style plugin exists. However, there is little that is specific to the view being shown as a table: further parts of this could be refactored out to the helper class, and other style plugins could make use of this.
Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.
Comments
Duplicate fields
Hi, I used your module and it works fine, but I have a problem:
into the editable page created I see the same editable fields twice.
Can I have to set something?
Thanks in advice