You are here

function module_builder_page_generate in Module Builder 7.2

Same name and namespace in other branches
  1. 6.2 includes/module_builder.pages.inc \module_builder_page_generate()
  2. 7 includes/module_builder.pages.inc \module_builder_page_generate()

Form builder for page 2: generate code.

1 string reference to 'module_builder_page_generate'
module_builder_page in includes/module_builder.pages.inc
Displays module builder interface via a multi-step form. The steps are:

File

includes/module_builder.pages.inc, line 255
Menu callback for main module builder page.

Code

function module_builder_page_generate($form, &$form_state) {
  module_load_include('inc', 'module_builder', 'includes/module_builder.form');
  $mb_task_handler_generate = \DrupalCodeBuilder\Factory::getTask('Generate', 'module');
  $form_helper = new ModuleBuilderComponentFormBase($mb_task_handler_generate);
  $form_state_object = new FormState($form_state);
  $module_data = $form_helper
    ->copyFormValuesToEntity($form, $form_state_object);

  // Ungroup the hooks value.
  $hooks = [];
  foreach ($form_state['values']['data']['hooks'] as $group_values) {

    // Filter out empty values. (FormAPI *still* doesn't do this???)
    $group_hooks = array_filter($group_values);

    // Store as a numeric array.
    $group_hooks = array_keys($group_hooks);
    $hooks = array_merge($group_hooks, $hooks);
  }
  $module_data['hooks'] = $hooks;

  // Presets get expanded with JS.
  unset($module_data['module_hook_presets']);

  // Get the files.
  $files = $mb_task_handler_generate
    ->generateComponent($module_data);

  //dsm($files);

  /*
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('Back'),
    '#name' => 'back',
  );
  */
  foreach ($files as $filename => $code) {
    $form['code_instructions_' . $filename] = array(
      '#markup' => t('Please copy and paste the following text into a file called !module.', array(
        '!module' => $filename,
      )),
      '#prefix' => '<div class="module-message">',
      '#suffix' => '</div>',
    );
    $form['module_code_' . $filename] = array(
      '#type' => 'textarea',
      '#title' => t($filename . ' code'),
      '#rows' => count(explode("\n", $code)),
      '#default_value' => $code,
      '#prefix' => '<div class="module-code">',
      '#suffix' => '</div>',
    );
  }

  /*
  $form['code_instructions'] = array(
    '#value' => t('Please copy and paste the following text into a file called !module.', array('!module' => $form_state['values']['root_name'] .'.module')),
    '#prefix' => '<div id="module-message">',
    '#suffix' => '</div>',
  );
  $form['module_code'] = array(
    '#type' => 'textarea',
    '#title' => t('Module code'),
    '#rows' => 20,
    '#default_value' => $code,
    '#prefix' => '<div id="module-code">',
    '#suffix' => '</div>',
  );
  */

  /*
  $form['download_module'] = array(
    '#type' => 'submit',
    '#value' => t('Download module'),
  );
  $form['write_module'] = array(
    '#type' => 'button',
    '#value' => t('Write module file'),
  );
  */

  /*
  $form['download_info'] = array(
    '#type' => 'submit',
    '#name' => 'op',
    '#value' => t('Download info file'),
  );
  $form['write_info'] = array(
    '#type' => 'button',
    '#value' => t('Write info file'),
  );
  */

  // handle the write buttons

  ## $form['#after_build'] = array('module_builder_write_buttons');
  return $form;
}