I've a term reference multi value field. What is the right way to count filled values which is also portable to D8, D9 etc.
The dsm output shows like this:
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
It really depends on the type of field, and on when you are trying to retrieve the values.
hook_form_alter() for checkboxes, radios, and select fields, the values you are referring to are typically set via the #options property. Example:
$form['artist_tags']['und']['#options']. You can wrap that in
count() to get the number of values.
hook_form_submit() or a function called from the
$form['#after_build'] property, you will also have access to the number of selected values via
$form_state['values']['artist_tags']['und'] (or when
$form_state['submitted'] is TRUE, check