function variable_build_multiple in Variable 7
Same name and namespace in other branches
- 7.2 variable.inc \variable_build_multiple()
 
Build multiple variables
1 call to variable_build_multiple()
- variable_build_mail_text in ./
variable.variable.inc  - Build multiple mail variable
 
1 string reference to 'variable_build_multiple'
- variable_variable_type_info in ./
variable.variable.inc  - Implements hook_variable_type_info().
 
File
- ./
variable.inc, line 82  - Variable API module. Extended API.
 
Code
function variable_build_multiple($variable, $options) {
  // Invoke variable callbacks
  if (!empty($variable['multiple callback'])) {
    $variable['multiple'] = variable_callback($variable['multiple callback'], $variable, $options);
  }
  if (isset($variable['multiple'])) {
    if (!is_array($variable['multiple'])) {
      $variable['multiple'] = variable_option_list($variable['multiple'], $variable, $options);
    }
    $variable += array(
      'children' => array(),
      'repeat' => array(),
    );
    // Build children variables with the name => value array
    foreach ($variable['multiple'] as $key => $title) {
      $name = preg_replace('/\\[\\w+\\]/', $key, $variable['name']);
      // Be careful to respect previously set properties, add but do not override.
      $child = isset($variable['children'][$name]) ? $variable['children'][$name] : array();
      $child += $variable['repeat'];
      $child += array(
        'name' => $name,
        'index' => $key,
        'title' => $title,
        'type' => 'default',
        'parent' => $variable['name'],
        'module' => $variable['module'],
      );
      // Set default value from parent
      if (isset($variable['default']) && is_array($variable['default']) && isset($variable['default'][$key])) {
        $child += array(
          'default' => $variable['default'][$key],
        );
      }
      $child += variable_get_type($child['type']);
      $variable['children'][$name] = $child;
    }
  }
  return $variable;
}