Blog Archive

Thursday, 17 October 2013

Drupal 7 - create node programatically, adding a youtube embed to a field

<?php
$node = new StdClass();
$node->type = 'card';
$node->language = LANGUAGE_NONE;
$node->title = "Creating file node youtube";
$node->field_card_type['und'][0]['value'] = 'video';
$video_path = "http://www.youtube.com/watch?v=FmsgX1LkeRE";
module_load_include('inc', 'media_youtube', 'includes/MediaInternetYouTubeHandler.inc');
$obj = new MediaInternetYouTubeHandler($video_path);
$file = $obj->getFileObject();
$file->display = 1;
file_save($file);
$node->field_card_upload_video['und'][0] = (array) $file;
node_save($node);
?>

No comments:

Post a Comment