You are here

class ModuleBuilderGeneratorCode in Module Builder 6.2

Generator class for module code files.

Hierarchy

Expanded class hierarchy of ModuleBuilderGeneratorCode

File

includes/generate.inc, line 106
Module builder code generating code.

View source
class ModuleBuilderGeneratorCode extends ModuleBuilderGenerator {
  function __construct($module_data) {
    $this->module_data = $module_data;
  }
  function code_body() {

    // Get old style variable names.
    $module_data = $this->module_data;
    $hook_data = $this->hook_data;
    $code = '';
    foreach ($hook_data as $hook_name => $hook) {

      // Display PHP doc.
      $code .= "\n" . module_builder_code_hook_doxy($hook_name);

      // function declaration: put in the module name, add closing brace, decode html entities
      $declaration = str_replace('hook', $module_data['module_root_name'], $hook['declaration']) . ' {';
      $code .= htmlspecialchars_decode($declaration);

      // See if function bodies exist; if so, use function bodies from template
      if (isset($hook['template'])) {

        // Strip out INFO: comments for advanced users
        if (!variable_get('module_builder_detail', 0)) {

          // Used to strip INFO messages out of generated file for advanced users.
          $pattern = '#\\s+/\\* INFO:(.*?)\\*/#ms';
          $hook['template'] = preg_replace($pattern, '', $hook['template']);
        }

        //dsm($hook);
        $code .= $hook['template'];
      }
      else {
        $code .= "\n\n";
      }
      $code .= "}\n\n";
    }

    // foreach hook
    // Replace variables
    $variables = array(
      '%module' => $module_data['module_root_name'],
      '%description' => str_replace("'", "\\'", $module_data['module_short_description']),
      '%name' => !empty($module_data['module_readable_name']) ? str_replace("'", "\\'", $module_data['module_readable_name']) : $module_data['module_root_name'],
      '%help' => !empty($module_data['module_help_text']) ? str_replace('"', '\\"', $module_data['module_help_text']) : t('TODO: Create admin help text.'),
      '%readable' => str_replace("'", "\\'", $module_data['module_readable_name']),
    );
    $code = strtr($code, $variables);
    return $code;
  }

  /**
   * Return a file footer.
   */
  function code_footer() {
    $footer = variable_get('module_builder_footer', '');
    return $footer;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ModuleBuilderGenerator::build function The main code building function.
ModuleBuilderGenerator::code_header function Return the file doxygen header and any custom header code. 1
ModuleBuilderGenerator::file_header function Return the PHP file header line. 1
ModuleBuilderGeneratorCode::code_body function Return the main body of the file code. Overrides ModuleBuilderGenerator::code_body
ModuleBuilderGeneratorCode::code_footer function Return a file footer. Overrides ModuleBuilderGenerator::code_footer
ModuleBuilderGeneratorCode::__construct function Overrides ModuleBuilderGenerator::__construct