You are here

common_version.inc in Module Builder 7

Same filename and directory in other branches
  1. 6.2 includes/common_version.inc

common_version.inc Stuff needed both by module and drush command. Functions that need to differ for versions of Drupal. This file is the default fallback, and covers Drupal 5 and 6.

File

includes/common_version.inc
View source
<?php

/**
 * @file common_version.inc
 *   Stuff needed both by module and drush command.
 *   Functions that need to differ for versions of Drupal.
 *   This file is the default fallback, and covers Drupal 5 and 6.
 */

/**
 * Run through Drupal's directory creation and checking stuff, 
 * adding a version subfolder for common directories.
 *
 * @param $directory
 *  A directory path. Should be either absolute or relative; the latter will
 *  be taken to mean it's inside the Drupal /files directory.
 * @param $common
 *  Boolean to indicate whether this directory is common across several 
 *  Drupal installations. If set, the actual directory used will be a
 *  subdirectory with a version number: eg path/to/dir/6
 */
function module_builder_create_directory(&$directory, $common = FALSE) {
  if (substr($directory, 0, 1) == '/') {

    // absolute path

    //print 'starts with /';
  }
  else {

    // Relative, and so assumed to be in Drupal's files folder.
    // sanity check. need to verify /files exists before we do anything. see http://drupal.org/node/367138
    $files = file_create_path();
    file_check_directory($files, FILE_CREATE_DIRECTORY);
    $directory = file_create_path($directory);
  }

  // Note that recursive stuff won't work here!
  // You really should make sure the dir exists yourself.
  file_check_directory($directory, FILE_CREATE_DIRECTORY);

  // If the directory is common, append the version number subdir.
  if ($common) {

    // $directory has no trailing / at this point: file_check_directory removes it.
    $directory = $directory . '/' . _module_builder_drupal_major_version();
    file_check_directory($directory, FILE_CREATE_DIRECTORY);
  }
}

/**
 * A version-independent wrapper for drupal_system_listing().
 */
function module_builder_system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
  return drupal_system_listing($mask, $directory, $key, $min_depth);
}

Functions

Namesort descending Description
module_builder_create_directory Run through Drupal's directory creation and checking stuff, adding a version subfolder for common directories.
module_builder_system_listing A version-independent wrapper for drupal_system_listing().