0

I have a content type which uses panelizer. I have placed different panes in different regions.

Everything is working. I have existing nodes with the same settings.

Now I added a anew pane to the content type panelizer. But that pane is not displaying for the existing nodes.

Is there a way to update the existing nodes to display that new pane?

I have tried the following but with no luck.

function update_entity_panelizer($entity_type = 'node', $entity) {
      // Get the default display of the panelizer object.
      ctools_include('export');
      $panelizers = ctools_export_load_object('panelizer_defaults');

      $panelizer = $panelizers["$entity_type:$entity->type:default"];
      $default_display = $panelizer->display;
      $default_content = $default_display->content;

      $updated_displays = array();
      if (
        !empty($entity->panelizer['page_manager']->display->did) &&
        $entity->panelizer['page_manager']->display->did != 'new' &&
        !in_array($entity->panelizer['page_manager']->display->did, $updated_displays)
      ) {
        $updated_displays[] = $entity->panelizer['page_manager']->did;
        $display = panels_load_display($entity->panelizer['page_manager']->display->did);

        // Loop over the content in the entity and preserve the content in the
        // right and bottom columns because these stay unaltered if the renderer
        // comes from the content_region pipeline.
        if ($panelizer->pipeline == 'paddle_content_region') {
          foreach ($display->content as $pid => $pane) {
            if (!in_array($pane->panel, array('right', 'bottom'))) {
              unset($display->content[$pid]);
            }
          }
        }

        // For every existing pane, create a new pane and hand it in the display.
        foreach ($default_content as $pid => $pane) {
          if (
            $panelizer->pipeline != 'paddle_content_region' ||
            ($panelizer->pipeline == 'paddle_content_region' &&
              !in_array($pane->panel, array('right', 'bottom')))
          ) {
            $new_pane = panels_new_pane($pane->type, $pane->subtype, TRUE);

            foreach ($pane as $key => $value) {
                $new_pane->{$key} = $pane->{$key};
            }

            $display->content[$new_pane->pid] = $new_pane;
            $display->panels[$new_pane->panel][] = $new_pane->pid;
          }
        }

        panels_save_display($display);
      }
    }
    function testmodule_update_7001() {
      $limit = 5;
      $entities = paddle_core_get_entity_revisions('node', array('content_type'));
      $sandbox['entities'] = $entities;

      batch_helper(
        $sandbox,
        $limit,
        // Count callback.
        function (&$sandbox) {
          return count($sandbox['entities']);
        },
        // Range retrieval callback.
        function ($limit, &$sandbox) {
          $offset = $sandbox['progress'];
          return array_slice($sandbox['entities'], $offset, $limit);
        },
        // Single item update callback.
        function ($entity, &$sandbox) {
          try {
            update_entity_panelizer('node', $entity);
            return TRUE;
          } catch (\Exception $e) {
            // Nothing we can do.
            return FALSE;
          }
        },
        // Progress message callback.
        function ($sandbox) {
          $item = $sandbox['last_item'];
          $updated = $sandbox['last_item_update_status'];

          $id_string = "{$item->type} {$item->nid} rev {$item->vid} lang {$item->language}";
          $action = $updated ? "has been updated" : "could NOT be updated";
          return $id_string . " " . $action . ".";
        }
      );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.