/**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     ctools_include('export');
     $object = ctools_export_crud_load($this->getComponent(), $this->getIdentifier());
     if ($object) {
         ctools_export_crud_delete($this->getComponent(), $object);
     }
     $data = $this->getData();
     $data->export_type = NULL;
     // get title_pane key if configured.
     if (isset($data->conf['display']->title_pane)) {
         $title_pane = $data->conf['display']->title_pane;
     }
     $display = panels_save_display($data->conf['display']);
     // title_pane configuration workaround.
     if (isset($display->content[$title_pane])) {
         $pid = $display->content[$title_pane]->pid;
         $display->{$title_pane} = $pid;
         db_update('panels_display')->fields(array('title_pane' => $pid))->condition('did', $display->did)->execute();
     }
     $data->conf['did'] = $data->conf['display']->did;
     unset($data->conf['display']);
     ctools_export_crud_save($this->getComponent(), $data);
     $settings->addInfo('imported', $this->getUniqueId());
 }
 public function save()
 {
     $op = $this->inDatabase ? 'edit' : 'insert';
     $values = new stdClass();
     // $this;
     $values->sid = $this->sid;
     $values->consumer_type = $this->consumerType;
     $values->consumer_module = $this->consumer->consumerModule;
     $values->status = $this->status ? 1 : 0;
     $values->only_ldap_authenticated = (int) $this->onlyApplyToLdapAuthenticated;
     $values->derive_from_dn = (int) $this->deriveFromDn;
     $values->derive_from_dn_attr = $this->deriveFromDnAttr;
     $values->derive_from_attr = (int) $this->deriveFromAttr;
     $values->derive_from_attr_attr = $this->arrayToLines($this->deriveFromAttrAttr);
     $values->derive_from_attr_use_first_attr = (int) $this->deriveFromAttrUseFirstAttr;
     $values->derive_from_attr_nested = (int) $this->deriveFromAttrNested;
     $values->derive_from_entry = (int) $this->deriveFromEntry;
     $values->derive_from_entry_search_all = (int) $this->deriveFromEntrySearchAll;
     $values->derive_from_entry_entries = $this->arrayToLines($this->deriveFromEntryEntries);
     $values->derive_from_entry_entries_attr = $this->deriveFromEntryEntriesAttr;
     $values->derive_from_entry_attr = $this->deriveFromEntryMembershipAttr;
     $values->derive_from_entry_user_ldap_attr = $this->deriveFromEntryAttrMatchingUserAttr;
     $values->derive_from_entry_use_first_attr = (int) $this->deriveFromEntryUseFirstAttr;
     $values->derive_from_entry_nested = (int) $this->deriveFromEntryNested;
     $values->mappings = $this->arrayToPipeList($this->mappings);
     $values->use_filter = (int) $this->useMappingsAsFilter;
     $values->synch_to_ldap = (int) $this->synchToLdap;
     $values->synch_on_logon = (int) $this->synchOnLogon;
     $values->revoke_ldap_provisioned = (int) $this->revokeLdapProvisioned;
     $values->create_consumers = (int) $this->createConsumers;
     $values->regrant_ldap_provisioned = (int) $this->regrantLdapProvisioned;
     if (module_exists('ctools')) {
         ctools_include('export');
         // Populate our object with ctool's properties
         $object = ctools_export_crud_new('ldap_authorization');
         foreach ($object as $property => $value) {
             if (!isset($values->{$property})) {
                 $values->{$property} = $value;
             }
         }
         $result = ctools_export_crud_save('ldap_authorization', $values);
     } elseif ($op == 'edit') {
         $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
     } else {
         // insert
         $result = drupal_write_record('ldap_authorization', $values);
     }
     if ($result) {
         $this->inDatabase = TRUE;
     } else {
         drupal_set_message(t('Failed to write LDAP Authorization to the database.'));
     }
     // revert mappings to array and remove temporary properties from ctools export
     $this->mappings = $this->pipeListToArray($values->mappings, TRUE);
     foreach (array('consumer_type', 'consumer_module', 'only_ldap_authenticated', 'derive_from_dn', 'derive_from_dn_attr', 'derive_from_attr', 'derive_from_attr_attr', 'derive_from_attr_use_first_attr', 'derive_from_attr_nested', 'derive_from_entry', 'derive_from_entry_entries', 'derive_from_entry_attr', 'derive_from_entry_search_all', 'derive_from_entry_use_first_attr', 'derive_from_entry_nested', 'use_filter', 'synch_to_ldap', 'synch_on_logon', 'revoke_ldap_provisioned', 'create_consumers', 'regrant_ldap_provisioned') as $prop_name) {
         unset($this->{$prop_name});
     }
 }
 public function save()
 {
     $op = $this->inDatabase ? 'edit' : 'insert';
     $values = new stdClass();
     // $this;
     $values->sid = $this->sid;
     $values->numeric_consumer_conf_id = $this->numericConsumerConfId;
     $values->consumer_type = $this->consumerType;
     $values->consumer_module = $this->consumer->consumerModule;
     $values->status = $this->status ? 1 : 0;
     $values->only_ldap_authenticated = (int) $this->onlyApplyToLdapAuthenticated;
     $values->use_first_attr_as_groupid = (int) $this->useFirstAttrAsGroupId;
     $values->mappings = serialize($this->mappings);
     $values->use_filter = (int) $this->useMappingsAsFilter;
     $values->synch_to_ldap = (int) $this->synchToLdap;
     $values->synch_on_logon = (int) $this->synchOnLogon;
     $values->revoke_ldap_provisioned = (int) $this->revokeLdapProvisioned;
     $values->create_consumers = (int) $this->createConsumers;
     $values->regrant_ldap_provisioned = (int) $this->regrantLdapProvisioned;
     if (module_exists('ctools')) {
         ctools_include('export');
         // Populate our object with ctool's properties
         $object = ctools_export_crud_new('ldap_authorization');
         foreach ($object as $property => $value) {
             if (!isset($values->{$property})) {
                 $values->{$property} = $value;
             }
         }
         try {
             $values->export_type = NULL;
             $result = ctools_export_crud_save('ldap_authorization', $values);
         } catch (Exception $e) {
             //  debug($e); Integrity constraint violation: 1062 Duplicate entry
             $values->export_type = EXPORT_IN_DATABASE;
             $result = ctools_export_crud_save('ldap_authorization', $values);
         }
         ctools_export_load_object_reset('ldap_authorization');
         // ctools_export_crud_save doesn't invalidate cache
     } else {
         if ($op == 'edit') {
             $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
         } else {
             // insert
             $result = drupal_write_record('ldap_authorization', $values);
         }
         if ($result) {
             $this->inDatabase = TRUE;
         } else {
             drupal_set_message(t('Failed to write LDAP Authorization to the database.'));
         }
     }
 }
Пример #4
0
 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     ctools_include('export');
     $object = ctools_export_crud_load($this->getComponent(), $this->getIdentifier());
     if ($object) {
         ctools_export_crud_delete($this->getComponent(), $object);
     }
     $data = $this->getData();
     $data->export_type = NULL;
     $group = field_group_unpack($data);
     ctools_export_crud_save($this->getComponent(), $group);
     $settings->addInfo('imported', $this->getUniqueId());
 }
Пример #5
0
 public function save($op)
 {
     $op = $this->inDatabase ? 'edit' : 'insert';
     if (module_exists('ctools')) {
         // add or edit with ctolls
         ctools_include('export');
         $ctools_values = clone $this;
         foreach ($this->fields() as $field_id => $field) {
             $value = $this->{$field['property_name']};
             if (isset($field['exportable']) && $field['exportable'] === FALSE) {
                 // field not exportable
                 unset($ctools_values->{$field['property_name']});
             } elseif (isset($field['schema']) && $field['property_name'] != $field_id) {
                 // field in property with different name
                 $ctools_values->{$field_id} = $value;
                 unset($ctools_values->{$field['property_name']});
             } else {
                 // do nothing.  property is already in cloned objecat
             }
         }
         // Populate our object with ctool's properties.  copying all properties for backward compatibility
         $object = ctools_export_crud_new('ldap_query');
         foreach ($object as $property_name => $value) {
             if (!isset($ctools_values->{$property_name})) {
                 $ctools_values->{$property_name} = $value;
             }
         }
         $result = ctools_export_crud_save('ldap_query', $ctools_values);
         ctools_export_load_object_reset('ldap_query');
         // ctools_export_crud_save doesn't invalidate cache
     } else {
         $values = array();
         foreach ($this->fields() as $field_id => $field) {
             if (isset($field['schema'])) {
                 $values[$field_id] = $this->{$field['property_name']};
             }
         }
         if ($op == 'edit') {
             // edit w/o ctools
             $result = drupal_write_record('ldap_query', $values, 'qid');
         } else {
             // insert
             $result = drupal_write_record('ldap_query', $values);
         }
     }
     if ($result) {
         $this->inDatabase = TRUE;
     } else {
         drupal_set_message(t('Failed to write LDAP Query to the database.'));
     }
 }
 public function save()
 {
     $op = $this->inDatabase ? 'edit' : 'insert';
     $values = new stdClass();
     // $this;
     $values->sid = $this->sid;
     $values->numeric_consumer_conf_id = $this->numericConsumerConfId;
     $values->consumer_type = $this->consumerType;
     $values->consumer_module = $this->consumer->consumerModule;
     $values->status = $this->status ? 1 : 0;
     $values->only_ldap_authenticated = (int) $this->onlyApplyToLdapAuthenticated;
     $values->useFirstAttrAsGroupId = (int) $this->useFirstAttrAsGroupId;
     $values->mappings = $this->arrayToPipeList($this->mappings);
     $values->use_filter = (int) $this->useMappingsAsFilter;
     $values->synch_to_ldap = (int) $this->synchToLdap;
     $values->synch_on_logon = (int) $this->synchOnLogon;
     $values->revoke_ldap_provisioned = (int) $this->revokeLdapProvisioned;
     $values->create_consumers = (int) $this->createConsumers;
     $values->regrant_ldap_provisioned = (int) $this->regrantLdapProvisioned;
     if (module_exists('ctools')) {
         ctools_include('export');
         // Populate our object with ctool's properties
         $object = ctools_export_crud_new('ldap_authorization');
         foreach ($object as $property => $value) {
             if (!isset($values->{$property})) {
                 $values->{$property} = $value;
             }
         }
         $values->export_type = $this->numericConsumerConfId ? EXPORT_IN_DATABASE : NULL;
         $result = ctools_export_crud_save('ldap_authorization', $values);
         ctools_export_load_object_reset('ldap_authorization');
         // ctools_export_crud_save doesn't invalidate cache
     } else {
         if ($op == 'edit') {
             $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
         } else {
             // insert
             $result = drupal_write_record('ldap_authorization', $values);
         }
         if ($result) {
             $this->inDatabase = TRUE;
         } else {
             drupal_set_message(t('Failed to write LDAP Authorization to the database.'));
         }
     }
     // revert mappings to array and remove temporary properties from ctools export
     $this->mappings = $this->pipeListToArray($values->mappings, FALSE);
     foreach (array('consumer_type', 'consumer_module', 'only_ldap_authenticated', 'use_filter', 'synch_to_ldap', 'synch_on_logon', 'revoke_ldap_provisioned', 'create_consumers', 'regrant_ldap_provisioned') as $prop_name) {
         unset($this->{$prop_name});
     }
 }
 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     ctools_include('export');
     $object = ctools_export_crud_load($this->getComponent(), $this->getIdentifier());
     if ($object) {
         ctools_export_crud_delete($this->getComponent(), $object);
     }
     $data = $this->getData();
     $data->export_type = NULL;
     panels_save_display($data->conf['display']);
     $data->conf['did'] = $data->conf['display']->did;
     unset($data->conf['display']);
     ctools_export_crud_save($this->getComponent(), $data);
     $settings->addInfo('imported', $this->getUniqueId());
 }
 /**
  * Called to save the final product from the edit form.
  */
 function edit_save_form($form_state)
 {
     $item =& $form_state['item'];
     $export_key = $this->plugin['export']['key'];
     $result = ctools_export_crud_save($this->plugin['schema'], $item);
     if ($result) {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
         drupal_set_message($message);
     } else {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['fail']);
         drupal_set_message($message, 'error');
     }
 }
/**
 * Form submission handler for facetapi_revert_form_submit().
 */
function current_search_delete_item_form_submit($form, &$form_state)
{
    $name = $form['#current_search']['name'];
    $item = $form['#current_search']['item'];
    // Removes item from the current search block configuration.
    if (isset($item->settings['items'][$name])) {
        $label = $item->settings['items'][$name]['label'];
        drupal_set_message(t('@label has been removed.', array('@label' => $label)));
        unset($item->settings['items'][$name]);
        ctools_export_crud_save('current_search', $item);
    }
    // Resirects back to current search block configuration page.
    $form_state['redirect'] = 'admin/config/search/current_search/list/' . $item->name . '/edit';
}
Пример #10
0
 /**
  * @param string enum $op 'add', 'update'
  */
 public function save($op)
 {
     $values = new stdClass();
     foreach ($this->field_to_properties_map() as $field_name => $property_name) {
         $field_name_lcase = drupal_strtolower($field_name);
         $values->{$field_name_lcase} = $this->{$property_name};
     }
     if (isset($this->bindpw) && $this->bindpw) {
         $values->bindpw = ldap_servers_encrypt($this->bindpw);
     }
     if ($this->bindpw_new) {
         $values->bindpw = ldap_servers_encrypt($this->bindpw_new);
     } elseif ($this->bindpw_clear) {
         $values->bindpw = NULL;
     }
     $values->tls = (int) $this->tls;
     $values->followrefs = (int) $this->followrefs;
     if (module_exists('ctools')) {
         ctools_include('export');
         // Populate our object with ctool's properties
         $object = ctools_export_crud_new('ldap_servers');
         foreach ($object as $property => $value) {
             $property_lcase = drupal_strtolower($property);
             if (!isset($values->{$property}) || !isset($values->{$property_lcase})) {
                 $values->{$property_lcase} = $value;
             }
         }
         try {
             $values->export_type = NULL;
             $result = ctools_export_crud_save('ldap_servers', $values);
         } catch (Exception $e) {
             $values->export_type = EXPORT_IN_DATABASE;
             $result = ctools_export_crud_save('ldap_servers', $values);
         }
         ctools_export_load_object_reset('ldap_servers');
         // ctools_export_crud_save doesn't invalidate cache
     } else {
         // directly via db
         unset($values->numeric_sid);
         if ($op == 'add') {
             $result = drupal_write_record('ldap_servers', $values);
         } else {
             $result = drupal_write_record('ldap_servers', $values, 'sid');
         }
         ldap_servers_cache_clear();
     }
     //  debug("values sent to save op=$op, ctools=". (int)module_exists('ctools')); debug($values);
     if ($result) {
         $this->inDatabase = TRUE;
     } else {
         drupal_set_message(t('Failed to write LDAP Server to the database.'));
     }
 }
Пример #11
0
 /**
  * Save an object in the database.
  *
  * @param ObjectInterface $object
  *   The object to save.
  */
 public static function save(ObjectInterface $object)
 {
     ctools_include('export');
     $configuration = $object->getConfiguration();
     $export = $object->getExport();
     ctools_export_crud_save($configuration['table'], $export);
 }
 /**
  * Submit callback for the bundle edit form.
  */
 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);
         if (!empty($panelizer_defaults)) {
             foreach ($panelizer_defaults as $panelizer) {
                 list($entity_type, $old_bundle, $name) = explode(':', $panelizer->name);
                 $panelizer->name = implode(':', array($entity_type, $new_bundle, $name));
                 if ($panelizer->view_mode != 'page_manager') {
                     $panelizer->name .= ':' . $panelizer->view_mode;
                 }
                 // The default display selection.
                 $old_variable_name = 'panelizer_' . $this->entity_type . ':' . $bundle . ':' . $panelizer->view_mode . '_selection';
                 $new_variable_name = 'panelizer_' . $this->entity_type . ':' . $new_bundle . ':' . $panelizer->view_mode . '_selection';
                 $default_layout = variable_get($old_variable_name, NULL);
                 if (!is_null($default_layout)) {
                     variable_set($new_variable_name, $default_layout);
                     variable_del($old_variable_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);
             }
         }
     }
     // Fix the configuration.
     // If the main configuration is disabled then everything gets disabled.
     if (empty($form_state['values']['panelizer']['status'])) {
         $form_state['values']['panelizer']['view modes'] = array();
     } elseif (!empty($form_state['values']['panelizer']['view modes'])) {
         // Make sure each setting is disabled if the view mode is disabled.
         foreach ($form_state['values']['panelizer']['view modes'] as $view_mode => &$config) {
             if (empty($config['status'])) {
                 foreach ($config as $key => $val) {
                     $config[$key] = 0;
                 }
             }
         }
     }
     // Save the default display for this bundle to a variable so that it may be
     // controlled separately.
     foreach ($this->get_default_panelizer_objects($new_bundle) as $panelizer) {
         if (!empty($form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['default display'])) {
             $new_value = $form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['default display'];
             $variable_name = 'panelizer_' . $this->entity_type . ':' . $new_bundle . ':' . $panelizer->view_mode . '_selection';
             variable_set($variable_name, $new_value);
             // Don't save the setting with the rest of the settings bundle.
             unset($form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['default display']);
         }
     }
     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']);
 }
Пример #13
0
 public function save($op)
 {
     $entry = $this;
     foreach ($this->field_to_properties_map() as $field_name => $property_name) {
         $entry->{$field_name} = $this->{$property_name};
     }
     if (isset($this->bindpw) && $this->bindpw) {
         $entry->bindpw = ldap_servers_encrypt($this->bindpw);
     }
     if ($this->bindpw_new) {
         $entry->bindpw = ldap_servers_encrypt($this->bindpw_new);
     } elseif ($this->bindpw_clear) {
         $entry->bindpw = NULL;
     }
     $entry->tls = (int) $entry->tls;
     $result = FALSE;
     if ($op == 'edit') {
         if (module_exists('ctools')) {
             ctools_include('export');
             $result = ctools_export_crud_save('ldap_servers', $entry);
         } else {
             $result = drupal_write_record('ldap_servers', $entry, 'sid');
         }
     } else {
         if (module_exists('ctools')) {
             ctools_include('export');
             // Populate our object with ctool's properties
             $object = ctools_export_crud_new('ldap_servers');
             foreach ($object as $property => $value) {
                 if (!isset($entry->{$property})) {
                     $entry->{$property} = $value;
                 }
             }
             $result = ctools_export_crud_save('ldap_servers', $entry);
         } else {
             $result = drupal_write_record('ldap_servers', $entry);
         }
     }
     if ($result) {
         $this->inDatabase = TRUE;
     } else {
         drupal_set_message(t('Failed to write LDAP Server to the database.'));
     }
 }
Пример #14
0
 public function save($op)
 {
     $entry = $this->entry();
     $result = FALSE;
     if ($op == 'edit') {
         if (module_exists('ctools')) {
             ctools_include('export');
             $result = ctools_export_crud_save('ldap_servers', $entry);
             ctools_export_load_object_reset('ldap_servers');
             // ctools_export_crud_save doesn't invalidate cache
         } else {
             $result = drupal_write_record('ldap_servers', $entry, 'sid');
         }
     } else {
         if (module_exists('ctools')) {
             ctools_include('export');
             // Populate our object with ctool's properties
             $object = ctools_export_crud_new('ldap_servers');
             foreach ($object as $property => $value) {
                 if (!isset($entry->{$property})) {
                     $entry->{$property} = $value;
                 }
             }
             $result = ctools_export_crud_save('ldap_servers', $entry);
             ctools_export_load_object_reset('ldap_servers');
             // ctools_export_crud_save doesn't invalidate cache
         } else {
             $result = drupal_write_record('ldap_servers', $entry);
         }
     }
     if ($result) {
         $this->inDatabase = TRUE;
     } else {
         drupal_set_message(t('Failed to write LDAP Server to the database.'));
     }
 }
 /**
  * Called to save the final product from the edit form.
  */
 function edit_save_form($form_state)
 {
     $item =& $form_state['item'];
     $export_key = $this->plugin['export']['key'];
     $operation_type = $form_state['op'];
     // if snippet is being added for the first time then make entry in snippet and snippet_revison
     // table to have complete information
     if ($operation_type == 'add') {
         $result = ctools_export_crud_save($this->plugin['schema'], $item);
         $result = _save_snippet($form_state['values']);
     } elseif ($operation_type == 'edit') {
         $result = _save_snippet($form_state['values']);
     }
     if ($result) {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
         drupal_set_message($message);
     } else {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['fail']);
         drupal_set_message($message, 'error');
     }
 }
 /**
  * Submit callback for the bundle edit form.
  */
 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);
         if (!empty($panelizer_defaults)) {
             foreach ($panelizer_defaults as $panelizer) {
                 list($entity_type, $old_bundle, $name) = explode(':', $panelizer->name);
                 $panelizer->name = implode(':', array($entity_type, $new_bundle, $name));
                 if ($panelizer->view_mode != 'page_manager') {
                     $panelizer->name .= ':' . $panelizer->view_mode;
                 }
                 // The default display selection.
                 $old_variable_name = 'panelizer_' . $this->entity_type . ':' . $bundle . ':' . $panelizer->view_mode . '_selection';
                 $new_variable_name = 'panelizer_' . $this->entity_type . ':' . $new_bundle . ':' . $panelizer->view_mode . '_selection';
                 $default_layout = variable_get($old_variable_name, NULL);
                 if (!is_null($default_layout)) {
                     variable_set($new_variable_name, $default_layout);
                     variable_del($old_variable_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);
             }
         }
     }
     // Fix the configuration.
     // If the main configuration is disabled then everything gets disabled.
     if (empty($form_state['values']['panelizer']['status'])) {
         $form_state['values']['panelizer']['view modes'] = array();
     } elseif (!empty($form_state['values']['panelizer']['view modes'])) {
         // Make sure each setting is disabled if the view mode is disabled.
         foreach ($form_state['values']['panelizer']['view modes'] as $view_mode => &$config) {
             if (empty($config['status'])) {
                 foreach ($config as $key => $val) {
                     $config[$key] = 0;
                 }
             }
         }
     }
     // Save the default display for this bundle to a variable so that it may be
     // controlled separately.
     foreach ($this->get_default_panelizer_objects($new_bundle) as $panelizer) {
         if (isset($form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['selection'])) {
             $variable_name = 'panelizer_' . $this->entity_type . ':' . $new_bundle . ':' . $panelizer->view_mode . '_selection';
             $old_value = variable_get($variable_name, NULL);
             $new_value = $form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['selection'];
             // Save the variable.
             variable_set($variable_name, $new_value);
             // Cleanup.
             // Additional cleanup if the default display was changed.
             if (!is_null($old_value) && $old_value != $new_value) {
                 // The user specifically requested that existing entities are to be
                 // updated to the new display.
                 if (!empty($form_state['values']['panelizer']['view modes'][$panelizer->view_mode]['default revert'])) {
                     $updated_count = db_update('panelizer_entity')->fields(array('name' => $new_value))->condition('name', $old_value)->execute();
                     drupal_set_message(t('@count @entity records were updated to the new Panelizer display for the @mode view mode.', array('@count' => $updated_count, '@entity' => $this->entity_type, '@mode' => $panelizer->view_mode)));
                     // If EntityCache is enabled, clear all records of this type. This
                     // is a little heavy-handed, but I don't believe there's an easy way
                     // to clear only entities of certain types without querying for them
                     // first, which could trigger an execution timeout.
                     if (module_exists('entitycache')) {
                         cache_clear_all('*', 'cache_entity_' . $this->entity_type, TRUE);
                     }
                 }
             }
         }
     }
     // Remove some settings that shouldn't be saved with the others.
     if (!empty($form_state['values']['panelizer']['view modes'])) {
         foreach ($form_state['values']['panelizer']['view modes'] as $view_mode => $settings) {
             unset($form_state['values']['panelizer']['view modes'][$view_mode]['selection']);
             unset($form_state['values']['panelizer']['view modes'][$view_mode]['default revert']);
         }
     }
     variable_set('panelizer_defaults_' . $this->entity_type . '_' . $new_bundle, $form_state['values']['panelizer']);
     // Verify the necessary Page Manager prerequisites are ready.
     if (!empty($form_state['values']['panelizer']['status']) && !empty($form_state['values']['panelizer']['view modes']['page_manager']['status']) && $this->is_page_manager_enabled()) {
         $this->check_page_manager_status();
     }
     // Unset this so that the type save forms don't try to save it to variables.
     unset($form_state['values']['panelizer']);
 }
 /**
  * Submit callback for the bundle edit form.
  */
 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));
             if ($panelizer->view_mode != 'page_manager') {
                 $panelizer->name .= ':' . $panelizer->view_mode;
             }
             $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']);
 }