You are here

function mediafront_add_media in MediaFront 7

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

Function that will add media to the $additions array

2 calls to mediafront_add_media()
mediafront_get_playlist_from_view in ./mediafront.module
Returns a playlist provided a view.
mediafront_playlist_node in ./mediafront.module
Implements hook_playlist_node()

File

./mediafront.module, line 726

Code

function mediafront_add_media(&$additions, $file) {
  $media_added = false;

  // Only continue if the file exists.
  if ($file) {

    // Convert the file to an object.
    $file = is_array($file) ? mediafront_array_to_object($file) : $file;

    // If the file exists.
    if ($media_file = mediafront_get_media_file($file)) {
      if ($media_file->class && $media_file->mediaType) {
        if ($media_file->mediaType != "image" && isset($additions["mediafiles"][$media_file->class][$media_file->mediaType])) {
          $media = $additions["mediafiles"][$media_file->class][$media_file->mediaType];
          $files = is_array($media) ? $media : array(
            $media,
          );
          array_push($files, $media_file);
          $additions["mediafiles"][$media_file->class][$media_file->mediaType] = $files;
          $media_added = true;
        }
        else {
          $additions["mediafiles"][$media_file->class][$media_file->mediaType] = $media_file;
          $media_added = true;
        }
      }
    }
  }
  return $media_added;
}