You are here

function module_builder_page_validate in Module Builder 5

Makes sure that valid values have been provided to the Module Builder.

Related topics

File

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

Code

function module_builder_page_validate($form_id, $form_values) {
  if ($form_values['op'] == 'input') {

    // Ensure module_root_name was entered, and check for special characters
    if (!empty($form_values['module_root_name'])) {
      if (!preg_match(MODULE_BUILDER_FUNCTION_PATTERN, $form_values['module_root_name'])) {
        form_set_error('module_root_name', t('The module root name must only contain letters, numbers, and underscores, and may not start with a number.'));
      }
    }

    // Make sure at least one hook was chosen
    $hook_selected = false;
    foreach ($form_values['hooks'] as $file => $hooks) {
      foreach ($hooks as $hook) {
        if ($hook == 1) {
          $hook_selected = true;
          break;
        }
      }
      if ($hook_selected) {
        break;
      }
    }
    if (!$hook_selected) {
      form_set_error('hooks', t('You must select at least one hook.'));
    }
  }
}