You are here

function _module_builder_write_file in Module Builder 6.2

Same name and namespace in other branches
  1. 5 module_builder.module \_module_builder_write_file()
  2. 7 module_builder.module \_module_builder_write_file()

Helper function to write files saves moving this code while mucking about with different formsAPI approaches & quicker to shortcircuit

2 calls to _module_builder_write_file()
Xmodule_builder_page_write in ./module_builder.module
Module form: 'write' step
Xmodule_builder_write_buttons in ./module_builder.module
Form after build callback. If update button was clicked, update hooks documentation. Rest of form is not submitted. Cribbed from node_form_add_preview()

File

./module_builder.module, line 475
Builds scaffolding for custom modules.

Code

function _module_builder_write_file($basename, $extension, $content) {
  if (strlen($content) == 0) {
    return;
  }
  $directory = file_create_path(variable_get('module_builder_module_write_directory', 'modules') . '/' . $basename);
  file_check_directory($directory, FILE_CREATE_DIRECTORY);
  $file_name = $basename . $extension;
  $created_file = file_save_data($content, "{$directory}/{$file_name}", FILE_EXISTS_REPLACE);
  if ($created_file) {
    drupal_set_message(t("File @file has been written.", array(
      '@file' => $created_file,
    )));
  }
  else {
    drupal_set_message(t("There was a problem writing the file @file.", array(
      '@file' => "{$directory}/{$file_name}",
    )), 'error');
  }
}