public function generateValues($object, $instance, $plugin_definition, $form_display_options) { $object_field = array(); $settings = $instance->getFieldSettings(); // Set of possible top-level domains. $tlds = array('com', 'net', 'gov', 'org', 'edu', 'biz', 'info'); // Set random length for the domain name. $domain_length = mt_rand(7, 15); // Get the title settings from the field instance. $allow_title = $settings['title']; switch ($allow_title) { case DRUPAL_DISABLED: $generate_title = FALSE; break; case DRUPAL_REQUIRED: $generate_title = TRUE; break; case DRUPAL_OPTIONAL: // In case of optional title, randomize its generation. $generate_title = mt_rand(0, 1); break; } // Set the title value as the presave function is expecting it but only // input content if needed. $object_field['title'] = ''; if ($generate_title == TRUE) { $object_field['title'] = DevelGenerateBase::develCreateGreeking(4); } $object_field['url'] = 'http://www.' . DevelGenerateBase::generateWord($domain_length) . '.' . $tlds[mt_rand(0, sizeof($tlds) - 1)]; return $object_field; }
public function generateValues($object, $instance, $plugin_definition, $form_display_options) { static $file; $settings = $instance->getFieldSettings(); if (empty($file)) { if ($path = $this->generateTextFile()) { $source = new stdClass(); $source->uri = $path; $source->uid = 1; // TODO: randomize? use case specific. $source->filemime = 'text/plain'; $source->filename = drupal_basename($path); $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory']; file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY); $destination = $destination_dir . '/' . basename($path); $file = file_move($source, $destination, FILE_CREATE_DIRECTORY); } else { return FALSE; } } if (!$file) { // In case a previous file operation failed or no file is set, return FALSE return FALSE; } else { $object_field['target_id'] = $file->id(); $object_field['display'] = $settings['display_default']; $object_field['description'] = DevelGenerateBase::createGreeking(10); return $object_field; } }
public function generateValues($object, $instance, $plugin_definition, $form_display_options) { $object_field = array(); // Set of possible top-level domains. $tlds = array('com', 'net', 'gov', 'org', 'edu', 'biz', 'info'); // Set random lengths for the user and domain as the email field doesn't have // any setting for length. $user_length = mt_rand(5, 10); $domain_length = mt_rand(7, 15); $object_field['value'] = DevelGenerateBase::generateWord($user_length) . '@' . DevelGenerateBase::generateWord($domain_length) . '.' . $tlds[mt_rand(0, sizeof($tlds) - 1)]; return $object_field; }
public function generateValues($object, $instance, $plugin_definition, $form_display_options) { $object_field = array(); $settings = $instance->getSettings(); if (!empty($settings['text_processing'])) { $formats = filter_formats(); $format = array_rand($formats); } else { $format = filter_fallback_format(); } if (empty($settings['max_length'])) { // Textarea handling $object_field['value'] = DevelGenerateBase::createContent($format); if ($form_display_options['type'] == 'text_textarea_with_summary' && !empty($settings['display_summary'])) { $object_field['summary'] = DevelGenerateBase::createContent($format); } } else { // Textfield handling. $object_field['value'] = substr(DevelGenerateBase::createGreeking(mt_rand(1, $settings['max_length'] / 6), FALSE), 0, $settings['max_length']); } $object_field['format'] = $format; return $object_field; }
function generateValues($object, $instance, $plugin_definition, $form_display_options) { $object_field = array(); static $images = array(); $settings = $instance->getSettings(); $min_resolution = empty($settings['min_resolution']) ? '100x100' : $settings['min_resolution']; $max_resolution = empty($settings['max_resolution']) ? '600x600' : $settings['max_resolution']; $extensions = array_intersect(explode(' ', $settings['file_extensions']), array('png', 'gif', 'jpg', 'jpeg')); $extension = array_rand(array_combine($extensions, $extensions)); // 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 = $this->generateImage($extension, $min_resolution, $max_resolution)) { $account = user_load(1); $image = entity_create('file', array()); $image->setFileUri($path); $image->setOwner($account); $image->setMimeType('image/' . pathinfo($path, PATHINFO_EXTENSION)); $image->setFileName(drupal_basename($path)); $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory']; file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY); $destination = $destination_dir . '/' . basename($path); $file = file_move($image, $destination, FILE_CREATE_DIRECTORY); $images[$extension][$min_resolution][$max_resolution][$file->id()] = $file; } else { return FALSE; } } else { // Select one of the images we've already generated for this field. $image_index = array_rand($images[$extension][$min_resolution][$max_resolution]); $file = $images[$extension][$min_resolution][$max_resolution][$image_index]; } $object_field['target_id'] = $file->id(); $object_field['alt'] = DevelGenerateBase::createGreeking(4); $object_field['title'] = DevelGenerateBase::createGreeking(4); return $object_field; }