Hi guys,
the last couple of weeks I've been trying really hard to find a solution to this but I have been unsuccessful to this point.
I hope you can help me.
There is a php script I found which downloads information on books. I give it the title and it then fetches details of the closest 10 matches to the provided title. The user then simply clicks on the right one and the author, publishing date, list of characters, plot etc are neatly returned.
I have been trying to integrate it into drupal so I can use it in my site.
I have managed to setup a simple drupal module but I have gotten stuck on establishing a text-field in the node edit area. If you can tell / show me how to do that I'll be very grateful. I don't think it needs to be as involved as an actual CCK type - just a text-field. I then need to know how to capture it's content when the node is submitted so I can query the API and process the returned data.
But I also need advice on how best to store a varying length list of characters in the database, along with the other information
I would appreciate all input,
Thanks :-)
Comments
>don't think it needs to be
>don't think it needs to be as involved as an actual CCK type
For starters I would suggest creating a CCK text field manually. Then all storage questions are handled for you. It's then easy to intercept node submission from your own module and do whatever you want with the text field.
HTH,
gpk
----
www.alexoria.co.uk
Are you trying to set up the
Are you trying to set up the field in all node types? Or in a node type you have defined in your module?
Contact me to contract me for D7 -> D10/11 migrations.
Thanks ..........
I appreciate the responses.
If it's CCK, then so be it.
And, I only want the field to be available in any selected types so I'll have to figuare out an administration page setup too.
Can you guys give me pointers ( simple ones :-) to help me accomplish this goal ?
I've been tossing and turning for weeks and times running out.
Thanks again.
Have a play with CCK - define
Have a play with CCK - define the text field you want and apply it to the node type(s) you want to have this. Then use the devel module to inspect sample node objects which have this field defined - look for the Dev load tab on the node in question. Or in a hook_form_alter() intercept node edit forms and use devel module's dsm() function to dsm($form) - outputs the $form array in a readable format. These should help you to intercept the field in question.
As implied above CCK is not the only way but may do quite a bit of the heavy lifting for you.
gpk
----
www.alexoria.co.uk
A little more help, please
I'm looking into everything you recommended but I must say, it's been a while since I've been confused about what to do in a programming situation.
Can you please give me some direction, tutorial links etc
You can probably do what you
Actually, you can probably do what you want without creating a custom module...
Use CCK to create a text field to hold the title. Have a play and confirm that it does what you want.
Then use CCK Computed Field module to add a computed field - this will contain PHP code in the field definition. Just include your custom script and the computed field will then store the results which will be available as the "content" of the field when viewing the node. Note that the field will only be calculated when the node is saved IIRC, after that the "results" will stay the same until the node is next updated/saved again.
gpk
----
www.alexoria.co.uk
Here is the non CCK way. If
Here is the non CCK way.
If you want to affect other node types, you can use hook_nodeapi. This hook is called each time a node of any type is being executed. You can attach into parts of the process using the various $op values.
For example, you can use the 'prepare' value of $op to add data to the node before it is either viewed or edited. And you can use $op == 'view' to convert the data you have added into it's displayable form.
Contact me to contract me for D7 -> D10/11 migrations.
And you could also combine
And you could also combine this way .. i.e. use hook_nodeapi() .. with a CCK field if you wanted...
gpk
----
www.alexoria.co.uk
New input . . .
Thanks for your great suggestions guy. I appreciate them all.
So, I got started and I went the CCK route. I had previously found a great tutorial at http://www.lullabot.com/articles/creating-custom-cck-fields .
I took the first tentative steps by basically renaming the example module provided in that tutorial to my desired name. It provided a text-field and managed to send the value of the text-field to the API.
So far, I'm just tackling the image that the API returns. The code I'm using for that line follows:
exec("mv {$filename} {$name}.jpg");It simply uses php to execute a linux command to move and rename a file.
The problem is the same command output to my screen,an all white screen, which means Drupal is crashed.
Can anyone direct me to a means of coping a remote file in a drupal module without causing the undesired effect described above.
See file_move().
See file_move().
Something's wrong ...
I tried the code below :
file_move($filename, 0, "/home/remote/public_html/sites/default/files/images/".$name.".jpg");However, file_move did not rename my file( the original name was retained ) and it was dumped in the files directory instead of the images directory.
A little more help ? ....................... ;-)
This example (from manual
This example (from manual page)
file_move("/uploads/mno.txt", "/uploads/converted/xyz.txt"); // move and renameshows proper usage.Phrase 1 complete ...
That's the part where I have developed the module to the point where I enter a name into my cck text-field and it uses my third party API to fetch information.
The first part of that information is an image. I created directories named after the nodeID and used file_move to copy a remote image.
Now, here is my next dialema. I want all the information I import via my module to be accessible in views. Can I make the information my module imports available to Views without that information being in a CCK field ?
If the above is not possible, can I manually copy in a remote image, as I am already doing, but somehow make that image available in a CCK image field.
That may sound bizzare but I have thousands of nodes to import and each does not come with it's image. The image is only retrieved by fetching it through the API. So, that means, my module has to fetch it and somehow attach it to a traditional CCK Image field.
I'd appreciate more suggestions, please.
>I want all the information I
>I want all the information I import via my module to be accessible in views
Well yes, you are probably beginning to see why my knee-jerk reaction was to recommend CCK in order to get all of the built-in functionality e.g. Views integration.
However imagefield will have its own API functions available and may well be able to make use - via a simple one-line function call perhaps - of an image you supply it "manually".
So you have a choice:
1. write your own Views integration ... not hard but you need to get up to speed on the Views API
2. investigate imagefield's API. I'd probably start here since it might be quite simple.
gpk
----
www.alexoria.co.uk
Imagefield API useage
Thanks for your insights in this on going issue.
I took the advice you gave and I'm going down the CCK route.
I added the following code to my module
The function has a reference to the active node so I thought it would work.
However, the site crashed with an internal server error message.
Can you offer any insight into what I'm doing wrong ?
Rather than manipulate the
Rather than manipulate the node object and the image file directly I was meaning that you should have a look at imagefield/imageapi modules and look for existing functions that will do this correctly for you. As a general rule you shouldn't directly manipulate files inside Drupal's files folder - Drupal and contrib modules will lose track of what's in there and various inconsistencies will results. In any case you often need to node_submit() before you node_save().
gpk
----
www.alexoria.co.uk
Sorry
Please excuse me for being a pain.
I agree with the way you specified to approach this problem. I looked around in the imagefield module and attempted calling a number of functions directly from node.tpl.php, like the following :
That function is from the imagefield.module file. I tried others in the same module.
It seems simply enough but notthing to suggest it's working happened. The image appeared nowhere in my website nor on my computer
Understanding the drupal module setup is proving to be harder than I thought.
Can anyone offer some direction on what functions of the imagefield / image modules would allow me to download and save a remote image ?
Are there any websites that deal with drupal pure coding of this nature ?
A couple of pointers: 1.
A couple of pointers:
1. node.tpl.php is part of your theme so it should be just outputting stuff rather than "doing" anything - the code needs to go in your module
2. as the comments say, imagefield_file_download is an "Implementation of hook_file_download."(http://api.drupal.org/api/function/hook_file_download/6) This means that it is invoked automatically by Drupal and you would not generally call it directly. As the doc for the latter says it controls access so again won't actually do anything.
To work out how to integrate with imagefield you'd probably need to walk through the process of what happens when you use the module to attach an image, then see where you can automatically inject your own image into the process. You probably need to get to grips with filefield as well since I think imagefield implements hooks from filefield's API.
Or maybe writing your own Views integration for your custom module begins to look attractive. You might also find some help on IRC, or by finding other contrib modules that do similar things, or maybe some useful info in CCK doc pages on this site.
gpk
----
www.alexoria.co.uk