In the PanelizerEntityDefault.class.php, function hook_entity_update(), around rows 933 - 947, the Panelizer sets $update = array('entity_type', 'revision_id', 'view_mode'); if $this->supports_revisions is true. This causes the drupal_write_record to execute update on a database row instead of insert. Issue is that in some cases the panelizer_entity table might be missing row for that node and thus the Panelizer settings are not saved. In my opinion the code should check the $panelizer->entity_id to determine if it should do an insert or an update. Currently it uses the $this->supports_revisions to determine it.

Possible way to reproduce

  • Create new content type without panelizer set
  • Create nodes on that content type
  • Enable Panelizer on the content type
  • Try to edit nodes Panelizer settings, for example by settings a CSS class to it. Changes are not saved
  • Create new node (same content) type, edit node Panelizer settings => changes are stored to panelizer_entity DB table

Possible fix to the PanelizerEntityDefault.class.php file, function hook_entity_update. This code change made it possible to edit nodes that did not previously save node Panelizer changes.

old code

if ($this->supports_revisions) {
        if (empty($panelizer->revision_id) || $panelizer->revision_id != $revision_id) {
          $panelizer->revision_id = $revision_id;
        }

        $update = array('entity_type', 'revision_id', 'view_mode');
      }
      else {
        if (empty($panelizer->entity_id)) {
          $update = array();
        }
        else {
          $update = array('entity_type', 'entity_id', 'view_mode');
        }
      }

new code

     if ($this->supports_revisions) {
        if (empty($panelizer->revision_id) || $panelizer->revision_id != $revision_id) {
          $panelizer->revision_id = $revision_id;
        }
      }

      // If panelizer is missing entity_id, new panelizer_entity row needs to be created
      if (empty($panelizer->entity_id)) {
        $update = array();
      }
      else {
        // Existing row, do an update to the row
        $update = array('entity_type', 'entity_id', 'view_mode');
      }

Comments

mikat’s picture

This can be also fixed without touching the Panelizer code. Since in our project this only happens in 10-30 nodes, I created code that executes panelizer entity update.

$nid = null; // Get nid from somewhere
$entity = entity_load_single('node', $nid);
  if ($entity && $handler = panelizer_entity_plugin_get_handler('node')) {
    $handler->supports_revisions = false;
    $handler->hook_entity_update($entity);
  }

In my case I use $_GET to get the nid so when faulty node is spotted, it can be fixed by simply setting the nid in the URL.

damienmckenna’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

I'm unable to reproduce this with the current 7.x-3.x-dev release, please test it again.