When submitting the form found at 'admin/build/subsites/1/content/pages' the current CSS of the subsite is deleted.

I used the following code to resolve the problem:

Change

function subsites_content_pages_form_submit($form, &$form_state) {
  $old_subsite = subsites_get($form_state['values']['sid']);
  subsites_edit($form_state['values']['sid'], $old_subsite->name, $form_state['values']['pages'], $form_state['values']['visibility'], $old_subsite->css, $old_subsite->theme, $old_subsite->weight, $old_subsite->status, $old_subsite->header, $old_subsite->headerlink);

  $form_state['redirect'] = 'admin/build/subsites/'. $form_state['values']['sid'] .'/content/pages';

  drupal_set_message(t('subsites configuration changes saved.'));
}

To:

function subsites_content_pages_form_submit($form, &$form_state) {
  $old_subsite = subsites_get($form_state['values']['sid']);
  subsites_edit($form_state['values']['sid'], $old_subsite->name, $form_state['values']['pages'], $form_state['values']['visibility'], NULL, $old_subsite->theme, $old_subsite->weight, $old_subsite->status, $old_subsite->header, $old_subsite->headerlink);

  $form_state['redirect'] = 'admin/build/subsites/'. $form_state['values']['sid'] .'/content/pages';

  drupal_set_message(t('subsites configuration changes saved.'));
}

and change:

function subsites_edit($sid, $name, $pages, $visibility, $css, $theme, $weight, $status, $header, $headerlink) {
  // update db
  db_query("UPDATE {subsites} SET name = '%s', pages = '%s', visibility = %d, theme = '%s', weight = %d, status = %d, header = '%s', headerlink = '%s' WHERE sid = %d", $name, $pages, $visibility, $theme, $weight, $status, $header, $headerlink, $sid);

  // update menu item weight
  db_query("UPDATE {menu_links} SET weight = %d WHERE link_path = '%s'", $weight, 'admin/build/subsites/'. $sid);

  // save css

	  file_check_directory(file_create_path('subsites'), FILE_CREATE_DIRECTORY);
	  file_check_directory(file_create_path('subsites/'. $sid), FILE_CREATE_DIRECTORY);
	  file_save_data($css, subsites_get_css_path($sid), FILE_EXISTS_REPLACE);

}

to

function subsites_edit($sid, $name, $pages, $visibility, $css, $theme, $weight, $status, $header, $headerlink) {
  // update db
  db_query("UPDATE {subsites} SET name = '%s', pages = '%s', visibility = %d, theme = '%s', weight = %d, status = %d, header = '%s', headerlink = '%s' WHERE sid = %d", $name, $pages, $visibility, $theme, $weight, $status, $header, $headerlink, $sid);

  // update menu item weight
  db_query("UPDATE {menu_links} SET weight = %d WHERE link_path = '%s'", $weight, 'admin/build/subsites/'. $sid);

  // save css
  if($css != NULL):
	  file_check_directory(file_create_path('subsites'), FILE_CREATE_DIRECTORY);
	  file_check_directory(file_create_path('subsites/'. $sid), FILE_CREATE_DIRECTORY);
	  file_save_data($css, subsites_get_css_path($sid), FILE_EXISTS_REPLACE);
  endif;
}

Comments

chunty’s picture

Version: 6.x-1.4 » 6.x-1.x-dev

Running this update bust my site as the subsites table did not have either the "header" or a "headerlink" column so I had to use:

<?php
function subsites_edit($sid, $name, $pages, $visibility, $css, $theme, $weight, $status, $header, $headerlink) {
  // update db
  db_query("UPDATE {subsites} SET name = '%s', pages = '%s', visibility = %d, theme = '%s', weight = %d, status = %d WHERE sid = %d", $name, $pages, $visibility, $theme, $weight, $status, $sid);

  // update menu item weight
  db_query("UPDATE {menu_links} SET weight = %d WHERE link_path = '%s'", $weight, 'admin/build/subsites/'. $sid);

  // save css
  if($css != NULL):
	  file_check_directory(file_create_path('subsites'), FILE_CREATE_DIRECTORY);
	  file_check_directory(file_create_path('subsites/'. $sid), FILE_CREATE_DIRECTORY);
	  file_save_data($css, subsites_get_css_path($sid), FILE_EXISTS_REPLACE);
  endif;
}
?>

Not sure if this down to a version issue or something but I am running 6.x-1.x-dev

gisle’s picture

Status: Patch (to be ported) » Needs review

This suggestion (it is not even a patch) has never been properly reviewed by the community. Changing status.