You are here

function drush_devel_generate_menus in Devel 7

Command callback. Generate a number of menus and menu links.

1 string reference to 'drush_devel_generate_menus'
devel_generate_drush_command in devel_generate/devel_generate.drush.inc
Implementation of hook_drush_command().

File

devel_generate/devel_generate.drush.inc, line 185
Generate content, taxonomy, menu, and users via drush framework.

Code

function drush_devel_generate_menus($number_menus = 2, $number_links = 50, $max_depth = 3, $max_width = 8) {
  if (drush_generate_is_number($number_menus) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of menus'));
  }
  if (drush_generate_is_number($number_links) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of links'));
  }
  if (drush_generate_is_number($max_depth) == FALSE || $max_depth > 9 || $max_depth < 1) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid maximum link depth. Use a value between 1 and 9'));
  }
  if (drush_generate_is_number($max_width) == FALSE || $max_width < 1) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid maximum menu width. Use a positive numeric value.'));
  }
  global $user;
  $user_one = user_load(1);
  $user = $user_one;
  drupal_save_session(FALSE);
  drush_generate_include_devel();

  // Delete custom menus.
  if (drush_get_option('kill')) {
    devel_generate_delete_menus();
    drush_log(dt('Deleted existing menus and links.'), 'success');
  }

  // Generate new menus.
  $new_menus = devel_generate_menus($number_menus, '12');
  if (!empty($new_menus)) {
    drush_log(dt("Created the following new menus:\n!menus", array(
      '!menus' => implode("\n", $new_menus),
    )), 'success');
  }

  // Generate new menu links.
  $link_types = drupal_map_assoc(array(
    'node',
    'front',
    'external',
  ));
  $new_links = devel_generate_links($number_links, $new_menus, '12', $link_types, $max_depth, $max_width);
  drush_log(dt('Created !count new menu links.', array(
    '!count' => count($new_links),
  )), 'success');
}