diff --git a/includes/common.inc b/includes/common.inc index ccadaee9cf09701c090023fa77d2b8a476a1fa16..6180e926ef71f5be4a6f841f5d0a5832eeb793ea 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -153,14 +153,14 @@ function panelizer_settings_form_submit(&$form, &$form_state) { * we can properly handle revisioning. */ function panelizer_add_revision_info_form(&$form, &$form_state) { - if (empty($form_state['entity'])) { + if (empty($form_state['display']->context['panelizer']->data)) { return; } if (empty($form_state['revision info'])) { return; } - $entity = $form_state['entity']; + $entity = $form_state['display']->context['panelizer']->data; list($use_revisions, $control_revisions, $default_revision) = $form_state['revision info']; @@ -174,6 +174,7 @@ function panelizer_add_revision_info_form(&$form, &$form_state) { $form_state['use revisions'] = TRUE; $form['revision_information'] = array( '#weight' => 11, + '#access' => $control_revisions || $entity->revision, ); $form['revision_information']['revision'] = array( @@ -221,7 +222,7 @@ function panelizer_add_revision_info_form(&$form, &$form_state) { * Form submission callback for panelizer_add_revision_info_form(). */ function panelizer_add_revision_info_form_submit(&$form, &$form_state) { - $entity = &$form_state['entity']; + $entity = &$form_state['display']->context['panelizer']->data; if (!empty($form_state['use revisions'])) { $entity->revision = $form_state['values']['revision']; $entity->log = $form_state['values']['log']; diff --git a/panelizer.install b/panelizer.install index 2a732a8be9f551aff228fbe7e71ce9d39e9140ba..2d7506d8e81ded5639eb98655996eab9aa2555cc 100644 --- a/panelizer.install +++ b/panelizer.install @@ -1157,3 +1157,18 @@ function panelizer_update_7121() { } } } + +/** + * Update new variables to reflect the current panelizer behavior. + */ +function panelizer_update_7122() { + foreach (node_type_get_types() as $type) { + $options = variable_get('node_options_' . $type->type, array('status', 'promote', 'panelizer')); + // Only set the variable if it was previously configured. + if (!in_array('panelizer', $options)) { + $options[] = 'panelizer'; + variable_set('node_options_' . $type->type, $options); + } + } +} + diff --git a/panelizer.module b/panelizer.module index 1e92e809cace55a35e59e5421ba7381123243543..479b14acb191d2f420ac2b5be38e7a6f1866fcd1 100644 --- a/panelizer.module +++ b/panelizer.module @@ -1332,17 +1332,16 @@ function panelizer_panels_cache_save($argument, $cache) { ctools_export_crud_save('panelizer_defaults', $panelizer); } else { - list($entity_id, $view_mode) = explode(':', $key); - $conditions = (isset($vid) ? array('vid' => $vid) : array()); - $entities = entity_load($entity_type, array($entity_id), $conditions); - if ($entities[$entity_id] && $entities[$entity_id]->panelizer[$view_mode]) { - $entities[$entity_id]->panelizer[$view_mode]->display = $cache->display; - $entities[$entity_id]->panelizer[$view_mode]->display_is_modified = TRUE; - $handler->entity_save($entities[$entity_id]); + list($entity_id, $view_mode, $vid) = explode(':', $key); + $entity = $cache->display->context['panelizer']->data; + if ($entity->panelizer[$view_mode]) { + $entity->panelizer[$view_mode]->display = $cache->display; + $entity->panelizer[$view_mode]->display_is_modified = TRUE; + $handler->entity_save($entity); // The display may have been cloned in the save process, so we need // to be sure to put the old display back, and its contexts. - $cache->display = $entities[$entity_id]->panelizer[$view_mode]->display; - $cache->display->context = $handler->get_contexts($entities[$entity_id]->panelizer[$view_mode], $entities[$entity_id]); + $cache->display = $entity->panelizer[$view_mode]->display; + $cache->display->context = $handler->get_contexts($entity->panelizer[$view_mode], $entity); } } panelizer_panels_cache_clear($original, $cache); diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index a113f52025e789e96962fdea4a6e9b09761cc178..921f7cc030671f652f9da08888998403efbd16d0 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -1175,12 +1175,19 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { } } + array_unshift($form['#validate'], 'panelizer_entity_default_bundle_form_validate'); array_unshift($form['#submit'], 'panelizer_entity_default_bundle_form_submit'); $form_state['panelizer_entity_handler'] = $this; } /** + * Validate callback for the bundle edit form. + */ + public function add_bundle_setting_form_validate($form, &$form_state, $bundle, $type_location) { + } + + /** * Submit callback for the bundle edit form. */ public function add_bundle_setting_form_submit($form, &$form_state, $bundle, $type_location) { @@ -3574,6 +3581,12 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { } } +function panelizer_entity_default_bundle_form_validate($form, &$form_state) { + $bundle = $form['panelizer']['#bundle']; + $type_location = $form['panelizer']['#location']; + $form_state['panelizer_entity_handler']->add_bundle_setting_form_validate($form, $form_state, $bundle, $type_location); +} + function panelizer_entity_default_bundle_form_submit($form, &$form_state) { $bundle = $form['panelizer']['#bundle']; $type_location = $form['panelizer']['#location']; diff --git a/plugins/entity/PanelizerEntityNode.class.php b/plugins/entity/PanelizerEntityNode.class.php index 22d4ab0b48e8b238720f4412ebee304bdcd543b6..bd73032befafa0d344327c106449001fe765b269 100644 --- a/plugins/entity/PanelizerEntityNode.class.php +++ b/plugins/entity/PanelizerEntityNode.class.php @@ -25,6 +25,12 @@ class PanelizerEntityNode extends PanelizerEntityDefault { * Implement the save function for the entity. */ public function entity_save($entity) { + if (module_exists('workbench_moderation') && workbench_moderation_node_type_moderated($entity->type)) { + $live_entity = workbench_moderation_node_live_load($entity); + if ($live_entity->vid != $entity->vid) { + $entity->revision = TRUE; + } + } node_save($entity); } @@ -44,10 +50,10 @@ class PanelizerEntityNode extends PanelizerEntityDefault { list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity); - $node_options = variable_get('node_options_' . $bundle, array('status', 'promote')); + $node_options = variable_get('node_options_' . $bundle, array('status', 'promote', 'panelizer')); // Whether or not the entity supports revisions. - $retval[0] = TRUE; + $retval[0] = in_array('panelizer', $node_options); // Whether or not the user can control if a revision is created. $retval[1] = user_access('administer nodes'); @@ -138,7 +144,31 @@ class PanelizerEntityNode extends PanelizerEntityDefault { $bundle = $form['#node_type']->type; $this->add_bundle_setting_form($form, $form_state, $bundle, array('type')); } + + if (module_exists('workbench_moderation')) { + // Disable the 'revision' checkbox when the 'moderation' checkbox is checked, so that moderation + // can not be enabled unless revisions are enabled. + $form['workflow']['node_options']['revision']['#states'] = array( + 'disabled' => array(':input[name="node_options[panelizer]"]' => array('checked' => FALSE)), + ); + + // Disable the 'moderation' checkbox when the 'revision' checkbox is not checked, so that + // revisions can not be turned off without also turning off moderation. + $form['workflow']['node_options']['#options']['panelizer'] = t('Enable panelizer revisions'); + $form['workflow']['node_options']['panelizer']['#description'] = t('Revisions must be enabled in order to create panelizer revisions.'); + $form['workflow']['node_options']['panelizer']['#states'] = array( + 'disabled' => array(':input[name="node_options[revision]"]' => array('checked' => FALSE)), + ); + } + } + } + + public function add_bundle_setting_form_validate($form, &$form_state, $bundle, $type_location) { + // Ensure that revisions are enabled if panelizer revisions are. + if (isset($form_state['values']['node_options']['panelizer']) || array_key_exists('panelizer', $form_state['values']['node_options'])) { + $form_state['values']['node_options']['revision'] = 1; } + parent::add_bundle_setting_form_validate($form, $form_state, $bundle, $type_location); } public function hook_page_alter(&$page) {