function privatemsg_devel_generate_form

7-2 privatemsg.devel_generate.inc privatemsg_devel_generate_form()
6-2 privatemsg.devel_generate.inc privatemsg_devel_generate_form()

Form Builder; Integrates with Devel Generate.

See also

privatemsg_devel_generate_form_validate()

privatemsg_devel_generate_form_submit()

1 string reference to 'privatemsg_devel_generate_form'
privatemsg_menu in ./privatemsg.module
Implements hook_menu().

File

./privatemsg.devel_generate.inc, line 9

Code

function privatemsg_devel_generate_form() {

  // Check if authenticated users can write new messages.
  $perm = 'write privatemsg';
  $role_perms = user_role_permissions(array(DRUPAL_AUTHENTICATED_RID => 'authenticated user'));
  $perms = $role_perms[DRUPAL_AUTHENTICATED_RID];

  if (!in_array($perm, $perms)) {
    drupal_set_message(t('Authenticated users do not have %perm permission. This function will not run correctly. <a href="@url">Permissions page</a>.', array('%perm' => $perm, '@url' => url('admin/people/permissions', array('fragment' => 'module-privatemsg', 'query' => array('destination' => 'admin/generate/privatemsg'))))), 'warning');
  }

  $options = array();
  for ($i = 1; $i <= 10; $i++) {
    $options[$i] = $i;
  }

  $form['kill_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Delete all messages</strong> before generating new messages.'),
    '#default_value' => FALSE,
  );
  $form['num_threads'] = array(
    '#type' => 'textfield',
    '#title' => t('How many threads would you like to generate?'),
    '#default_value' => 10,
    '#size' => 10,
  );
  $form['max_thread_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Max thread length?'),
    '#default_value' => 5,
    '#size' => 10,
  );
  $form['recipients'] = array(
    '#type' => 'fieldset',
    '#title' => t('Recipients'),
    '#description' => t('A random number of recipients will be generated for each message.'),
  );
  $form['recipients']['min_recipients'] = array(
    '#type' => 'select',
    '#title' => t('Minimum number of recipients for each message'),
    '#default_value' => 1,
    '#options' => $options,
  );
  $form['recipients']['max_recipients'] = array(
    '#type' => 'select',
    '#title' => t('Maximum number of recipients for each message'),
    '#default_value' => 3,
    '#options' => $options,
  );

  $options = array(1 => t('Now'));
  foreach (array(
    3600,
    86400,
    604800,
    2592000,
    31536000,
  ) as $interval) {
    $options[$interval] = format_interval($interval, 1) . ' ' . t('ago');
  }
  $form['time_range'] = array(
    '#type' => 'select',
    '#title' => t('How far back in time should the messages be dated?'),
    '#description' => t('Message creation dates will be distributed randomly from the current time, back to the selected time.'),
    '#options' => $options,
    '#default_value' => 604800,
  );

  $form['subject_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Max word length of subjects'),
    '#default_value' => 8,
    '#size' => 10,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Generate'),
  );
  $form['#redirect'] = FALSE;

  return $form;
}