You are here

function _mediafront_get_field in MediaFront 7

Same name and namespace in other branches
  1. 6.2 mediafront.module \_mediafront_get_field()
  2. 6 mediafront.module \_mediafront_get_field()

Returns the field if it exists.

1 call to _mediafront_get_field()
mediafront_playlist_node in ./mediafront.module
Implements hook_playlist_node()

File

./mediafront.module, line 758

Code

function _mediafront_get_field($node, $field_name, $index = -1) {
  $langs = array(
    $node->language,
    'und',
  );
  foreach ($langs as $lang) {
    if (isset($node->{$field_name}) && is_array($node->{$field_name}) && isset($node->{$field_name}[$lang]) && is_array($node->{$field_name}[$lang]) && isset($node->{$field_name}[$lang][0])) {
      if ($index >= 0) {
        $field = (array) $node->{$field_name}[$lang][$index];
        return $field;
      }
      else {
        $fields = array();
        foreach ($node->{$field_name}[$lang] as $index => $field) {
          $fields[$index] = (array) $field;
        }
        return $fields;
      }
    }
  }
  return null;
}