You are here

module_builder.module in Module Builder 7.2

Builds scaffolding for custom modules.

File

module_builder.module
View source
<?php

/**
 * @file
 * Builds scaffolding for custom modules.
 */

/**
 * Implements hook_libraries_info().
 */
function module_builder_libraries_info() {
  $libraries['drupal-code-builder'] = array(
    'name' => 'Drupal Code Builder',
    'vendor url' => 'https://github.com/drupal-code-builder/drupal-code-builder',
    'download url' => 'https://github.com/drupal-code-builder/drupal-code-builder/archive/3.2.x.zip',
    'version' => 'none',
    'files' => array(
      'php' => array(
        'Factory.php',
      ),
    ),
    // Auto-load the files.
    'integration files' => array(
      'module_builder' => array(
        'php' => array(
          'Factory.php',
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * @defgroup module_builder_core Core Drupal hooks
 */

/**
 * Helper to load and initialize the Drupal Code Builder library.
 */
function module_builder_init_library() {
  libraries_load('drupal-code-builder');
  \DrupalCodeBuilder\Factory::setEnvironmentLocalClass('DrupalLibrariesAPI')
    ->setCoreVersionNumber(VERSION);
}

/**
 * Implementation of hook_help().
 */
function module_builder_help($path, $arg) {
  switch ($path) {
    case 'admin/help#module_builder':
      return t("Module builder allows you to generate code files for new custom modules.");
    case 'admin/modules/module_builder':
      return t('This page allows you to generate the files for a custom module with scaffolding code for hook implementations.');
  }
}

/**
 * Implementation of hook_permission().
 *
 * @ingroup module_builder_core
 */
function module_builder_permission() {
  return array(
    'access module builder' => array(
      'title' => t('Access module builder'),
    ),
  );
}

/**
 * Implementation of hook_menu().
 *
 * @ingroup module_builder_core
 */
function module_builder_menu() {
  $items['admin/modules/module_builder'] = array(
    'title' => 'Module builder',
    'description' => t('Builds scaffolding for custom modules.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'module_builder_page',
    ),
    'file' => 'includes/module_builder.pages.inc',
    'access arguments' => array(
      'access module builder',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => '50',
  );
  $items['admin/config/development/module_builder'] = array(
    'title' => 'Module builder',
    'description' => t('Set default header and footer, api download location, defaults for detail and download and force the api to be re-downloaded.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'module_builder_admin_settings',
    ),
    'file' => 'includes/module_builder.admin.inc',
    'access arguments' => array(
      'access module builder',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/config/development/module_builder/settings'] = array(
    'title' => 'Settings',
    'description' => t('Set default header and footer, folder locations, and defaults for detail.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'module_builder_admin_settings',
    ),
    'file' => 'includes/module_builder.admin.inc',
    'access arguments' => array(
      'access module builder',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/config/development/module_builder/update'] = array(
    'title' => 'Update hooks',
    'description' => t('Download hook documentation.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'module_builder_admin_update',
    ),
    'file' => 'includes/module_builder.admin.inc',
    'access arguments' => array(
      'access module builder',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Implementation of hook_theme.
 */
function module_builder_theme($existing, $type, $theme, $path) {
  return array(
    'module_builder_hook_list' => array(
      'render element' => 'form',
    ),
  );
}

############################# old code below here

/**
 * This still needs some work. Set a bunch of check boxes, forward, back, uncheck
 * the boxes, forward and back and the boxes get turned back on for some reason.
 * Otherwise this seems pretty good.
 */
function _module_builder_save_old_form_values($form, $form_values, $indent = '') {
  static $excludes;
  if (!isset($excludes)) {
    $excludes = array(
      'op',
      'form_build_id',
      'form_token',
      'form_id',
      'generate_module',
      'module_code',
      'module_info',
    );
  }
  if (isset($form['#multistep_excludes']) && is_array($form['#multistep_excludes'])) {
    $excludes = array_merge($excludes, $form['#multistep_excludes']);
  }
  if (isset($form_values)) {
    foreach ($form_values as $key => $value) {

      //print_r($indent . $key .' => '. $value ."\n");
      $include = !in_array($key, $excludes);
      if ($include) {
        if (is_array($value)) {
          if (!isset($form[$key])) {
            $form[$key] = array();
          }
          $form[$key] = _module_builder_save_old_form_values($form[$key], $value, $indent . '    ');
          $form[$key]['#tree'] = TRUE;
        }
        else {
          if (isset($form[$key])) {
            $form[$key]['#value'] = $value;
          }
          else {
            $form[$key] = array(
              '#type' => 'hidden',
              '#value' => $value,
            );
          }
        }
      }
    }
  }
  return $form;
}

Functions

Namesort descending Description
module_builder_help Implementation of hook_help().
module_builder_init_library Helper to load and initialize the Drupal Code Builder library.
module_builder_libraries_info Implements hook_libraries_info().
module_builder_menu Implementation of hook_menu().
module_builder_permission Implementation of hook_permission().
module_builder_theme Implementation of hook_theme.
_module_builder_save_old_form_values This still needs some work. Set a bunch of check boxes, forward, back, uncheck the boxes, forward and back and the boxes get turned back on for some reason. Otherwise this seems pretty good.