0

In checking whether a form field contains an entry, it has been typical to do something like:

if (sizeof($form_state['values']['my_field'][LANGUAGE_NONE]) > 0)

because an empty field would still be an array, but an empty one. With entity reference fields, an empty field looks like:

$form_state
  values
    my_field
      und
        0
          target_id=''
          add_entityconnect_my_field_0_ = "New content"
          edit_entityconnect_my_field_0_ = "Edit content"

so that testing for the empty array fails. One could check to see if the target_id is empty, but I'm wondering if there's a way to test the form field for empty without needing to go down to that level.

1 Answer 1

1

Take a look at entityreference_field_is_empty(), which at least will get you up a level by checking if target_id is empty on your behalf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.