|
|
Drupal example source code file (php.rules.inc)
The php.rules.inc Drupal example source code<?php // $Id: php.rules.inc,v 1.1.2.1 2010/12/16 09:30:43 fago Exp $ /** * @file rules integration for the php module * * @addtogroup rules * @{ */ /** * Implements hook_rules_file_info() on behalf of the php module. */ function rules_php_file_info() { return array('modules/php.eval'); } /** * Implements hook_rules_evaluator_info() on behalf of the php module. */ function rules_php_evaluator_info() { return array( 'php' => array( 'class' => 'RulesPHPEvaluator', 'type' => array('text', 'token', 'uri'), 'weight' => -10, 'module' => 'php', ), ); } /** * Implements hook_rules_data_processor_info() on behalf of the php module. */ function rules_php_data_processor_info() { return array( 'php' => array( 'class' => 'RulesPHPDataProcessor', 'type' => array('text', 'token', 'decimal', 'integer', 'date', 'duration', 'boolean', 'uri'), 'weight' => 10, 'module' => 'php', ), ); } /** * Implements hook_rules_action_info() on behalf of the php module. */ function rules_php_action_info() { return array( 'php_eval' => array( 'label' => t('Execute custom PHP code'), 'group' => t('PHP'), 'parameter' => array( 'code' => array( 'restriction' => 'input', 'type' => 'text', 'label' => t('PHP code'), ), ), 'base' => 'rules_execute_php_eval', 'access callback' => 'rules_php_integration_access', ), ); } /** * Process the settings to prepare code execution. */ function rules_execute_php_eval_process(RulesAbstractPlugin $element) { $element->settings['used_vars'] = RulesPHPEvaluator::getUsedVars('<?' . $element->settings['code'], $element->availableVariables()); } /** * Specify the php module as dependency. */ function rules_execute_php_eval_dependencies() { return array('php'); } /** * PHP integration access callback. */ function rules_php_integration_access() { return user_access('use PHP for settings'); } /** * Implements hook_rules_condition_info() on behalf of the PHP module. */ function rules_php_condition_info() { return array( 'php_eval' => array( 'label' => t('Execute custom PHP code'), 'group' => t('PHP'), 'parameter' => array( 'code' => array( 'restriction' => 'input', 'type' => 'text', 'label' => t('PHP code'), ), ), 'base' => 'rules_execute_php_eval', 'access callback' => 'rules_php_integration_access', ), ); } /** * Generates help for the PHP actions, conditions and input evaluator. */ function rules_php_evaluator_help($var_info, $action_help = FALSE) { $render['top'] = array( '#prefix' => '<p>', '#suffix' => '</p>', '#markup' => t('PHP code inside of <?php ?> delimiters will be evaluated and replaced by its output. E.g. <? echo 1+1?> will be replaced by 2.') . ' ' . t('Furthermore you can make use of the following variables:'), ); $render['vars'] = array( '#theme' => 'table', '#header' => array(t('Variable name'), t('Type'), t('Description')), '#attributes' => array('class' => array('rules-php-help')), ); $cache = rules_get_cache(); foreach ($var_info as $name => $info) { $row = array(); $row[] = '$'. check_plain($name); $label = isset($cache['data_info'][$info['type']]['label']) ? $cache['data_info'][$info['type']]['label'] : $info['type']; $row[] = check_plain(drupal_ucfirst($label)); $row[] = check_plain($info['label']); $render['vars']['#rows'][] = $row; } if ($action_help) { $render['updated_help'] = array( '#prefix' => '<p>', '#suffix' => '</p>', '#markup' => t("If you want to change a variable just return an array of new variable values, e.g.: !code", array('!code' => '<pre>return array("node" => $node);</pre>')), ); } return $render; } /** * @} */ Other Drupal examples (source code examples)Here is a short list of links related to this Drupal php.rules.inc source code file: |
"Drupal" is a registered trademark of Dries Buytaert.
my drupal tutorials and examples
Copyright
1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.
Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.