Closed (fixed)
Project:
File (Field) Paths
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
31 Mar 2011 at 07:53 UTC
Updated:
16 Nov 2011 at 14:01 UTC
Hello how i can use the FileField Path to Programmatic create nodes in Drupal 7?
$node = new stdClass();
$node->type = 'article';
node_object_prepare($node);
$node->title = 'Node Created Programmatically on ' . date('c');
$node->language = LANGUAGE_NONE;
$filepath = drupal_realpath('misc/druplicon.png');
$file = (object) array(
'uid' => 1,
'uri' => $filepath,
'filemime' => file_get_mimetype($filepath),
'status' => 1,
);
$file = file_copy($file, 'public://');
$node->field_image[$node->language][0] = (array)$file;
node_save($node);
The above code works, but does not use the FileField Path.
How can I extend this to use it?
Comments
Comment #1
deciphered commentedTested the above code and it's working correctly with the latest dev of FileField Paths.
Comment #2
marcoka commentedi am infront of the same problem, your code is not good because you set your own path manually: $filepath = drupal_realpath('misc/druplicon.png');
'uri' => $filepath,
so normally it would loook like this with filefeld_paths processed:
http://screensnapr.com/v/CnFJHq.png
but as you set the URI by yourself there is no proecessing through filefield paths. i am currently searching how to get the path processed by filefield_paths.
Comment #3
deciphered commentede-anima,
If you're referring to akalyptos' code when you say 'your code' I disagree, I tested that code with the latest dev of FileField Paths and confirmed that the file was processed correctly, as node_save() invokes the appropriate triggers for FileField Paths to modify the filepath.
If you have conflicting evidence can you provide a step-by-step guide on how to reproduce the issues you are having? Also, when you do so, make sure to set this issue as active, as it is still considered to be fixed.
Cheers,
Deciphered.
Comment #4
marcoka commentedi did something wrong with the LANGUAGE_NONE constant, my bad. i can now confirm that it works as it should with that code above. apologys