You are here

function zenophile_create_submit in Zenophile 7

Same name and namespace in other branches
  1. 6.2 zenophile.module \zenophile_create_submit()
  2. 6 zenophile.module \zenophile_create_submit()

Submit function for zenophile_create().

File

./zenophile.module, line 264
Creates Zen subthemes quickly and easily.

Code

function zenophile_create_submit($form, &$form_state) {
  $zen_dir = drupal_get_path('theme', 'zen');
  $info = array(
    't_name' => $form_state['values']['sysname'],
    't_dir' => "sites/{$form_state['values']['site']}/themes/{$form_state['values']['sysname']}",
    'parent' => $form_state['values']['parent'],
    'parent_dir' => $form_state['values']['parent'] === 'STARTERKIT' ? $form_state['values']['zen_info']['vers_float'] >= 2 ? $zen_dir . '/STARTERKIT' : $zen_dir . '/../STARTERKIT' : drupal_get_path('theme', $form_state['values']['parent']),
    'zen_dir' => $zen_dir,
    'form_values' => $form_state['values'],
  );
  $cur_path = '';
  $file_list = _zenophile_populate_files($info['parent_dir'], $cur_path);
  $files = array();
  $weight = -10;
  foreach ($file_list as $file => $type) {
    $files[$file] = array(
      'from' => "{$info['parent_dir']}/{$file}",
      'type' => $type,
      'repl' => array(),
      'weight' => $weight += 10,
    );
  }

  // Call alter hooks.
  // We can't do module_invoke_all() because it doesn't pass $files by reference
  // to the hook implementations. We'll do it manually. (Thanks, catch in
  // #drupal!)
  foreach (module_implements('zenophile_alter') as $module) {
    $function = $module . '_zenophile_alter';
    if ($function($files, $info) === FALSE) {

      // One of the hook implementations wants to stop everything. It should
      // have shown an error with drupal_set_message. Return without processing
      // any files.
      return;
    }
  }

  // Process the $files array.
  if (_zenophile_process($files, $info['t_dir']) !== FALSE) {
    drupal_set_message(t('A new subtheme was successfully created in %dir.', array(
      '%dir' => $info['t_dir'],
    )));
  }

  // Do we want to switch to this new theme? Only try this if the theme was put
  // in the "all" directory or this site's directory.

  /*
    if ($form_state['values']['switch'] && ($form_state['values']['site'] === 'all' || conf_path() === 'sites/' . $form_state['values']['site'])) {
      $themes_fs = array(
        'values' => array(
          'op' => t('Save configuration'),
          'status' => array(
            // "Check the box" for the new theme
            $form_state['values']['sysname'] => TRUE,
          ),
          // Select the theme's "Default" radio button
          'theme_default' => $form_state['values']['sysname'],
        ),
      );
      // "Check the box" for current themes
      foreach (list_themes() as $theme) {
        if ($theme->status) {
          $themes_fs['values']['status'][$theme->name] = TRUE;
        }
      }

      // …and "submit" the themes form.
      // But first, load the .inc file the theme form is buried in.
      module_load_include('inc', 'system', 'system.admin');
      drupal_form_submit('system_themes_form', $themes_fs);
    }
    else {
  */

  // Flush the cached theme data so the new subtheme appears in the parent
  // theme list.
  system_rebuild_theme_data();

  /*   } */
}