Posted by dbourrion on May 21, 2011 at 7:50am
After installation of the Rules module, I created a Triggered rules that is supposed to :
- look if there is an image associated with the new created content (image into field_image)
- if yes, made the new content «Sticky» on publich (even by scheduler)
But it doesn't work :(
The code is below - does somebody understand where is the problem ?
Thanks for tips and help
Best
D.
array (
'rules' =>
array (
'rules_punaiser' =>
array (
'#type' => 'rule',
'#set' => 'event_node_insert',
'#label' => 'Punaiser contenu si images',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
0 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Le champ \'field_image\' de created content a été modifié',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Contenu contenant des modifications',
),
'node_unchanged' =>
array (
'type' => 'node',
'label' => 'Contenu ne contenant pas de modification',
),
),
'module' => 'CCK',
),
'#name' => 'content_rules_field_changed',
'#settings' =>
array (
'field_name' => 'field_image',
'#argument map' =>
array (
'node' => 'node',
'node_unchanged' => 'node',
),
),
'#type' => 'condition',
),
1 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Created content is published',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Contenu',
),
),
'module' => 'Node',
),
'#name' => 'rules_condition_content_is_published',
'#settings' =>
array (
'#argument map' =>
array (
'node' => 'node',
),
),
'#type' => 'condition',
),
),
'#actions' =>
array (
0 =>
array (
'#type' => 'action',
'#settings' =>
array (
'auto_save' => 1,
'#argument map' =>
array (
'node' => 'node',
),
),
'#name' => 'rules_core_node_make_sticky_action',
'#info' =>
array (
'label' => 'Mettre en lumière le created content',
'module' => 'Node',
'arguments' =>
array (
'node' =>
array (
'label' => 'Contenu',
'type' => 'node',
),
),
'base' => 'rules_core_action_execute',
'action_name' => 'node_make_sticky_action',
'configurable' => false,
'label callback' => 'rules_core_node_label_callback',
'label_skeleton' => 'Mettre en lumière le @node',
),
'#weight' => 0,
),
),
'#version' => 6003,
),
),
)
Comments
Hum
Still trying to find it out.
In fact, I don't know what condition I should use, to test if the image_field is empty or not (if not, my condition is on and I should stick the content).
Any help ?
Solved that way
Just by evaluating the field_image with numeric evaluation
array ('rules' =>
array (
'rules_puna' =>
array (
'#type' => 'rule',
'#set' => 'event_node_insert',
'#label' => 'Punaiser',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
1 =>
array (
'#type' => 'condition',
'#settings' =>
array (
'number1' => '[node:field_image-filefield-filesize]',
'number2' => '0',
'operation' => 'greater',
'#eval input' =>
array (
'token_rules_input_evaluator' =>
array (
'number1' =>
array (
0 => 'node',
1 => ':global',
),
'number2' =>
array (
0 => ':global',
),
),
),
),
'#name' => 'rules_condition_number_compare',
'#info' =>
array (
'label' => 'Numeric comparison',
'arguments' =>
array (
'number1' =>
array (
'label' => 'Number 1',
'type' => 'number',
),
'number2' =>
array (
'label' => 'Number 2',
'type' => 'number',
),
),
'module' => 'Rules',
),
'#weight' => 0,
),
),
'#actions' =>
array (
0 =>
array (
'#type' => 'action',
'#settings' =>
array (
'from' => 'Face-terres',
'subject' => 'Test',
'message' => '',
'#argument map' =>
array (
'user' => 'user',
),
'#eval input' =>
array (
'token_rules_input_evaluator' =>
array (
'subject' =>
array (
0 => ':global',
),
'message' =>
array (
0 => ':global',
),
'from' =>
array (
0 => ':global',
),
),
),
),
'#name' => 'rules_action_mail_to_user',
'#info' =>
array (
'label' => 'Send a mail to a user',
'arguments' =>
array (
'user' =>
array (
'type' => 'user',
'label' => 'Destinataire',
),
),
'module' => 'System',
'eval input' =>
array (
0 => 'subject',
1 => 'message',
2 => 'from',
),
),
'#weight' => 0,
),
1 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Mettre en lumière le created content',
'module' => 'Node',
'arguments' =>
array (
'node' =>
array (
'label' => 'Contenu',
'type' => 'node',
),
),
'base' => 'rules_core_action_execute',
'action_name' => 'node_make_sticky_action',
'configurable' => false,
'label callback' => 'rules_core_node_label_callback',
'label_skeleton' => 'Mettre en lumière le @node',
),
'#name' => 'rules_core_node_make_sticky_action',
'#settings' =>
array (
'auto_save' => 1,
'#argument map' =>
array (
'node' => 'node',
),
),
'#type' => 'action',
),
),
'#version' => 6003,
),
),
)
Empty fields are tricky
It is sometimes tricky for Rules to know if a field is empty or not – especially when it comes to complex fields like image uploads.
I think it is possible to create a condition that checks if CCK fields are empty, in generally applicable way, but there are no such condition currently. I'm maintaining the Rules Bonus Pack module, and I'd be happy for a feature request about this.
Cheers!
//Johan Falk
**
Learn Drupal with Nodeone! Drupal 7 introduction | The Views module | Learn Page manager! | Drupal configuration learning curve | Rules for Drupal 6 | Theming Drupal 6 | 49 Drupal 6 modules you should know
Rules Bonus pack
Well... I've your bonus pack installed
The way I evaluate the image field works great for me, but perhaps that a more generic tool should help somebody (and me ;) )
Best