summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormoshe weitzman2010-04-03 23:45:08 (GMT)
committer moshe weitzman2010-04-03 23:45:08 (GMT)
commit6676ec1a1bd23f7f530e785b241fd65349835570 (patch)
tree3a38b25bc64a57101060a9c11505259c45f61776
parent66aa60eff80ffb379e425f6df5f26fe9108eaa0a (diff)
#282010 by naxoc. Allow languages to be assigned to generated nodes
-rw-r--r--devel_generate.drush.inc13
-rw-r--r--devel_generate.inc4
-rw-r--r--devel_generate.module10
3 files changed, 25 insertions, 2 deletions
diff --git a/devel_generate.drush.inc b/devel_generate.drush.inc
index 42977a9..4f4f575 100644
--- a/devel_generate.drush.inc
+++ b/devel_generate.drush.inc
@@ -45,7 +45,7 @@ function devel_generate_drush_command() {
),
'aliases' => array('gent'),
);
- $items['generate content'] = array(
+ $items['generate-content'] = array(
'description' => 'Creates content.',
'drupal dependencies' => array('devel_generate'),
'arguments' => array(
@@ -56,6 +56,7 @@ function devel_generate_drush_command() {
'kill' => 'Delete all content before generating new content.',
'add-terms' => 'Add terms to generated nodes.',
'add-upload' => 'Add an attached file to generated nodes.',
+ 'languages' => 'A comma-separated list of language codes',
),
'aliases' => array('genc'),
);
@@ -92,7 +93,7 @@ function drush_devel_generate_generate_taxonomy($num_vocab = NULL, $num_terms =
/**
* Command callback. Generate a number of content.
*/
-function drush_devel_generate_generate_content($num_nodes = NULL, $max_comments = NULL) {
+function drush_devel_generate_generate_content($num_nodes = NULL, $max_comments = NULL, $add_language = NULL) {
if (drush_generate_is_number($num_nodes) == FALSE) {
drush_set_error('DEVEL_GENERATE_INVALID_NUM_NODES', dt('Invalid number of nodes'));
}
@@ -100,6 +101,14 @@ function drush_devel_generate_generate_content($num_nodes = NULL, $max_comments
drush_set_error('DEVEL_GENERATE_INVALID_NUM_COMMENTS', dt('Invalid number of comments.'));
}
+ $add_language = drush_get_option('languages');
+ if (!empty($add_language)) {
+ $add_language = explode(',', str_replace(' ', '', $add_language));
+ // Intersect with the enabled languages to make sure the language args
+ // passed are actually enabled.
+ $values['values']['add_language'] = array_flip(array_intersect($add_language, array_keys(locale_language_list())));
+ }
+
// Let's load user 1, seems to be need for creating comments.
global $user;
$user_one = user_load(array('uid' => '1'));
diff --git a/devel_generate.inc b/devel_generate.inc
index 4606489..ba1cec0 100644
--- a/devel_generate.inc
+++ b/devel_generate.inc
@@ -492,6 +492,10 @@ function devel_generate_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($results['add_terms']) {
devel_generate_add_terms($node);
}
+ if (isset($results['add_language']) && variable_get('language_content_type_' . $node->type, 0)) {
+ $languages = array_keys($results['add_language']);
+ $node->language = $languages[array_rand($languages)];
+ }
break;
case 'insert':
if ($results['max_comments']) {
diff --git a/devel_generate.module b/devel_generate.module
index 0021ab4..7fd856f 100644
--- a/devel_generate.module
+++ b/devel_generate.module
@@ -163,6 +163,16 @@ function devel_generate_content_form() {
'#default_value' => TRUE,
'#access' => module_exists('statistics'),
);
+ if (module_exists('locale')) {
+ $form['add_language'] = array(
+ '#type' => 'select',
+ '#title' => t('Set language on nodes'),
+ '#multiple' => TRUE,
+ '#description' => t('Requires locale.module'),
+ '#options' => array_merge(array('' => t('Language neutral')), locale_language_list()),
+ '#default_value' => '',
+ );
+ }
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Do it!'),