You are here

function PanelizerEntityDefault::page_settings in Panelizer 7.2

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

Switched page callback to give the settings form.

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

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

    // If this entity is not yet panelized, and there is no default panel
    // do to configuration, give them the option of panelizing it.
    if ($this
      ->has_default_panel($bundle)) {
      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);
    $panelizer->name = NULL;
  }
  else {
    $form_id = 'panelizer_settings_form';
    $reset_button = TRUE;
    $panelizer = $entity->panelizer;
  }
  $form_state = array(
    'entity' => $entity,
    'revision info' => $this
      ->entity_allows_revisions($entity),
    'panelizer' => $panelizer,
    'no_redirect' => TRUE,
  );
  if (!empty($reset_button)) {
    $form_state['reset button'] = TRUE;
  }
  ctools_include('common', 'panelizer');
  $output = drupal_build_form($form_id, $form_state);
  if (!empty($form_state['executed'])) {
    if (empty($form_state['clicked_button']['#reset'])) {
      drupal_set_message(t('The settings have been updated.'));
      $entity->panelizer = $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;
      }
      $this
        ->entity_save($entity);
    }
    else {
      $this
        ->delete_entity_panelizer($entity);
    }
    drupal_goto($_GET['q']);
  }
  return $output;
}