You are here

function devel_generate_multiple in Devel 7

A simple function to return multiple values for fields that use custom multiple value widgets but don't need any other special multiple values handling. This will call the field generation function a random number of times and compile the results into a node array.

6 calls to devel_generate_multiple()
file_devel_generate in devel_generate/file.devel_generate.inc
image_devel_generate in devel_generate/image.devel_generate.inc
list_devel_generate in devel_generate/list.devel_generate.inc
number_devel_generate in devel_generate/number.devel_generate.inc
taxonomy_devel_generate in devel_generate/taxonomy.devel_generate.inc

... See full list

File

devel_generate/devel_generate.fields.inc, line 79
Functions needed for devel_generate Fields API integration.

Code

function devel_generate_multiple($function, $object, $field, $instance, $bundle) {
  $object_field = array();
  if (function_exists($function)) {
    switch ($field['cardinality']) {
      case FIELD_CARDINALITY_UNLIMITED:
        $max = rand(0, 3);

        //just an arbitrary number for 'unlimited'
        break;
      default:
        $max = $field['cardinality'] - 1;
        break;
    }
    for ($i = 0; $i <= $max; $i++) {
      $result = $function($object, $field, $instance, $bundle);
      if (!empty($result)) {
        $object_field[$i] = $result;
      }
    }
  }
  return $object_field;
}