You are here

function zenophile_zenophile_alter in Zenophile 6.2

Same name and namespace in other branches
  1. 7 zenophile.module \zenophile_zenophile_alter()

Implementation of hook_zenophile_alter().

This is our own implementation of hook_zenophile_alter(). This one should fire first because we're setting the module's weight in the {system} table to -10 in hook_install(). Otherwise, this implementation would probably fire last due to the name of this module, which places it near the end of any alphabetical ordering.

File

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

Code

function zenophile_zenophile_alter(&$files, $info) {
  $weight = 59990;

  // Step 2: Rename the .info file, and replace instances of the parent name
  // that of the child name. Also, add the name and description.
  // Make an exception for STARTERKIT again… dammit.
  $dotinfo = $info['t_name'] . '.info';
  $files[$dotinfo] = $files[$info['parent'] . ($info['parent'] === 'STARTERKIT' ? '.info.txt' : '.info')];
  $files[$dotinfo]['repl'] = array();
  $files[$dotinfo]['repl']["/{$info['parent']}/"] = $info['t_name'];
  $files[$dotinfo]['repl']['/^name\\s*=.*/m'] = 'name        = ' . $info['form_values']['friendly'];
  $files[$dotinfo]['repl']['/^description\\s*=.*/m'] = 'description = ' . $info['form_values']['description'];

  // Remove packaging robot stuff
  $files[$dotinfo]['repl']['/^; Information added by drupal\\.org packaging script on .+$/m'] = '';
  $files[$dotinfo]['repl']['/^(version|core|project|datestamp) = ".+$/m'] = '';
  if ($info['parent'] === 'STARTERKIT') {
    unset($files['STARTERKIT.info.txt']);
  }
  else {
    unset($files[$info['parent'] . '.info']);
  }

  // Do we also want to create the the fresh stylesheet?
  if ($info['form_values']['fresh']) {
    $fresh_name = $info['form_values']['zen_info']['vers_float'] < 2 ? $info['t_name'] . '-fresh.css' : 'css/fresh.css';
    $files[$fresh_name] = array(
      'from' => '',
      'type' => 'file',
      'repl' => array(),
      'weight' => $weight += 10,
    );

    // Add it to the .info file
    $files[$dotinfo]['repl']['/^  ; Set the conditional stylesheets that are processed by IE\\.$/m'] = "\n  ; Adding a nice clean stylesheet\nstylesheets[all][] = {$fresh_name}\n\n  ; Set the conditional stylesheets that are processed by IE.\n";
  }

  // Copy the liquid or fixed stylesheet, zen.css, print.css and
  // html-elements.css from the actual Zen theme (not the parent theme). Steps 3
  // through 6. Only do this if the parent is STARTERKIT - otherwise these
  // should already be in the subtheme directory, and therefore already in the
  // $files array.
  if ($info['parent'] === 'STARTERKIT') {
    if ($info['form_values']['zen_info']['vers_float'] < 2) {
      $files['layout.css'] = array(
        'from' => $info['zen_dir'] . "/layout-{$info['form_values']['layout']}.css",
        'type' => 'file',
        'repl' => array(),
        'weight' => $weight += 10,
      );
      $files['print.css'] = array(
        'from' => $info['zen_dir'] . '/print.css',
        'type' => 'file',
        'repl' => array(),
        'weight' => $weight += 10,
      );
      $files['html-elements.css'] = array(
        'from' => $info['zen_dir'] . '/html-elements.css',
        'type' => 'file',
        'repl' => array(),
        'weight' => $weight += 10,
      );
    }
    else {

      // For version 2, there's less we have to do.
      if ($info['form_values']['layout'] === 'fixed') {
        unset($files['css/layout-liquid.css']);
        unset($files['css/layout-liquid-rtl.css']);
      }
      else {
        unset($files['css/layout-fixed.css']);
        unset($files['css/layout-fixed-rtl.css']);
        $files[$dotinfo]['repl']['~css/layout-fixed~'] = 'css/layout-liquid';
      }
    }
  }
  if ($info['form_values']['zen_info']['vers_float'] < 2) {

    // If there is a starter_theme.css file in the directory already,
    // rename it to this_theme.css. Otherwise, copy over zen.css and
    // rename it.
    $parent_css = "{$info['parent_dir']}/{$info['parent']}.css";
    $files[$info['t_name'] . '.css'] = array(
      'from' => file_exists($parent_css) ? $parent_css : $info['zen_dir'] . '/zen.css',
      'type' => 'file',
      'repl' => array(),
      'weight' => $weight += 10,
    );
  }

  // Copy template.php and theme-settings.php and replace the parent theme's
  // name. Kind of Step 1 plus Step 7 mixed together. The files should already
  // be there in $files, so we'll just tweak their repl arrays.
  $files['template.php']['repl']["/{$info['parent']}/"] = $info['t_name'];
  $files['theme-settings.php']['repl']["/{$info['parent']}/"] = $info['t_name'];
}