From 4aa84cadae0cffa11f595823e93f94efa1afb01c Mon Sep 17 00:00:00 2001 From: Jakob Perry Date: Wed, 17 Aug 2016 10:35:42 -0700 Subject: [PATCH] 2457113 # Conflicts: # panelizer.install --- includes/common.inc | 7 ++-- panelizer.install | 14 ++++++++ panelizer.module | 21 ++++++----- plugins/entity/PanelizerEntityDefault.class.php | 21 +++++++++++ plugins/entity/PanelizerEntityNode.class.php | 48 +++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 16 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index ccadaee..6180e92 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 4fc17d1..4ba1898 100644 --- a/panelizer.install +++ b/panelizer.install @@ -1329,3 +1329,17 @@ function panelizer_update_7303(&$sandbox) { return t('Added the storage type for panelizer_entities to relevant panels displays'); } } + +/** + * Update new variables to reflect the new Panelizer behavior for revision + * handling when using Workbench Moderation. + */ +function panelizer_update_7304() { + foreach (node_type_get_types() as $type) { + $options = variable_get('node_options_' . $type->type, array('status', 'promote', 'panelizer')); + // Only set the variable if it wasn't 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 9133367..eb58f97 100644 --- a/panelizer.module +++ b/panelizer.module @@ -1413,17 +1413,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]); - // The display may have been cloned in the save process, so 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]); + 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 = $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 ba2ae74..afb82d8 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -1177,12 +1177,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) { @@ -3658,6 +3665,20 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { } } +/** + * Form API validation callback for + * PanelizerEntityDefault->add_bundle_setting_form(). + */ +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); +} + +/** + * Form API submission callback for + * PanelizerEntityDefault->add_bundle_setting_form(). + */ 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 b43261c..8b00f2e 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,15 @@ 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. + // Whether or not the entity supports revisions. Drupal core supports + // revisions by default on nodes; if Workbench Moderation is enabled it's + // possible to disable this. $retval[0] = TRUE; + if (module_exists('workbench_moderation')) { + $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'); @@ -141,7 +152,40 @@ class PanelizerEntityNode extends PanelizerEntityDefault { $bundle = $form['#node_type']->type; $this->add_bundle_setting_form($form, $form_state, $bundle, array('type')); } + + // Additional workflow options when Workbench Moderation is enabled. + if (module_exists('workbench_moderation')) { + // It's now possible to disable revision creation through the Panelizer + // interface. + $form['workflow']['node_options']['#options']['panelizer'] = t('Enable Panelizer revisions'); + + // 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']['panelizer']['#description'] = t('Revisions must be enabled in order to create revisions from within Panelizer.'); + $form['workflow']['node_options']['panelizer']['#states'] = array( + 'disabled' => array(':input[name="node_options[revision]"]' => array('checked' => FALSE)), + ); + } + } + } + + /** + * {@inheritDoc} + */ + 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) { -- 2.6.4 (Apple Git-63)