Projet

Général

Profil

Révision 950416da

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/rules/rules.module
1 1
<?php
2 2

  
3 3
/**
4
 * @file Rules engine module
4
 * @file
5
 * Rules engine module.
5 6
 */
6 7

  
7 8
// The class autoloader may fail for classes added in 7.x-2.4 (Issue 2090511).
......
57 58
}
58 59

  
59 60
/**
60
 * Returns an instance of the rules UI controller, which eases re-using the Rules UI.
61
 * Returns an instance of the rules UI controller.
61 62
 *
63
 * This function is for convenience, to ease re-using the Rules UI.
62 64
 * See the rules_admin.module for example usage.
63 65
 *
64 66
 * @return RulesUIController
......
76 78
 *
77 79
 * @param $name
78 80
 *   The action's name.
79
 * @param $settings
81
 * @param array $settings
80 82
 *   The action's settings array.
83
 *
81 84
 * @return RulesAction
82 85
 */
83 86
function rules_action($name, $settings = array()) {
......
89 92
 *
90 93
 * @param $name
91 94
 *   The condition's name.
92
 * @param $settings
95
 * @param array $settings
93 96
 *   The condition's settings array.
97
 *
94 98
 * @return RulesCondition
95 99
 */
96 100
function rules_condition($name, $settings = array()) {
......
100 104
/**
101 105
 * Creates a new rule.
102 106
 *
103
 * @param $variables
107
 * @param array $variables
104 108
 *   The array of variables to setup in the evaluation state, making them
105
 *   available for the configuraion elements. Values for the variables need to
109
 *   available for the configuration elements. Values for the variables need to
106 110
 *   be passed as argument when the rule is executed. Only Rule instances with
107 111
 *   no variables can be embedded in other configurations, e.g. rule sets.
108 112
 *   The array has to be keyed by variable name and contain a sub-array for each
......
115 119
 *      initially, but the "Set data value" action may be used to do so. This is
116 120
 *      in particular useful for defining variables which can be provided to the
117 121
 *      caller (see $provides argument) but need not be passed in as parameter.
118
 * @param $provides
122
 * @param array $provides
119 123
 *   The names of variables which should be provided to the caller. Only
120 124
 *   variables contained in $variables may be specified.
125
 *
121 126
 * @return Rule
122 127
 */
123 128
function rule($variables = NULL, $provides = array()) {
......
136 141
/**
137 142
 * Creates a logical OR condition container.
138 143
 *
139
 * @param $variables
144
 * @param array $variables
140 145
 *   An optional array as for rule().
146
 *
141 147
 * @return RulesOr
142 148
 */
143 149
function rules_or($variables = NULL) {
......
147 153
/**
148 154
 * Creates a logical AND condition container.
149 155
 *
150
 * @param $variables
156
 * @param array $variables
151 157
 *   An optional array as for rule().
158
 *
152 159
 * @return RulesAnd
153 160
 */
154 161
function rules_and($variables = NULL) {
......
158 165
/**
159 166
 * Creates a loop.
160 167
 *
161
 * @param $settings
168
 * @param array $settings
162 169
 *   The loop settings, containing
163 170
 *     'list:select': The data selector for the list to loop over.
164 171
 *     'item:var': Optionally a name for the list item variable.
165
 *     'item:label': Optionally a lebel for the list item variable.
166
 * @param $variables
172
 *     'item:label': Optionally a label for the list item variable.
173
 * @param array $variables
167 174
 *   An optional array as for rule().
175
 *
168 176
 * @return RulesLoop
169 177
 */
170 178
function rules_loop($settings = array(), $variables = NULL) {
......
174 182
/**
175 183
 * Creates a rule set.
176 184
 *
177
 * @param $variables
185
 * @param array $variables
178 186
 *   An array as for rule().
179
 * @param $provides
187
 * @param array $provides
180 188
 *   The names of variables which should be provided to the caller. See rule().
189
 *
181 190
 * @return RulesRuleSet
182 191
 */
183 192
function rules_rule_set($variables = array(), $provides = array()) {
......
187 196
/**
188 197
 * Creates an action set.
189 198
 *
190
 * @param $variables
199
 * @param array $variables
191 200
 *   An array as for rule().
192
 * @param $provides
201
 * @param array $provides
193 202
 *   The names of variables which should be provided to the caller. See rule().
203
 *
194 204
 * @return RulesActionSet
195 205
 */
196 206
function rules_action_set($variables = array(), $provides = array()) {
......
202 212
 *
203 213
 * @param $msg
204 214
 *   The message to log.
205
 * @param $args
215
 * @param array $args
206 216
 *   An array of placeholder arguments as used by t().
207 217
 * @param $priority
208 218
 *   A priority as defined by the RulesLog class.
209 219
 * @param RulesPlugin $element
210
 *  (optional) The RulesElement causing the log entry.
211
 * @param boolean $scope
212
 *  (optional) This may be used to denote the beginning (TRUE) or the end
213
 *  (FALSE) of a new execution scope.
220
 *   (optional) The RulesElement causing the log entry.
221
 * @param bool $scope
222
 *   (optional) This may be used to denote the beginning (TRUE) or the end
223
 *   (FALSE) of a new execution scope.
214 224
 */
215 225
function rules_log($msg, $args = array(), $priority = RulesLog::INFO, RulesPlugin $element = NULL, $scope = NULL) {
216 226
  static $logger, $settings;
......
247 257
/**
248 258
 * Fetches module definitions for the given hook name.
249 259
 *
250
 * Used for collecting events, rules, actions and condtions from other modules.
260
 * Used for collecting events, rules, actions and condition from other modules.
251 261
 *
252 262
 * @param $hook
253 263
 *   The hook of the definitions to get from invoking hook_rules_{$hook}.
......
275 285
    if (isset($discover[$hook])) {
276 286
      $data[$hook] += rules_discover_plugins($discover[$hook]);
277 287
    }
278
    drupal_alter('rules_'. $hook, $data[$hook]);
288
    drupal_alter('rules_' . $hook, $data[$hook]);
279 289
  }
280 290
  return $data[$hook];
281 291
}
......
323 333

  
324 334
/**
325 335
 * Determines the module providing the given class.
336
 *
337
 * @param string $class
338
 *   The name of the class or interface plugins to discover.
339
 *
340
 * @return string|false
341
 *   The path of the class, relative to the Drupal installation root,
342
 *   or FALSE if not discovered.
326 343
 */
327 344
function _rules_discover_module($class) {
328 345
  $paths = &drupal_static(__FUNCTION__);
......
340 357
  $path = str_replace(realpath(DRUPAL_ROOT) . DIRECTORY_SEPARATOR, '', realpath(dirname($reflection->getFileName())));
341 358
  $path = DIRECTORY_SEPARATOR != '/' ? str_replace(DIRECTORY_SEPARATOR, '/', $path) : $path;
342 359

  
343
  // Go up the path until we match a module up.
360
  // Go up the path until we match a module.
344 361
  $parts = explode('/', $path);
345 362
  while (!isset($paths[$path]) && array_pop($parts)) {
346 363
    $path = dirname($path);
......
381 398
        }
382 399
      }
383 400
      if ($cid === 'data') {
384
        // There is no 'data' cache so we need to rebuild it. Make sure subsequent
385
        // cache gets of the main 'data' cache during rebuild get the interim
386
        // cache by passing in the reference of the static cache variable.
401
        // There is no 'data' cache so we need to rebuild it. Make sure
402
        // subsequent cache gets of the main 'data' cache during rebuild get
403
        // the interim cache by passing in the reference of the static cache
404
        // variable.
387 405
        _rules_rebuild_cache($cache['data']);
388 406
      }
389 407
      elseif (strpos($cid, 'comp_') === 0) {
......
419 437
 * @see entity_defaults_rebuild()
420 438
 */
421 439
function _rules_rebuild_cache(&$cache) {
422
  foreach(array('data_info', 'plugin_info') as $hook) {
440
  foreach (array('data_info', 'plugin_info') as $hook) {
423 441
    $cache[$hook] = rules_fetch_data($hook);
424 442
  }
425 443
  foreach ($cache['plugin_info'] as $name => &$info) {
......
481 499
}
482 500

  
483 501
/**
484
 * Clears the rule set cache
502
 * Clears the rule set cache.
485 503
 */
486 504
function rules_clear_cache() {
487 505
  cache_clear_all('*', 'cache_rules', TRUE);
......
494 512
/**
495 513
 * Imports the given export and returns the imported configuration.
496 514
 *
497
 * @param $export
515
 * @param string $export
498 516
 *   A serialized string in JSON format as produced by the RulesPlugin::export()
499 517
 *   method, or the PHP export as usual PHP array.
518
 * @param string $error_msg
519
 *
500 520
 * @return RulesPlugin
501 521
 */
502 522
function rules_import($export, &$error_msg = '') {
503 523
  return entity_get_controller('rules_config')->import($export, $error_msg);
504 524
}
505 525

  
506

  
507 526
/**
508 527
 * Wraps the given data.
509 528
 *
......
511 530
 *   If available, the actual data, else NULL.
512 531
 * @param $info
513 532
 *   An array of info about this data.
514
 * @param $force
533
 * @param bool $force
515 534
 *   Usually data is only wrapped if really needed. If set to TRUE, wrapping the
516 535
 *   data is forced, so primitive data types are also wrapped.
536
 *
517 537
 * @return EntityMetadataWrapper
518 538
 *   An EntityMetadataWrapper or the unwrapped data.
519 539
 *
......
554 574
/**
555 575
 * Unwraps the given data, if it's wrapped.
556 576
 *
557
 * @param $data
577
 * @param array $data
558 578
 *   An array of wrapped data.
559
 * @param $info
579
 * @param array $info
560 580
 *   Optionally an array of info about how to unwrap the data. Keyed as $data.
561
 * @return
581
 *
582
 * @return array
562 583
 *   An array containing unwrapped or passed through data.
563 584
 */
564 585
function rules_unwrap_data(array $data, $info = array()) {
......
626 647
 * For a configured event name like node_view--article the base event name
627 648
 * node_view is returned.
628 649
 *
650
 * @param string $event_name
651
 *   A (configured) event name.
652
 *
629 653
 * @return string
630 654
 *   The event base name.
631 655
 */
......
672 696
}
673 697

  
674 698
/**
675
 * Implementation of hook_rules_plugin_info().
699
 * Implements hook_rules_plugin_info().
676 700
 *
677 701
 * Note that the cache is rebuilt in the order of the plugins. Therefore the
678 702
 * condition and action plugins must be at the top, so that any components
......
684 708
    'condition' => array(
685 709
      'class' => 'RulesCondition',
686 710
      'embeddable' => 'RulesConditionContainer',
687
      'extenders' => array (
711
      'extenders' => array(
688 712
        'RulesPluginImplInterface' => array(
689 713
          'class' => 'RulesAbstractPluginDefaults',
690 714
        ),
691
        'RulesPluginFeaturesIntegrationInterace' => array(
715
        'RulesPluginFeaturesIntegrationInterface' => array(
692 716
          'methods' => array(
693 717
            'features_export' => 'rules_features_abstract_default_features_export',
694 718
          ),
......
701 725
    'action' => array(
702 726
      'class' => 'RulesAction',
703 727
      'embeddable' => 'RulesActionContainer',
704
      'extenders' => array (
728
      'extenders' => array(
705 729
        'RulesPluginImplInterface' => array(
706 730
          'class' => 'RulesAbstractPluginDefaults',
707 731
        ),
708
        'RulesPluginFeaturesIntegrationInterace' => array(
732
        'RulesPluginFeaturesIntegrationInterface' => array(
709 733
          'methods' => array(
710 734
            'features_export' => 'rules_features_abstract_default_features_export',
711 735
          ),
......
797 821
}
798 822

  
799 823
/**
800
 * Implementation of hook_entity_info().
824
 * Implements hook_entity_info().
801 825
 */
802 826
function rules_entity_info() {
803 827
  return array(
......
826 850
}
827 851

  
828 852
/**
829
 * Implementation of hook_hook_info().
853
 * Implements hook_hook_info().
830 854
 */
831 855
function rules_hook_info() {
832
  foreach(array('plugin_info', 'rules_directory', 'data_info', 'condition_info', 'action_info', 'event_info', 'file_info', 'evaluator_info', 'data_processor_info') as $hook) {
856
  foreach (array('plugin_info', 'rules_directory', 'data_info', 'condition_info', 'action_info', 'event_info', 'file_info', 'evaluator_info', 'data_processor_info') as $hook) {
833 857
    $hooks['rules_' . $hook] = array(
834 858
      'group' => 'rules',
835 859
    );
......
856 880
 * @see hook_entity_info()
857 881
 * @see RulesEntityController
858 882
 *
859
 * @param $names
883
 * @param array|false $names
860 884
 *   An array of rules configuration names or FALSE to load all.
861
 * @param $conditions
885
 * @param array $conditions
862 886
 *   An array of conditions in the form 'field' => $value.
863 887
 *
864
 * @return
888
 * @return array
865 889
 *   An array of rule configurations indexed by their ids.
866 890
 */
867 891
function rules_config_load_multiple($names = array(), $conditions = array()) {
......
889 913
 *   Whether to return only the label or the whole component object.
890 914
 * @param $type
891 915
 *   Optionally filter for 'action' or 'condition' components.
892
 * @param $conditions
916
 * @param array $conditions
893 917
 *   An array of additional conditions as required by rules_config_load().
894 918
 *
895
 * @return
919
 * @return array
896 920
 *   An array keyed by component name containing either the label or the config.
897 921
 */
898 922
function rules_get_components($label = FALSE, $type = NULL, $conditions = array()) {
......
915 939
/**
916 940
 * Delete rule configurations from database.
917 941
 *
918
 * @param $ids
942
 * @param array $ids
919 943
 *   An array of entity IDs.
920 944
 */
921 945
function rules_config_delete(array $ids) {
......
925 949
/**
926 950
 * Ensures the configuration's 'dirty' flag is up to date by running an integrity check.
927 951
 *
928
 * @param $update
952
 * @param bool $update
929 953
 *   (optional) Whether the dirty flag is also updated in the database if
930 954
 *   necessary. Defaults to TRUE.
931 955
 */
932 956
function rules_config_update_dirty_flag($rules_config, $update = TRUE) {
933 957
  // Keep a log of already check configurations to avoid repetitive checks on
934
  // oftent used components.
958
  // often used components.
935 959
  // @see rules_element_invoke_component_validate()
936 960
  $checked = &drupal_static(__FUNCTION__, array());
937 961
  if (!empty($checked[$rules_config->name])) {
......
978 1002
 * @param ...
979 1003
 *   Arguments to pass to the hook / event.
980 1004
 *
981
 * @return
1005
 * @return array
982 1006
 *   An array of return values of the hook implementations. If modules return
983 1007
 *   arrays from their implementations, those are merged into one array.
984 1008
 */
......
1039 1063
 *
1040 1064
 * @param $event_name
1041 1065
 *   The event's name.
1042
 * @param $args
1066
 * @param array $args
1043 1067
 *   An array of parameters for the variables provided by the event, as defined
1044 1068
 *   in hook_rules_event_info(). Either pass an array keyed by the variable
1045 1069
 *   names or a numerically indexed array, in which case the ordering of the
......
1070 1094
 * @param $args
1071 1095
 *   Pass further parameters as required for the invoked component.
1072 1096
 *
1073
 * @return
1097
 * @return array
1074 1098
 *   An array of variables as provided by the component, or FALSE in case the
1075 1099
 *   component could not be executed.
1076 1100
 */
......
1084 1108
}
1085 1109

  
1086 1110
/**
1087
 * Filters the given array of arrays by keeping only entries which have $key set
1088
 * to the value of $value.
1111
 * Filters the given array of arrays.
1112
 *
1113
 * This filter operates by keeping only entries which have $key set to the
1114
 * value of $value.
1089 1115
 *
1090
 * @param $array
1116
 * @param array $array
1091 1117
 *   The array of arrays to filter.
1092 1118
 * @param $key
1093 1119
 *   The key used for the comparison.
......
1109 1135
}
1110 1136

  
1111 1137
/**
1112
 * Merges the $update array into $array making sure no values of $array not
1113
 * appearing in $update are lost.
1138
 * Merges the $update array into $array.
1114 1139
 *
1115
 * @return
1140
 * Makes sure no values of $array not appearing in $update are lost.
1141
 *
1142
 * @return array
1116 1143
 *   The updated array.
1117 1144
 */
1118 1145
function rules_update_array(array $array, array $update) {
......
1130 1157
/**
1131 1158
 * Extracts the property with the given name.
1132 1159
 *
1133
 * @param $arrays
1160
 * @param array $arrays
1134 1161
 *   An array of arrays from which a property is to be extracted.
1135 1162
 * @param $key
1136 1163
 *   The name of the property to extract.
1137 1164
 *
1138
 * @return An array of extracted properties, keyed as in $arrays-
1165
 * @return array
1166
 *   An array of extracted properties, keyed as in $arrays.
1139 1167
 */
1140 1168
function rules_extract_property($arrays, $key) {
1141 1169
  $data = array();
......
1160 1188
 *
1161 1189
 * @param $replacements
1162 1190
 *   An array of token replacements that need to be "cleaned" for use in the URL.
1163
 * @param $data
1191
 * @param array $data
1164 1192
 *   An array of objects used to generate the replacements.
1165
 * @param $options
1193
 * @param array $options
1166 1194
 *   An array of options used to generate the replacements.
1167 1195
 *
1168 1196
 * @see rules_path_action_info()
......
1269 1297

  
1270 1298
/**
1271 1299
 * Menu callback for loading rules configuration elements.
1300
 *
1272 1301
 * @see RulesUIController::config_menu()
1273 1302
 */
1274 1303
function rules_element_load($element_id, $config_name) {
......
1278 1307

  
1279 1308
/**
1280 1309
 * Menu callback for getting the title as configured.
1310
 *
1281 1311
 * @see RulesUIController::config_menu()
1282 1312
 */
1283 1313
function rules_get_title($text, $element) {
......
1296 1326
 * Menu callback for getting the title for the add element page.
1297 1327
 *
1298 1328
 * Uses a work-a-round for accessing the plugin name.
1329
 *
1299 1330
 * @see RulesUIController::config_menu()
1300 1331
 */
1301 1332
function rules_menu_add_element_title($array) {
......
1388 1419
 * Returns whether the debug log should be shown.
1389 1420
 */
1390 1421
function rules_show_debug_output() {
1391
  if (variable_get('rules_debug', FALSE) == RulesLog::INFO && user_access('access rules debug')) {
1422
  // For performance avoid unnecessary auto-loading of the RulesLog class.
1423
  if (!class_exists('RulesLog', FALSE)) {
1424
    return FALSE;
1425
  }
1426
  if (variable_get('rules_debug', 0) == RulesLog::INFO && user_access('access rules debug')) {
1392 1427
    return TRUE;
1393 1428
  }
1394
  // For performance avoid unnecessary auto-loading of the RulesLog class.
1395
  return variable_get('rules_debug', FALSE) == RulesLog::WARN && user_access('access rules debug') && class_exists('RulesLog', FALSE) && RulesLog::logger()->hasErrors();
1429
  return variable_get('rules_debug', 0) == RulesLog::WARN && user_access('access rules debug') && RulesLog::logger()->hasErrors();
1396 1430
}
1397 1431

  
1398 1432
/**
......
1499 1533
      ->fields('r')
1500 1534
      ->condition('id', $ids, 'IN')
1501 1535
      ->condition('active', 1)
1502
      ->execute()->rowCount();
1536
      ->countQuery()
1537
      ->execute()
1538
      ->fetchField();
1503 1539
    if ($count > 0) {
1504 1540
      $message = format_plural($count,
1505 1541
        '1 Rules configuration requires some of the disabled modules to function and cannot be executed any more.',
1506
        '@count Rules configuration require some of the disabled modules to function and cannot be executed any more.'
1542
        '@count Rules configurations require some of the disabled modules to function and cannot be executed any more.'
1507 1543
      );
1508 1544
      drupal_set_message($message, 'warning');
1509 1545
    }
......
1584 1620
/**
1585 1621
 * Helper function to keep track of external documentation pages for Rules.
1586 1622
 *
1587
 * @param $topic
1623
 * @param string $topic
1588 1624
 *   The topic key for used for identifying help pages.
1589 1625
 *
1590
 * @return
1626
 * @return string|array|false
1591 1627
 *   Either a URL for the given page, or the full list of external help pages.
1592 1628
 */
1593 1629
function rules_external_help($topic = NULL) {
1594 1630
  $help = array(
1595
    'rules' =>                'http://drupal.org/node/298480',
1596
    'terminology' =>          'http://drupal.org/node/1299990',
1597
    'condition-components' => 'http://drupal.org/node/1300034',
1598
    'data-selection' =>       'http://drupal.org/node/1300042',
1599
    'chained-tokens' =>       'http://drupal.org/node/1300042',
1600
    'loops' =>                'http://drupal.org/node/1300058',
1601
    'components' =>           'http://drupal.org/node/1300024',
1602
    'component-types' =>      'http://drupal.org/node/1300024',
1603
    'variables' =>            'http://drupal.org/node/1300024',
1604
    'scheduler' =>            'http://drupal.org/node/1300068',
1605
    'coding' =>               'http://drupal.org/node/878720',
1631
    'rules' =>                'https://www.drupal.org/node/298480',
1632
    'terminology' =>          'https://www.drupal.org/node/1299990',
1633
    'condition-components' => 'https://www.drupal.org/node/1300034',
1634
    'data-selection' =>       'https://www.drupal.org/node/1300042',
1635
    'chained-tokens' =>       'https://www.drupal.org/node/1300042',
1636
    'loops' =>                'https://www.drupal.org/node/1300058',
1637
    'components' =>           'https://www.drupal.org/node/1300024',
1638
    'component-types' =>      'https://www.drupal.org/node/1300024',
1639
    'variables' =>            'https://www.drupal.org/node/1300024',
1640
    'scheduler' =>            'https://www.drupal.org/node/1300068',
1641
    'coding' =>               'https://www.drupal.org/node/878720',
1606 1642
  );
1607 1643

  
1608 1644
  if (isset($topic)) {
......
1704 1740
 * when Drupal is not fully bootstrapped. It gets enabled in rules_init() and
1705 1741
 * rules_enable().
1706 1742
 *
1707
 * @param bool|NULL $enable
1743
 * @param bool|null $enable
1708 1744
 *   NULL to leave the setting as is and TRUE / FALSE to change the behaviour.
1709 1745
 *
1710 1746
 * @return bool

Formats disponibles : Unified diff