function mediafront_get_node in MediaFront 7.2
Same name and namespace in other branches
- 6.2 mediafront.module \mediafront_get_node()
- 6 mediafront.module \mediafront_get_node()
- 7 mediafront.module \mediafront_get_node()
Provided a type, entity, and fields; this creaets a player node.
Parameters
string $type The type of object we are dealing with.:
object $entity The entity to search.:
array $fields An array of fields to include in the player.:
2 calls to mediafront_get_node()
- mediafront_get_playlist_from_view in ./
mediafront.module - Returns a playlist provided a view.
- theme_mediafront_player in ./
mediafront.module - Implement the theme for the media player.
File
- ./
mediafront.module, line 652
Code
function mediafront_get_node($type, $entity, $fields) {
// Create our node object.
$node = array();
// Only iterate over fields if they are an array.
if (is_array($fields)) {
// Iterate through all of our fields.
$stream = '';
foreach ($fields as $field) {
// Get the options.
$options = $field['options'];
// Get the values for this field.
$values = mediafront_get_field_value($type, $entity, $field);
if (!empty($values)) {
// If this is a media field.
if ($field['type'] == 'media') {
foreach ($values as $value) {
$node['mediafiles']['media'][$options['media_type']][] = new MediaFile($value);
}
}
else {
if ($field['type'] == 'image') {
// Iterate through the thumbnail and previews.
foreach (array(
'thumbnail',
'preview',
) as $image_type) {
// If we just want the original image...
if ($options[$image_type] == 'mediafront_original') {
$file = new MediaFile($values[0]);
$node['mediafiles']['image']['image'] = $file;
}
else {
if (!empty($options[$image_type])) {
$file = new MediaFile($values[0]);
if (empty($file->path)) {
$file->path = image_style_url($options[$image_type], $file->file->uri);
}
$node["mediafiles"]['image'][$image_type] = $file;
}
}
}
}
else {
if ($field['type'] == 'title') {
$node['title'] = is_array($values[0]) ? $values[0]['safe_value'] : $values[0];
}
else {
if ($field['type'] == 'custom') {
// Add this field to the node values.
$node[$options['custom']] = is_array($values[0]) ? $values[0]['safe_value'] : $values[0];
}
else {
if ($field['type'] == 'stream') {
$stream = $values[0];
}
else {
// All other fields are added directly to the node.
$node[$field['field']] = is_array($values[0]) ? $values[0]['safe_value'] : $values[0];
}
}
}
}
}
}
}
// If a stream was provided, then set it to the media file.
if ($stream && !empty($node['mediafiles']['media']['media'][0])) {
$node['mediafiles']['media']['media'][0]->stream = $stream;
}
// Always include the node title.
if ($type == 'node' && !empty($entity->title)) {
$node['title'] = $entity->title;
}
// Add the node id if it is available.
if ($type == 'node' && !empty($entity->nid)) {
$node['nid'] = $entity->nid;
}
// If we have media, but not preview, see if the media module can help us out...
if (!empty($node['mediafiles']['media']) && empty($node['mediafiles']['image'])) {
if ($image = mediafront_get_media_preview($node['mediafiles']['media']['media'][0])) {
$node['mediafiles']['image']['image'] = $image;
}
}
}
else {
if (!empty($entity->fid)) {
// If this a media entity, then we need to handle that as well.
$node['mediafiles']['media']['media'] = new MediaFile($entity);
$node['title'] = $entity->filename;
}
}
// Allow other modules the opportunity to alter the node.
drupal_alter('mediafront_node', $entity, $fields, $node, $type);
// Return the node object.
return $node;
}