You are here

function PanelizerEntityDefault::page_context in Panelizer 7.2

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

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

function page_context($js, $input, $entity) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
  $cache_key = $entity_id;
  $panelizer = panelizer_context_cache_get($this->entity_type, $cache_key);
  if (empty($panelizer)) {
    return MENU_NOT_FOUND;
  }
  $form_state = array(
    'panelizer' => &$panelizer,
    'entity' => $entity,
    'revision info' => $this
      ->entity_allows_revisions($entity),
    'panelizer type' => $this->entity_type,
    'cache key' => $cache_key,
    'no_redirect' => TRUE,
  );
  ctools_include('common', 'panelizer');
  $output = drupal_build_form('panelizer_default_context_form', $form_state);
  if (!empty($form_state['executed'])) {
    if (!empty($form_state['clicked_button']['#write'])) {
      drupal_set_message(t('The settings have been updated.'));
      $entity->panelizer = $form_state['panelizer'];
      $this
        ->entity_save($entity);
    }
    else {
      drupal_set_message(t('Changes have been discarded.'));
    }
    panelizer_context_cache_clear($this->entity_type, $cache_key);
    drupal_goto($_GET['q']);
  }
  return $output;
}