You are here

function PanelizerEntityDefault::page_layout in Panelizer 7.2

Same name and namespace in other branches
  1. 7.3 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::page_layout()

File

plugins/entity/PanelizerEntityDefault.class.php, line 1124
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

function page_layout($js, $input, $entity, $step = NULL, $layout = NULL) {
  $panelizer = $entity->panelizer;
  if (empty($panelizer)) {
    return MENU_NOT_FOUND;
  }
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
  $display = $panelizer->display;
  $display->context = $this
    ->get_contexts($panelizer, $entity);
  $bits = explode('/', $this->plugin['entity path']);
  foreach ($bits as $count => $bit) {
    if (strpos($bit, '%') === 0) {
      $bits[$count] = $entity_id;
    }
  }
  $bits[] = 'panelizer';
  $finish_path = $bits;
  $bits[] = 'layout';
  $bits[] = '%step';
  $form_state = array(
    'entity' => $entity,
    'revision info' => $this
      ->entity_allows_revisions($entity),
    'display' => $display,
    'wizard path' => implode('/', $bits),
    'allowed_layouts' => 'panelizer_' . $this->entity_type . ':' . $bundle,
  );
  ctools_include('common', 'panelizer');
  $output = panelizer_change_layout_wizard($form_state, $step, $layout);
  if (!empty($form_state['complete'])) {
    $entity->panelizer->display = $form_state['display'];
    $entity->panelizer->display_is_modified = TRUE;
    $this
      ->entity_save($entity);
    drupal_set_message(t('The layout has been changed.'));
    drupal_goto(implode('/', $finish_path) . '/content');
  }
  return $output;
}