1

The Field Collection module does not support revisions. Yes there are lots of patches which are still under review. But what I want to do is create a module that on the node edit screen, queries the fields of the content type and removes the Revision Information tab (or disables the "Create new revision" checkbox) if the content type has one or more Field Collection fields. Any help on how which hook to use, how to query the fields of a node, and how to disable the revisions tab would be very helpful. This module needs to be applied to hundreds of sites.

Thanks to pcambra, here is my module:

function epc_no_revisions_for_fc_form_node_form_alter(&$form, $form_state) {

    $collection_fields = field_read_fields(array('type' => 'field_collection'));

    foreach($collection_fields as $FC){
        if(isset($form['#node']->$FC['field_name'])){
            $form['revision_information']['#access'] = FALSE;
            drupal_set_message("This node cannot accept revisions because it contains the following Field Collection: " . $FC['field_name'],'status');
        }
    }
}

UPDATE:

The above module didn't handle a fresh node where the fields had not yet been set. So I revised it to first load all the fields in the database and see if any belong to the bundle (content type) in question:

function epc_no_revisions_for_fc_form_node_form_alter(&$form, $form_state) {
    if(_epc_no_revisions_for_fc_test_for_fc($form['#node']->type)){
        drupal_set_message("Please note: This node cannot accept revisions because it contains a Field Collection",'status');
        $form['revision_information']['#access'] = FALSE;
    }
}

function epc_no_revisions_for_fc_node_presave($node) {
    if(_epc_no_revisions_for_fc_test_for_fc($node->type)){
        if($node->revision == 1){
            $node->revision = 0;
            drupal_set_message("No revision was created because the content type contains a Field Collection",'status');
        }
    }
}

function _epc_no_revisions_for_fc_test_for_fc($node_type){
    $fields = field_info_fields();
    foreach($fields as $field){
        if($field['type'] == 'field_collection'){
            foreach(array_shift($field['bundles']) as $content_type){
                if($node_type == $content_type){
                    return true;

                }
            }
        }
    }
    return false;
}
1
  • hook_form_alter and the Entity API could help you to do this, along with the Devel module to inspect $form within hook_form_alter.
    – tenken
    Jul 16, 2014 at 14:49

2 Answers 2

3

You could use hook_form_FORM_ID_alter to alter your node forms of the content type (s) you need.

function my_module_form_node_form_alter(&$form, $form_state) {
  if ($form['#node']->type == 'my_content_type') {
    // Your code goes here.
  }
}

Now you need to know whether or not it has a field collection field on it. You can use one of the field api functions for this, for example, this will give you the field collections in your site:

$collection_fields = field_read_fields(array('type' => 'field_collection'));

Then you can check if your node has one of these to see if you disable the revision feature or not.

You can disable the checkbox appearance by adding an #access FALSE:

$form['revision_information']['#access'] = FALSE;

It's probably safer to repeat this operation and checks in hook_node_presave if that makes sense for your workflow.

Additionally, there are a couple of modules relevant to this issue, Jammer allows you to hide some specifics from the node creation form and so on, but nothing condition based. There's also Field SQL no revisions that will skip saving information for revisions, be careful because there's no come back from this one so you need to be very sure you're not using revisions for your fields in any other content type.

1
  • I want this for all content types except ones with field collections. Please see my revised question for my solution (thanks to you).
    – JM01
    Jul 16, 2014 at 20:42
0

I might be missing something, but: Revisioning is a per content type setting, accessible at admin/structure/types/manage/ Assuming you really mean to turn off revisioning for content types which contain field collections (as opposed to the node you are editing contains field collection data), go there. admin/reports/fields helps you figure out where field collections are used.

1
  • Thought of that but I have to apply this to hundreds of sites. I'm not going to go through each content type.
    – JM01
    Jul 16, 2014 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.