2

I am using asset module : https://www.drupal.org/project/asset

I creates a new entity type = asset. I get a form where I can add ( document, image, video..).

How can I, from a custom module add a content of asset ? I think that I cannot do it the way we creat nodes ... like :

$node = new stdClass();
$node->type = "asset";
node_object_prepare($node);
....

Please help

thank you

2 Answers 2

0

I think you can try to use core and EntityAPI methods for this task like this:

$asset = entity_get_controller('asset');
$asset->type = 'MY_TYPE';
$asset->... = '...';
....

$asset->save();
1
  • I'am trying this. Get back very soon. Commented Oct 8, 2014 at 9:01
0

this is the right code:

function create_assets(){

$asset = entity_create('asset' , array('type' =>'image'));
$asset->title = 'image publication';
//$asset->field_asset_image = array(LANGUAGE_NONE => array(0 => array('value' => get_external_image("http://cdn.sstatic.net/drupal/img/logo.png"))));
$asset->field_alt["und"][0]["value"] = "alt image publication";
//$asset->save();
entity_save('asset', $asset);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.