updated devel

This commit is contained in:
2020-06-23 12:18:53 +02:00
parent 835220fa8b
commit 5b116d4733
116 changed files with 6248 additions and 5663 deletions
@@ -270,6 +270,7 @@ function devel_generate_terms($records, $vocabs, $maxlength = 12) {
$term->format = filter_fallback_format();
$term->weight = mt_rand(0, 10);
$term->language = LANGUAGE_NONE;
$term->devel_generate = TRUE;
// Populate all core fields on behalf of field.module
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
@@ -477,29 +478,11 @@ function devel_generate_word($length){
return substr($word, 0, $length);
}
function devel_create_content($type = NULL) {
$nparas = mt_rand(1,12);
$type = empty($type) ? mt_rand(0,3) : $type;
$output = "";
switch($type % 3) {
// MW: This appears undesireable. Was giving <p> in text fields
// case 1: // html
// for ($i = 1; $i <= $nparas; $i++) {
// $output .= devel_create_para(mt_rand(10,60),1);
// }
// break;
//
// case 2: // brs only
// for ($i = 1; $i <= $nparas; $i++) {
// $output .= devel_create_para(mt_rand(10,60),2);
// }
// break;
default: // plain text
for ($i = 1; $i <= $nparas; $i++) {
$output .= devel_create_para(mt_rand(10,60)) ."\n\n";
}
function devel_create_content() {
$nparas = mt_rand(1, 12);
$output = '';
for ($i = 1; $i <= $nparas; $i++) {
$output .= devel_create_para(mt_rand(10,60)) . "\n\n";
}
return $output;
@@ -659,8 +642,12 @@ function devel_generate_content_pre_node(&$results) {
/**
* Create one node. Used by both batch and non-batch code branches.
*
* @param $num
* array of options obtained from devel_generate_content_form.
* @param $results
* array of options obtained from devel_generate_content_form. If call
* this function directly, $results should contain at the very least:
* node_types => an associative array of node type machine names
* users => an array of UIDs
* title_length => max number of words in titles, for example 4.
*/
function devel_generate_content_add_node(&$results) {
$node = new stdClass();
@@ -675,7 +662,7 @@ function devel_generate_content_add_node(&$results) {
$node->revision = mt_rand(0,1);
$node->promote = mt_rand(0, 1);
if ($type->has_title) {
if (!$type || $type->has_title) {
// We should not use the random function if the value is not random
if ($results['title_length'] < 2) {
$node->title = devel_create_greeking(1, TRUE);
@@ -6,9 +6,8 @@ tags[] = developer
configure = admin/config/development/generate
files[] = devel_generate.test
; Information added by Drupal.org packaging script on 2014-05-01
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2019-02-22
version = "7.x-1.7"
core = "7.x"
project = "devel"
datestamp = "1398963366"
datestamp = "1550852892"
@@ -91,7 +91,8 @@ function devel_generate_users_form() {
'#default_value' => 604800,
);
$form['submit'] = array(
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
@@ -225,7 +226,8 @@ function devel_generate_content_form() {
'#default_value' => array(LANGUAGE_NONE),
);
$form['submit'] = array(
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
@@ -292,7 +294,8 @@ function devel_generate_term_form() {
'#title' => t('Delete existing terms in specified vocabularies before generating new terms.'),
'#default_value' => FALSE,
);
$form['submit'] = array(
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
@@ -320,7 +323,8 @@ function devel_generate_vocab_form() {
'#title' => t('Delete existing vocabularies before generating new ones.'),
'#default_value' => FALSE,
);
$form['submit'] = array(
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
@@ -435,7 +439,7 @@ function devel_generate_menu_form() {
'#size' => 10,
'#states' => array(
'visible' => array(
':input[name=existing_menus[__new-menu__]]' => array('checked' => TRUE),
':input[name="existing_menus[__new-menu__]"]' => array('checked' => TRUE),
),
),
);
@@ -487,7 +491,8 @@ function devel_generate_menu_form() {
'#title' => t('Delete existing custom generated menus and menu links before generating new ones.'),
'#default_value' => FALSE,
);
$form['submit'] = array(
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
@@ -1,30 +1,29 @@
<?php
/**
* Devel Generate batch handling functions using the BatchAPI
* Devel Generate batch handling functions using the BatchAPI.
*/
/**
* Functions called from FAPI:
* Form constructor generating in batches.
*/
function devel_generate_batch_content($form_state) {
$operations = array();
// Setup the batch operations and save the variables.
$operations[] = array('devel_generate_batch_content_pre_node', array($form_state['values']));
// add the kill operation
// Add the kill operation.
if ($form_state['values']['kill_content']) {
$operations[] = array('devel_generate_batch_content_kill', array());
}
// add the operations to create the nodes
// Add the operations to create the nodes.
for ($num = 0; $num < $form_state['values']['num_nodes']; $num ++) {
$operations[] = array('devel_generate_batch_content_add_node', array());
}
// start the batch
// Start the batch.
$batch = array(
'title' => t('Generating Content'),
'operations' => $operations,
@@ -34,10 +33,6 @@ function devel_generate_batch_content($form_state) {
batch_set($batch);
}
/**
* Create Content Batch Functions:
*/
function devel_generate_batch_content_kill(&$context) {
module_load_include('inc', 'devel_generate', 'devel_generate');
devel_generate_content_kill($context['results']);
@@ -50,12 +45,18 @@ function devel_generate_batch_content_pre_node($vars, &$context) {
devel_generate_content_pre_node($context['results']);
}
/**
* Batch API callback: Generate nodes.
*/
function devel_generate_batch_content_add_node(&$context) {
module_load_include('inc', 'devel_generate', 'devel_generate');
devel_generate_content_add_node($context['results']);
$context['results']['num_nids'] ++;
}
/**
* Display a message when a batch is complete.
*/
function devel_generate_batch_finished($success, $results, $operations) {
if ($success) {
$message = t('Finished @num_nids nodes created successfully.', array('@num_nids' => $results['num_nids']));
@@ -65,4 +66,3 @@ function devel_generate_batch_finished($success, $results, $operations) {
}
drupal_set_message($message);
}
@@ -14,15 +14,22 @@ function _file_devel_generate($object, $field, $instance, $bundle) {
if (empty($file)) {
if ($path = devel_generate_textfile()) {
$source = new stdClass();
$source->uri = $path;
$source->uid = 1; // TODO: randomize? use case specific.
$source->filemime = 'text/plain';
$source->filename = basename($path);
$destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
$destination = $destination_dir . '/' . basename($path);
$file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
if ($uri = file_unmanaged_move($path, $destination_dir)) {
$file = new stdClass();
$file->fid = NULL;
$file->uri = $uri;
$file->filename = drupal_basename($uri);
$file->filemime = file_get_mimetype($file->uri);
// @todo Randomize file owner.
$file->uid = 1;
$file->devel_generate = TRUE;
$file = file_save($file);
}
else {
return FALSE;
}
}
else {
return FALSE;
@@ -29,16 +29,22 @@ function _image_devel_generate($object, $field, $instance, $bundle) {
// Generate a max of 5 different images.
if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
if ($path = devel_generate_image($extension, $min_resolution, $max_resolution)) {
$source = new stdClass();
$source->uri = $path;
$source->uid = 1; // TODO: randomize? Use case specific.
$source->filemime = 'image/' . pathinfo($path, PATHINFO_EXTENSION);
$source->filename = basename($path);
$destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
$destination = $destination_dir . '/' . basename($path);
$file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
$images[$extension][$min_resolution][$max_resolution][$file->fid] = $file;
if ($uri = file_unmanaged_move($path, $destination_dir)) {
$file = new stdClass();
$file->fid = NULL;
$file->uri = $uri;
$file->filename = drupal_basename($uri);
$file->filemime = file_get_mimetype($file->uri);
// @todo Randomize file owner.
$file->uid = 1;
$file = file_save($file);
$images[$extension][$min_resolution][$max_resolution][$file->fid] = $file;
}
else {
return FALSE;
}
}
else {
return FALSE;
@@ -21,14 +21,15 @@ function _text_devel_generate($object, $field, $instance, $bundle) {
if (empty($field['settings']['max_length'])) {
// Textarea handling
$object_field['value'] = devel_create_content($format);
$object_field['value'] = devel_create_content();
if ($instance['widget']['type'] == 'text_textarea_with_summary' && !empty($instance['display_summary'])) {
$object_field['summary'] = devel_create_content($format);
$object_field['summary'] = devel_create_content();
}
}
else {
// Textfield handling.
$object_field['value'] = substr(devel_create_greeking(mt_rand(1, $field['settings']['max_length'] / 6), FALSE), 0, $field['settings']['max_length']);
$max = ceil($field['settings']['max_length'] / 6);
$object_field['value'] = substr(devel_create_greeking(mt_rand(1, $max), FALSE), 0, $field['settings']['max_length']);
}
$object_field['format'] = $format;
return $object_field;