You are here

function _video_embed_field_clean_up_youtube_data in Video Embed Field 7.2

Flattens out some unnecessary nesting in the youtube data.

Parameters

array $data: The unflattened data.

Return value

array The flattened data.

1 call to _video_embed_field_clean_up_youtube_data()
video_embed_field_handle_youtube_data in ./video_embed_field.handlers.inc
Gets video data for a YouTube video URL.

File

./video_embed_field.handlers.inc, line 285
Provide some handlers for video embed field Other modules can implement the hook_video_embed_handler_info to provide more handlers.

Code

function _video_embed_field_clean_up_youtube_data($data) {

  // Make things a bit nicer for people trying to use the data.
  foreach ($data as $key => $value) {
    if (is_object($value)) {
      $temp = (array) $value;
      if (isset($temp['$t'])) {
        $data[$key] = $temp['$t'];
      }
      else {
        $data[$key] = _video_embed_field_clean_up_youtube_data($temp);
      }
    }
    elseif (is_array($value)) {
      $data[$key] = _video_embed_field_clean_up_youtube_data($value);
    }
    if ($key === 'category') {
      $terms = array();
      foreach ($data[$key] as $value) {
        if (isset($value['scheme']) && $value['scheme'] == 'http://schemas.google.com/g/2005#kind') {
          continue;
        }
        if (isset($value['term'])) {
          $terms[] = $value['term'];
        }
      }
      $data['terms'] = $terms;
    }
  }
  return $data;
}