You are here

function panelizer_edit_node_settings_page in Panelizer 6

Same name and namespace in other branches
  1. 7 includes/node.inc \panelizer_edit_node_settings_page()

Page to edit basic settings on a panelized node.

1 string reference to 'panelizer_edit_node_settings_page'
panelizer_menu in ./panelizer.module
Implementation of hook_menu().

File

includes/node.inc, line 179
Contains routines specific to handling nodes that are panelized.

Code

function panelizer_edit_node_settings_page($node) {
  $panelizer = panelizer_load_node_panelizer($node);
  if (empty($panelizer)) {

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

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

    // Fetch a special default panelizer that is only accessible with the
    // default_anyway flag.
    $panelizer = panelizer_load_node_panelizer($node, TRUE);
  }
  else {
    $form_id = 'panelizer_settings_form';
    $reset_button = TRUE;
  }
  _panelizer_check_admin_theme();
  $form_state = array(
    'panelizer' => &$panelizer,
    'no_redirect' => TRUE,
  );
  if (!empty($reset_button)) {
    $form_state['reset button'] = TRUE;
  }

  // load a comparison panelizer so that we can detect changes to the load object
  $compare_panelizer = panelizer_load_node_panelizer($node, TRUE);
  ctools_include('form');
  ctools_include('common', 'panelizer');
  $output = ctools_build_form($form_id, $form_state);
  if (!empty($form_state['executed'])) {
    if (empty($form_state['clicked_button']['#reset'])) {
      $difference = false;
      foreach ($panelizer as $key => $value) {
        if ($value != $compare_panelizer->{$key}) {
          $difference = true;
        }
      }
      if ($difference) {
        drupal_set_message(t('The settings have been updated.'));
        panelizer_save_node_panelizer($panelizer);
      }
      else {
        drupal_set_message(t('No changes found, using original settings.'));
      }
    }
    else {
      panelizer_delete_node_panelizer($panelizer);
      drupal_set_message(t('The node panel has been reset to the default.'));
    }
    drupal_goto($_GET['q']);
  }
  return $output;
}