You are here

function views_bulk_operations_fields_action in Views Bulk Operations (VBO) 6.3

Same name and namespace in other branches
  1. 6 actions/fields.action.inc \views_bulk_operations_fields_action()
1 string reference to 'views_bulk_operations_fields_action'
views_bulk_operations_views_default_views in ./views_bulk_operations.views_default.inc
Implementation of hook_views_default_views().

File

./fields.action.inc, line 310
Drupal action to set individual field values.

Code

function views_bulk_operations_fields_action(&$node, $context) {
  foreach ($context['#field_info'] as $field_name => $field) {
    if ($context[$field_name . '_check']) {

      // use the value for this field
      if (!empty($context[$field_name . '_code'])) {
        $value = eval('?>' . $context[$field_name . '_code']);
      }
      else {
        $value = $context[$field_name];
      }
      if ($context[$field_name . '_add']) {
        $function = $field['module'] . '_content_is_empty';
        foreach ($node->{$field_name} as $delta => $item) {
          if (call_user_func($function, $item, $field)) {
            foreach ($value as $v_delta => $v_item) {
              if (!call_user_func($function, $v_item, $field)) {
                $node->{$field_name}[$delta] = $v_item;
                unset($value[$v_delta]);
                break;
              }
            }
          }
        }
      }
      else {
        $node->{$field_name} = $value;
      }
      if ($field_name == 'name') {

        // special case: fix uid when given author name
        if ($account = user_load(array(
          'name' => $node->name,
        ))) {
          $node->uid = $account->uid;
        }
        else {
          $node->uid = 0;
        }
      }
    }
  }
}