diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install index b62bfcf..bebedb3 100644 --- a/fieldable_panels_panes.install +++ b/fieldable_panels_panes.install @@ -32,6 +32,7 @@ function fieldable_panels_panes_uninstall() { // Variables. variable_del('fieldable_panels_panes_skip_default_type'); variable_del('fpp_blocks_expose'); + variable_del('fpp_revision_locking'); // Delete any variables that begin with 'fpp_expose_'. $results = db_query('SELECT name FROM {variable} WHERE name LIKE :var', array(':var' => 'fpp_expose_%'))->fetchCol(); diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module index aaf6691..5f381d7 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -1543,3 +1543,32 @@ function fieldable_panels_panes_file_download_access($field, $entity_type, $enti return ctools_access($entity->view_access, fieldable_panels_panes_get_base_context($entity)); } } + +/** + * Determine if an FPP's revision should be locked. + * + * @param object $entity + * The FPP object being examined. + * + * @return bool + */ +function fieldable_panels_panes_revision_is_lockable($entity) { + $lock = variable_get('fpp_revision_locking', 'legacy'); + + // Only non-reusable FPPs will be lockable. + if ($lock == 'lock') { + $revision_context_aware = empty($entity->reusable); + } + + // Lock all revisions, even reusable FPPs. + elseif ($lock == 'lock_all') { + $revision_context_aware = TRUE; + } + + // Legacy mode, no revisions handling. + else { + $revision_context_aware = FALSE; + } + + return $revision_context_aware; +} diff --git a/includes/admin.inc b/includes/admin.inc index 9625a86..5867cde 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -9,10 +9,20 @@ * Page callback for settings page. */ function fieldable_panels_panes_settings() { - // Get array of all FPP bundles. - $bundles = fieldable_panels_panes_get_bundle_labels(); - $form = array(); + + $form['fpp_revision_locking'] = array( + '#type' => 'radios', + '#title' => t('Should pane changes create new revisions?'), + '#description' => t(''), + '#options' => array( + 'legacy' => t('Ignore, every change saves directly.'), + 'lock' => t('Lock non-resuable FPPs.'), + 'lock_all' => t('Lock non-resuable and reusable FPPs.'), + ), + '#default_value' => variable_get('fpp_revision_locking', 'legacy'), + ); + $form['fpp_blocks_expose'] = array( '#type' => 'checkbox', '#title' => t('Make fieldable panels panes available as blocks'), @@ -33,6 +43,7 @@ function fieldable_panels_panes_settings() { ); // Render checkbox for each FPP bundle if any FPP bundles exist. + $bundles = fieldable_panels_panes_get_bundle_labels(); if (!empty($bundles)) { foreach ($bundles as $bundle => $info) { $form['bundles']['fpp_expose_' . $bundle] = array( diff --git a/plugins/content_types/fieldable_panels_pane.inc b/plugins/content_types/fieldable_panels_pane.inc index c96c622..0a12b36 100644 --- a/plugins/content_types/fieldable_panels_pane.inc +++ b/plugins/content_types/fieldable_panels_pane.inc @@ -255,47 +255,45 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form_sub fieldable_panels_panes_entity_edit_form_submit($form, $form_state); - // @todo: This is here to show that this should be a setting somewhere, - // however, I was having a time figuring out the appropriate place to put it - // and what to call it exactly. This is only temporary and hopefully someone - // will have some ideas. this would only apply for things like panelizer - // pages so that a pane actually corresponds to revision of the node. When - // the entity is reusable we want it to act as if it were global. We should - // also add some type of notice on the form so it's not completely - // confusing for users. - $revision_context_aware = !empty($entity->reusable); + // Determine how to handle revision locking. + $revision_context_aware = fieldable_panels_panes_revision_is_lockable($entity); + // If this is a new entity entity, or revision locking is enabled, look for a + // specific ID to use. if (!empty($entity->is_new) || $revision_context_aware) { + // If UUID is available, use it. if (module_exists('uuid') && isset($entity->uuid)) { if ($revision_context_aware) { - $entity_id = 'vuuid:' . $entity->vuuid; + $subtype = 'vuuid:' . $entity->vuuid; } else { - $entity_id = 'uuid:' . $entity->uuid; + $subtype = 'uuid:' . $entity->uuid; } } + + // Otherwise use the native ID values. else { if ($revision_context_aware) { - $entity_id = 'vid:' . $entity->vid; + $subtype = 'vid:' . $entity->vid; } else { - $entity_id = 'fpid:' . $entity->fpid; + $subtype = 'fpid:' . $entity->fpid; } } } + // The 'current' key will tell FPP to load up the current revision. This + // bypasses the entity cache on the FPP entity class and loads the revision + // that was just saved instead of the previous revision. This is only really + // relevant in Panels IPE administration or similar circumstances. else { - // The 'current' key will tell FPP to load up the current revision. This - // bypasses the entity cache on the FPP entity class and loads the revision - // that was just saved instead of the previous revision. This is only - // really relevant in Panels IPE administration or similar circumstances. - $entity_id = 'current:' . $entity->fpid; + $subtype = 'current:' . $entity->fpid; } // @todo: This won't work if $form_state does not contain 'pane' which could // theoretically happen in a non-Panels use case. Not that anybody uses this // outside of Panels. - $form_state['pane']->subtype = $entity_id; + $form_state['pane']->subtype = $subtype; } /** @@ -348,8 +346,10 @@ function _fieldable_panels_panes_custom_content_type($entity) { 'icon' => 'icon_block_custom.png', ); - $revision_context_aware = !empty($entity->reusable); + // Determine how to handle revision locking. + $revision_context_aware = fieldable_panels_panes_revision_is_lockable($entity); + // If UUID is available, use it. if (module_exists('uuid') && isset($entity->uuid)) { if ($revision_context_aware) { $info['name'] = 'vuuid:' . $entity->vuuid; @@ -358,6 +358,8 @@ function _fieldable_panels_panes_custom_content_type($entity) { $info['name'] = 'uuid:' . $entity->uuid; } } + + // Otherwise use the native ID values. else { if ($revision_context_aware) { $info['name'] = 'vid:' . $entity->vid;