[Solved] Attempting to Build Custom PHP rule

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
FatherShawn's picture

I am building a scheduled publishing rule set. I would like to have a php action that resets the created date on the node to the scheduled publishing date as the node is published. I found a clue in the issue que: http://drupal.org/node/641590

The Execute Custom PHP action pane states:

Furthermore you can make use of the following variables:

Variable Type Description Intelligent saving
$publish_content__content content Content {argument} Yes

So I wrote the following code snippet:

<?php
$publish_content__content 
->created = $publish_content__content    ->field_publish_date;
return array(
"node" => $publish_content__content);
?>

Which generates the following error message:

0.23 ms Action execution: "Execute custom PHP code"
0.343 ms Unknown variable name "node" return by action "rules_action_custom_php".

Clearly the "node" in the return statement isn't right. I'm too new to both Drupal and php to know why it doesn't work. I'd appreciate help from more experienced travelers!

Comments

The Fix

FatherShawn's picture

On a lark, I wondered if the module syntax had changed since the notes that I found. I tried this:

<?php
$publish_content__content
->created = $publish_content__content->field_publish_date;
return
$publish_content__content;
?>

Which does not generate an error and updated the field. Still have to get the time issue worked out...

Drupaling in NYC since 2009!

Getting the correct time

FatherShawn's picture

Although the code above executed, it did not result in effectively resetting the date. Using a clue from http://tadej.eu/drupal-published-date-equals-effective-date-fix I change the code to:

<?php
$publish_content__content
->created = time();
return
$publish_content__content;
?>

Which, since the action runs at the time of scheduled publication, is effectively the same thing but actually worked.

Drupaling in NYC since 2009!

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: