You are here

function devel_generate_content_form in Devel 7

Same name and namespace in other branches
  1. 5 devel_generate.module \devel_generate_content_form()
  2. 6 devel_generate.module \devel_generate_content_form()

Generates nodes using FormAPI.

1 string reference to 'devel_generate_content_form'
devel_generate_menu in devel_generate/devel_generate.module
Implements hook_menu().

File

devel_generate/devel_generate.module, line 114

Code

function devel_generate_content_form() {
  $options = array();
  if (module_exists('content')) {
    $types = content_types();
    foreach ($types as $type) {
      $warn = '';
      if (count($type['fields'])) {
        $warn = t('. This type contains CCK fields which will only be populated by fields that implement the content_generate hook.');
      }
      $options[$type['type']] = t($type['name']) . $warn;
    }
  }
  else {
    $types = node_type_get_types();
    foreach ($types as $type) {
      $options[$type->type] = array(
        'type' => t($type->name),
      );
      if (module_exists('comment')) {
        $default = variable_get('comment_' . $type->type, COMMENT_NODE_OPEN);
        $map = array(
          t('Hidden'),
          t('Closed'),
          t('Open'),
        );
        $options[$type->type]['comments'] = '<small>' . $map[$default] . '</small>';
      }
    }
  }

  // we cannot currently generate valid polls.
  unset($options['poll']);
  if (empty($options)) {
    drupal_set_message(t('You do not have any content types that can be generated. <a href="@create-type">Go create a new content type</a> already!</a>', array(
      '@create-type' => url('admin/structure/types/add'),
    )), 'error', FALSE);
    return;
  }
  $header = array(
    'type' => t('Content type'),
  );
  if (module_exists('comment')) {
    $header['comments'] = t('Comments');
  }
  $form['node_types'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#required' => TRUE,
  );
  if (module_exists('checkall')) {
    $form['node_types']['#checkall'] = TRUE;
  }
  $form['kill_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Delete all content</strong> in these content types before generating new content.'),
    '#default_value' => FALSE,
  );
  $form['num_nodes'] = array(
    '#type' => 'textfield',
    '#title' => t('How many nodes would you like to generate?'),
    '#default_value' => 50,
    '#size' => 10,
  );
  $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 nodes be dated?'),
    '#description' => t('Node creation dates will be distributed randomly from the current time, back to the selected time.'),
    '#options' => $options,
    '#default_value' => 604800,
  );
  $form['max_comments'] = array(
    '#type' => module_exists('comment') ? 'textfield' : 'value',
    '#title' => t('Maximum number of comments per node.'),
    '#description' => t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'),
    '#default_value' => 0,
    '#size' => 3,
    '#access' => module_exists('comment'),
  );
  $form['title_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum number of words in titles'),
    '#default_value' => 4,
    '#size' => 10,
  );
  $form['add_alias'] = array(
    '#type' => 'checkbox',
    '#disabled' => !module_exists('path'),
    '#description' => t('Requires path.module'),
    '#title' => t('Add an url alias for each node.'),
    '#default_value' => FALSE,
  );
  $form['add_statistics'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add statistics for each node (node_counter table).'),
    '#default_value' => TRUE,
    '#access' => module_exists('statistics'),
  );
  unset($options);
  $options[LANGUAGE_NONE] = t('Language neutral');
  if (module_exists('locale')) {
    $options += locale_language_list();
  }
  $form['add_language'] = array(
    '#type' => 'select',
    '#title' => t('Set language on nodes'),
    '#multiple' => TRUE,
    '#disabled' => !module_exists('locale'),
    '#description' => t('Requires locale.module'),
    '#options' => $options,
    '#default_value' => array(
      LANGUAGE_NONE,
    ),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Generate'),
  );
  $form['#redirect'] = FALSE;
  return $form;
}