Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi! I'm trying to create nodes programatically and would like to populate a youtube field. After doing some research, I learned that the code needs to be something like this:
<?php
// $value in this case is the youtube ID.
$file = new stdClass();
$file->uid = 1;
$file->filename = $value;
$file->uri = 'youtube://v/' . $value;
$file->filemime = 'video/youtube';
$file->type = 'video';
$file->status = 1;
$youtube = file_save($file);
node->field_youtube[$node->language]['0']['fid'] = (array) $youtube->fid;
However, it throws an error saying "Bad file type". I also tried writing the full url in $file->uri, then it showed up but wouldn't play. What am I doing wrong?
Comments
Comment #1
jaykainthola CreditAttribution: jaykainthola commentedHi,
I also want to implement same.
Can anyone suggest us?
Thanks