Posted by mnkylord on November 10, 2009 at 4:12pm
Hi everybody,
Here's what I'm trying to do: When the user submits a custom CCK content type (Newsletter), I have a rule setup to access one of its fields (field_pdf, a path to the associated pdf file), and generate a thumbnail from the file's front page. Here's what I've got so far:
Event: After saving new content
IF: Content is Newsletter
DO: Execute custom PHP code
However, in the PHP Code block of the Execute Custom PHP Code page, it is not obvious to me how I reference my content's field_pdf variable.
generateThumbnail(?????????);
How do I access that field?
Comments
Token replacements
You should be able to use the token replacement patterns in your php code. Another option is to use something like the Devel module and the dev load tab that appears when you view content to inspect nodes to see how they're constructed.
Any solution
I'm trying to evaluate a cck field when node is saved. I would like to look if this field is not empty.
Is it possible to have some PHP examples, because the help example isn't clear enough.
Thanks,
- Damien
Keep Open Spirit
fields are stored in the node object
fields are stored in the node object: http://drupal.org/node/634420
PHP examples for referencing CCK fields
The code below shows one method to access taxonomy and CCK fields within PHP. It's probably not the most efficient code, and it won't work as is. But it'll give you examples on how to extract the information you're looking for. Do use the Devel module to identify your site specific field names
Michael
<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
$node = node_load(arg(1));
$WineRating = '([placeholder till it\'s added])'; // Add this to CASE stmt when available
// TAXONOMY
foreach ($node->taxonomy as $term) {
switch ($term->vid) {
case 7:
$WineGrade = $term->name;
break;
case 8:
$WinePrice = $term->name;
break;
case 14:
$WineCountry = $term->name;
break;
case 16:
$WineYear = $term->name;
break;
}
}
switch ($WineGrade) {
case "A+":
$WineRatingTemp = (int) 12;
break;
case "B+":
$WineRatingTemp = (int) 9;
break;
}
...
// CCK FIELDS
$output .= '<p>Varietal(s): ' . $node->field_grapes[0]['value'] . '<br>';
$output .= 'Selected by: ' . $node->field_selected_by[0]['value'] . '<br>';
$output .= 'Imported by: ' . $node->field_imported_by[0]['value'] . '</p>';
...
?>