function tripal_delete_bulk_loader_field

2.x tripal_bulk_loader.api.templates.inc tripal_delete_bulk_loader_field($priority, $delete_field_index, $template_array)
3.x tripal_bulk_loader.api.templates.inc tripal_delete_bulk_loader_field($priority, $delete_field_index, $template_array)

An API function to delete a field from a template array

Parameters

$priority: The priority of the record containing the field

$delete_field_index: The index of the field to be deleted

$template_array: The array describing the template

Return value

The modified template array

Related topics

2 calls to tripal_delete_bulk_loader_field()
1 string reference to 'tripal_delete_bulk_loader_field'

File

tripal_bulk_loader/api/tripal_bulk_loader.api.templates.inc, line 272
Provides functions for hooking into bulk loader functionality.

Code

function tripal_delete_bulk_loader_field($priority, $delete_field_index, $template_array) {

  if (empty($template_array)) {
    drupal_set_message("Unable to delete record with a priority of $priority since the template was not supplied", 'error');
    return FALSE;
  }

  // Re-order the remaining fields of the same record to ensure that the indicies are
  // 0 to size and. If this is not done, weird behaviour may result
  $new_template_array = $template_array;
  $new_template_array[$priority]['fields'] = array();
  $i = 0;
  foreach ($template_array[$priority]['fields'] as $field_index => $field_details) {
    if ($field_index != $delete_field_index) {
      $new_template_array[$priority]['fields'][$i] = $field_details;
      $i++;
    }
  }

  // If this field was the only one in the current record, also delete the record
  if (empty($new_template_array[$priority]['fields'])) {
    $new_template_array = tripal_delete_bulk_loader_record($priority, $new_template_array);
  }

  return $new_template_array;
}