You are here

public function PanelizerEntityDefault::add_bundle_setting_form_submit in Panelizer 7.2

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

Submit callback for the bundle edit form.

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function add_bundle_setting_form_submit($form, &$form_state, $bundle, $type_location) {

  // Some types do not support changing bundles, so we don't check if it's
  // not possible to change.
  if ($type_location) {
    $new_bundle = drupal_array_get_nested_value($form_state['values'], $type_location);
  }
  else {
    $new_bundle = $bundle;
  }

  // Check to see if the bundle has changed. If so we need to move stuff around.
  if ($bundle && $new_bundle != $bundle) {

    // Remove old settings.
    variable_del('panelizer_defaults_' . $this->entity_type . '_' . $bundle);
    $allowed_layouts = variable_get('panelizer_' . $this->entity_type . ':' . $bundle . '_allowed_layouts', NULL);
    if ($allowed_layouts) {
      variable_del('panelizer_' . $this->entity_type . ':' . $bundle . '_allowed_layouts');
      variable_set('panelizer_' . $this->entity_type . ':' . $new_bundle . '_allowed_layouts', $allowed_layouts);
    }
    $default = variable_get('panelizer_' . $this->entity_type . ':' . $bundle . '_default', NULL);
    if ($default) {
      variable_del('panelizer_' . $this->entity_type . ':' . $bundle . '_default');
      variable_set('panelizer_' . $this->entity_type . ':' . $new_bundle . '_default', $default);
    }

    // Load up all panelizer defaults for the old bundle and resave them
    // for the new bundle.
    $panelizer_defaults = $this
      ->get_default_panelizer_objects($bundle);
    foreach ($panelizer_defaults as $panelizer) {
      list($entity_type, $old_bundle, $name) = explode(':', $panelizer->name);
      $panelizer->name = implode(':', array(
        $entity_type,
        $new_bundle,
        $name,
      ));
      $panelizer->panelizer_key = $new_bundle;

      // If there's a pnid this should change the name and retain the pnid.
      // If there is no pnid this will create a new one in the database
      // because exported panelizer defaults attached to a bundle will have
      // to be moved to the database in order to follow along and
      // then be re-exported.
      // @todo -- should we warn the user about this?
      ctools_export_crud_save('panelizer_defaults', $panelizer);
    }
  }
  variable_set('panelizer_defaults_' . $this->entity_type . '_' . $new_bundle, $form_state['values']['panelizer']);

  // Unset this so that the type save forms don't try to save it to variables.
  unset($form_state['values']['panelizer']);
}