You are here

function conditional_fields_is_empty in Conditional Fields 6.2

Checks if a submitted field value is empty.

1 call to conditional_fields_is_empty()
conditional_fields_node_form_validate in ./conditional_fields.module
Validation for node editing form.

File

./conditional_fields.module, line 1013
Content fields and groups visibility based on the values of user defined 'trigger' fields.

Code

function conditional_fields_is_empty($item, $field, $field_info) {

  // First, check if the module that provides the field implements
  // hook_content_is_empty, and, if so, use it.
  if (in_array($field_info['module'], module_implements('content_is_empty'))) {
    $empty = $field_info['module'] . '_content_is_empty';
    return $empty($item, $field);
  }
  $value = NULL;

  // Attempt to extract the key from "_error_element".
  if (isset($item[0]['_error_element'])) {
    $error_tree = explode('][', $item[0]['_error_element']);
    $key = array_pop($error_tree);
    if (isset($item[0][$key])) {
      $value = $item[0][$key];
    }
  }

  // Last resort: maybe the field uses a generic "value" key.
  if (is_null($value) && isset($item[0]['value'])) {
    $value = $item[0]['value'];
  }
  else {

    // If no value was found, assume that the field is empty,
    // which may be annoying, but prevents saving incomplete data.
    return TRUE;
  }
  return !count($value) || is_string($value) && drupal_strlen(trim($value)) == 0;
}