You are here

function PanelizerEntityDefault::page_context in Panelizer 7.3

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

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

function page_context($js, $input, $entity, $view_mode) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
  $cache_key = $entity_id . '.' . $view_mode;
  $panelizer = panelizer_context_cache_get($this->entity_type, $cache_key);
  if (empty($panelizer)) {
    return MENU_NOT_FOUND;
  }
  $form_state = array(
    'entity' => $entity,
    'revision info' => $this
      ->entity_allows_revisions($entity),
    'panelizer' => &$panelizer,
    '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'])) {
      $entity->panelizer[$view_mode] = $form_state['panelizer'];

      // Make sure that entity_save knows that the panelizer settings are
      // modified and must be made local to the entity.
      if (empty($panelizer->did) || !empty($panelizer->name)) {
        $panelizer->display_is_modified = TRUE;
      }

      // Update the entity.
      $this
        ->entity_save($entity);
      drupal_set_message(t('The settings have been updated.'));
    }
    else {
      drupal_set_message(t('Changes have been discarded.'));
    }

    // Clear the context cache.
    panelizer_context_cache_clear($this->entity_type, $cache_key);

    // Redirect.
    drupal_goto($_GET['q']);
  }
  return $this
    ->wrap_entity_panelizer_pages($entity, $view_mode, $output);
}