You are here

function PanelizerEntityDefault::page_settings in Panelizer 7.3

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

Switched page callback to give the settings form.

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

function page_settings($js, $input, $entity, $view_mode) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
  if (empty($entity->panelizer[$view_mode])) {

    // If this entity is not yet panelized, and there is no default panel
    // to do configuration, give them the option of panelizing it.
    if ($this
      ->has_default_panel($bundle . '.' . $view_mode)) {
      return MENU_NOT_FOUND;
    }

    // Set the form to the Panelize It! form.
    $form_id = 'panelizer_panelize_entity_form';

    // Fetch a special default panelizer that is only accessible with the
    // default_anyway flag.
    $panelizer = $this
      ->get_internal_default_panelizer($bundle, $view_mode);
    $panelizer->name = NULL;
  }
  else {
    $form_id = 'panelizer_settings_form';
    $panelizer = $entity->panelizer[$view_mode];
  }
  $form_state = array(
    'entity' => $entity,
    'revision info' => $this
      ->entity_allows_revisions($entity),
    'panelizer' => $panelizer,
    'view_mode' => $view_mode,
    'no_redirect' => TRUE,
  );
  ctools_include('common', 'panelizer');
  $output = drupal_build_form($form_id, $form_state);
  if (!empty($form_state['executed'])) {
    $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.'));

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