Révision 950416da
Ajouté par Assos Assos il y a plus de 5 ans
drupal7/sites/all/modules/rules/ui/ui.core.inc | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
/** |
4 |
* @file Contains core ui functions. |
|
4 |
* @file |
|
5 |
* Contains core Rules UI functions. |
|
5 | 6 |
*/ |
6 | 7 |
|
7 | 8 |
/** |
... | ... | |
10 | 11 |
interface RulesPluginUIInterface { |
11 | 12 |
|
12 | 13 |
/** |
13 |
* Adds the whole configuration form of this rules configuration. For rule |
|
14 |
* elements that are part of a configuration this method just adds the |
|
15 |
* elements configuration form. |
|
14 |
* Adds the whole configuration form of this rules configuration. |
|
15 |
* |
|
16 |
* For rule elements that are part of a configuration this method just adds |
|
17 |
* the elements configuration form. |
|
16 | 18 |
* |
17 | 19 |
* @param $form |
18 | 20 |
* The form array where to add the form. |
... | ... | |
37 | 39 |
* - 'restrict events': Optionally set an array of event names to restrict |
38 | 40 |
* the events that are available for adding. |
39 | 41 |
* |
40 |
* @todo |
|
41 |
* Implement the 'restrict *' options. |
|
42 |
* @todo Implement the 'restrict *' options. |
|
42 | 43 |
*/ |
43 | 44 |
public function form(&$form, &$form_state, $options = array()); |
44 | 45 |
|
... | ... | |
51 | 52 |
public function form_validate($form, &$form_state); |
52 | 53 |
|
53 | 54 |
/** |
55 |
* Form submit handler for the element configuration form. |
|
56 |
* |
|
54 | 57 |
* Submit the configuration form of this rule element. This makes sure to |
55 | 58 |
* put the updated configuration in the form state. For saving changes |
56 | 59 |
* permanently, just call $config->save() afterwards. |
... | ... | |
135 | 138 |
} |
136 | 139 |
return isset($this->index[$id]) ? $this->index[$id] : FALSE; |
137 | 140 |
} |
141 |
|
|
138 | 142 |
} |
139 | 143 |
|
140 | 144 |
/** |
141 |
* Faces UI extender for all kind of Rules plugins. Provides various useful |
|
142 |
* methods for any rules UI. |
|
145 |
* Faces UI extender for all kind of Rules plugins. |
|
146 |
* |
|
147 |
* Provides various useful methods for any rules UI. |
|
143 | 148 |
*/ |
144 | 149 |
class RulesPluginUI extends FacesExtender implements RulesPluginUIInterface { |
145 | 150 |
|
... | ... | |
149 | 154 |
protected $element; |
150 | 155 |
|
151 | 156 |
/** |
152 |
* The base path determines where a Rules overview UI lives. All forms that |
|
153 |
* want to display Rules (overview) forms need to set this variable. This is |
|
154 |
* necessary in order to get correct operation links, paths, redirects, bread |
|
155 |
* crumbs etc. for the form() and overviewTable() methods. |
|
157 |
* The base path determines where a Rules overview UI lives. |
|
158 |
* |
|
159 |
* All forms that want to display Rules (overview) forms need to set this |
|
160 |
* variable. This is necessary in order to get correct operation links, |
|
161 |
* paths, redirects, breadcrumbs etc. for the form() and overviewTable() methods. |
|
156 | 162 |
* |
157 | 163 |
* @see RulesUIController |
158 | 164 |
* @see rules_admin_reaction_overview() |
... | ... | |
193 | 199 |
} |
194 | 200 |
|
195 | 201 |
/** |
196 |
* Implements RulesPluginUIInterface. |
|
197 |
* Generates the element edit form. |
|
202 |
* Implements RulesPluginUIInterface. Generates the element edit form. |
|
198 | 203 |
* |
199 | 204 |
* Note: Make sure that you set RulesPluginUI::$basePath before using this |
200 | 205 |
* method, otherwise paths, links, redirects etc. won't be correct. |
... | ... | |
257 | 262 |
); |
258 | 263 |
} |
259 | 264 |
if (!empty($form['provides'])) { |
260 |
$help = '<div class="description">' . t('Adjust the names and labels of provided variables, but note that renaming of already utilizied variables invalidates the existing uses.') . '</div>';
|
|
265 |
$help = '<div class="description">' . t('Adjust the names and labels of provided variables, but note that renaming of already utilized variables invalidates the existing uses.') . '</div>'; |
|
261 | 266 |
$form['provides'] += array( |
262 | 267 |
'#tree' => TRUE, |
263 | 268 |
'#prefix' => '<h4 class="rules-form-heading">' . t('Provided variables') . '</h4>' . $help, |
... | ... | |
304 | 309 |
} |
305 | 310 |
|
306 | 311 |
// For translatable parameters, pre-populate an internal translation source |
307 |
// key so data type forms or input evaluators (i18n) may produce suiting
|
|
308 |
// help. |
|
312 |
// key so data type forms or input evaluators (i18n) may show a suitable
|
|
313 |
// help message.
|
|
309 | 314 |
if (drupal_multilingual() && !empty($info['translatable'])) { |
310 | 315 |
$parameter = $this->element->pluginParameterInfo(); |
311 | 316 |
$info['custom translation language'] = !empty($parameter['language']); |
... | ... | |
320 | 325 |
} |
321 | 326 |
|
322 | 327 |
// Add a link for switching the input mode when JS is enabled and a button |
323 |
// to switch it without javascript, in case switching is possible.
|
|
328 |
// to switch it without JavaScript, in case switching is possible.
|
|
324 | 329 |
if ($supports_input_mode && empty($info['restriction'])) { |
325 | 330 |
$value = $mode == 'selector' ? t('Switch to the direct input mode') : t('Switch to data selection'); |
326 | 331 |
|
... | ... | |
420 | 425 |
'#required' => TRUE, |
421 | 426 |
'#weight' => -5, |
422 | 427 |
); |
423 |
// @todo: For Drupal 8 use "owner" for generating machine names and
|
|
428 |
// @todo For Drupal 8 use "owner" for generating machine names and |
|
424 | 429 |
// module only for the modules providing default configurations. |
425 | 430 |
if (!empty($this->element->module) && !empty($this->element->name) && $this->element->module == 'rules' && strpos($this->element->name, 'rules_') === 0) { |
426 | 431 |
// Remove the Rules module prefix from the machine name. |
... | ... | |
457 | 462 |
$description = t('The variables used by the component. They can not be edited for configurations that are provided in code.'); |
458 | 463 |
} |
459 | 464 |
else { |
460 |
$description = t('Variables are normally input <em>parameters</em> for the component – data that should be available for the component to act on. Additionaly, action components may <em>provide</em> variables back to the caller. Each variable must have a specified data type, a label and a unique machine readable name containing only lowercase alphanumeric characters and underscores. See <a href="@url">the online documentation</a> for more information about variables.', |
|
465 |
$description = t('Variables are normally input <em>parameters</em> for the component – data that should be available for the component to act on. Additionally, action components may <em>provide</em> variables back to the caller. Each variable must have a specified data type, a label and a unique machine readable name containing only lowercase alphanumeric characters and underscores. See <a href="@url">the online documentation</a> for more information about variables.',
|
|
461 | 466 |
array('@url' => rules_external_help('variables')) |
462 | 467 |
); |
463 | 468 |
} |
... | ... | |
502 | 507 |
'#type' => 'checkbox', |
503 | 508 |
'#title' => t('Configure access for using this component with a permission.'), |
504 | 509 |
'#default_value' => !empty($this->element->access_exposed), |
505 |
'#description' => t('By default, the @plugin-type for using this component may be only used by users that have access to configure the component. If checked, access is determined by a permission instead.', array('@plugin-type' => $plugin_type)) |
|
510 |
'#description' => t('By default, the @plugin-type for using this component may be only used by users that have access to configure the component. If checked, access is determined by a permission instead.', array('@plugin-type' => $plugin_type)),
|
|
506 | 511 |
); |
507 | 512 |
$form['settings']['access']['permissions'] = array( |
508 | 513 |
'#type' => 'container', |
... | ... | |
516 | 521 |
} |
517 | 522 |
} |
518 | 523 |
|
519 |
// TODO: Attach field form thus description.
|
|
524 |
// @todo Attach field form thus description.
|
|
520 | 525 |
} |
521 | 526 |
|
522 | 527 |
/** |
... | ... | |
567 | 572 |
$form_values = RulesPluginUI::getFormStateValues($form['settings'], $form_state); |
568 | 573 |
$this->element->label = $form_values['label']; |
569 | 574 |
// If the name was changed we have to redirect to the URL that contains |
570 |
// the new name, instead of rebuilding on the old URL with the old name |
|
575 |
// the new name, instead of rebuilding on the old URL with the old name.
|
|
571 | 576 |
if ($form['settings']['name']['#default_value'] != $form_values['name']) { |
572 | 577 |
$module = isset($this->element->module) ? $this->element->module : 'rules'; |
573 | 578 |
$this->element->name = $module . '_' . $form_values['name']; |
... | ... | |
669 | 674 |
* Returns the name of class for the given data type. |
670 | 675 |
* |
671 | 676 |
* @param $data_type |
672 |
* The name of the data typ |
|
677 |
* The name of the data type
|
|
673 | 678 |
* @param $parameter_info |
674 | 679 |
* (optional) An array of info about the to be configured parameter. If |
675 | 680 |
* given, this array is complemented with data type defaults also. |
... | ... | |
689 | 694 |
|
690 | 695 |
/** |
691 | 696 |
* Implements RulesPluginUIInterface. |
692 |
* Show a preview of the configuration settings. |
|
697 |
* |
|
698 |
* Shows a preview of the configuration settings. |
|
693 | 699 |
*/ |
694 | 700 |
public function buildContent() { |
695 | 701 |
$config_name = $this->element->root()->name; |
... | ... | |
698 | 704 |
'#title' => $this->element->label(), |
699 | 705 |
'#href' => $this->element->isRoot() ? RulesPluginUI::path($config_name) : RulesPluginUI::path($config_name, 'edit', $this->element), |
700 | 706 |
'#prefix' => '<div class="rules-element-label">', |
701 |
'#suffix' => '</div>' |
|
707 |
'#suffix' => '</div>',
|
|
702 | 708 |
); |
703 | 709 |
// Put the elements below in a "description" div. |
704 | 710 |
$content['description'] = array( |
... | ... | |
712 | 718 |
$element = array(); |
713 | 719 |
if (!empty($this->element->settings[$name . ':select'])) { |
714 | 720 |
$element['content'] = array( |
715 |
'#markup' => '[' . $this->element->settings[$name . ':select'] . ']', |
|
721 |
'#markup' => '[' . $this->element->settings[$name . ':select'] . ']',
|
|
716 | 722 |
); |
717 | 723 |
} |
718 | 724 |
elseif (isset($this->element->settings[$name]) && (!isset($parameter['default value']) || $parameter['default value'] != $this->element->settings[$name])) { |
719 | 725 |
$class = $this->getDataTypeClass($parameter['type'], $parameter); |
720 | 726 |
$method = empty($parameter['options list']) ? 'render' : 'renderOptionsLabel'; |
721 |
// We cannot use method_exists() here as it would trigger a PHP bug,
|
|
722 |
// @see http://drupal.org/node/1258284
|
|
727 |
// We cannot use method_exists() here as it would trigger a PHP bug.
|
|
728 |
// @see https://www.drupal.org/node/1258284
|
|
723 | 729 |
$element = call_user_func(array($class, $method), $this->element->settings[$name], $name, $parameter, $this->element); |
724 | 730 |
} |
725 | 731 |
// Only add parameters that are really configured / not default. |
... | ... | |
802 | 808 |
*/ |
803 | 809 |
public function help() {} |
804 | 810 |
|
805 |
|
|
806 | 811 |
/** |
807 | 812 |
* Deprecated by the controllers overviewTable() method. |
808 | 813 |
*/ |
... | ... | |
811 | 816 |
} |
812 | 817 |
|
813 | 818 |
/** |
819 |
* Generates an operation path. |
|
820 |
* |
|
814 | 821 |
* Generates a path using the given operation for the element with the given |
815 | 822 |
* id of the configuration with the given name. |
816 | 823 |
*/ |
... | ... | |
824 | 831 |
else { |
825 | 832 |
$base_path = isset($element) && $element instanceof RulesTriggerableInterface ? 'admin/config/workflow/rules/reaction' : 'admin/config/workflow/rules/components'; |
826 | 833 |
} |
827 |
return implode('/', array_filter(array($base_path . '/manage', $name, $op, $element_id, $parameter))); |
|
834 |
|
|
835 |
// Only append the '/manage' path if it is not already present. |
|
836 |
if (substr($base_path, -strlen('/manage')) != '/manage') { |
|
837 |
$base_path .= '/manage'; |
|
838 |
} |
|
839 |
|
|
840 |
return implode('/', array_filter(array($base_path, $name, $op, $element_id, $parameter))); |
|
828 | 841 |
} |
829 | 842 |
|
830 | 843 |
/** |
831 |
* Determines the default redirect target for an edited/deleted element. This |
|
832 |
* is a parent element which is either a rule or the configuration root. |
|
844 |
* Determines the default redirect target for an edited/deleted element. |
|
845 |
* |
|
846 |
* This is a parent element which is either a rule or the configuration root. |
|
833 | 847 |
*/ |
834 | 848 |
public static function defaultRedirect(RulesPlugin $element) { |
835 | 849 |
while (!$element->isRoot()) { |
... | ... | |
879 | 893 |
->fetchCol('tag'); |
880 | 894 |
return drupal_map_assoc($result); |
881 | 895 |
} |
896 |
|
|
882 | 897 |
} |
883 | 898 |
|
884 | 899 |
/** |
... | ... | |
887 | 902 |
class RulesAbstractPluginUI extends RulesPluginUI { |
888 | 903 |
|
889 | 904 |
/** |
905 |
* Overrides RulesPluginUI::form(). |
|
906 |
* |
|
890 | 907 |
* Overridden to invoke the abstract plugins form alter callback and to add |
891 | 908 |
* the negation checkbox for conditions. |
892 | 909 |
*/ |
... | ... | |
923 | 940 |
form_set_error(implode('][', $e->keys), $e->getMessage()); |
924 | 941 |
} |
925 | 942 |
} |
943 |
|
|
926 | 944 |
} |
927 | 945 |
|
928 | 946 |
/** |
... | ... | |
941 | 959 |
'#tree' => TRUE, |
942 | 960 |
'#theme' => 'rules_elements', |
943 | 961 |
'#empty' => t('None'), |
944 |
'#caption' => t('Elements') |
|
962 |
'#caption' => t('Elements'),
|
|
945 | 963 |
); |
946 | 964 |
$form['elements']['#attributes']['class'][] = 'rules-container-plugin'; |
947 | 965 |
|
948 |
// Recurse over all element childrens or use the provided iterator.
|
|
966 |
// Recurse over all element children or use the provided iterator. |
|
949 | 967 |
$iterator = isset($iterator) ? $iterator : $this->element->elements(); |
950 | 968 |
$root_depth = $this->element->depth(); |
951 | 969 |
foreach ($iterator as $key => $child) { |
... | ... | |
965 | 983 |
); |
966 | 984 |
$form['elements'][$id]['parent_id'] = array( |
967 | 985 |
'#type' => 'hidden', |
968 |
// If another iterator is passed in, the childs parent may not equal
|
|
986 |
// If another iterator is passed in, the child parent may not equal |
|
969 | 987 |
// the current element. Thus ask the child for its parent. |
970 | 988 |
'#default_value' => $child->parentElement()->elementId(), |
971 | 989 |
); |
... | ... | |
1031 | 1049 |
return $render; |
1032 | 1050 |
} |
1033 | 1051 |
|
1034 |
|
|
1035 | 1052 |
public function buildContent() { |
1036 | 1053 |
$content = parent::buildContent(); |
1037 | 1054 |
// Don't link the title for embedded container plugins, except for rules. |
1038 | 1055 |
if (!$this->element->isRoot() && !($this->element instanceof Rule)) { |
1039 |
$content['label']['#type'] = 'markup'; |
|
1040 | 1056 |
$content['label']['#markup'] = check_plain($content['label']['#title']); |
1041 | 1057 |
unset($content['label']['#title']); |
1042 | 1058 |
} |
... | ... | |
1079 | 1095 |
} |
1080 | 1096 |
return $content; |
1081 | 1097 |
} |
1098 |
|
|
1082 | 1099 |
} |
1083 | 1100 |
|
1084 | 1101 |
/** |
... | ... | |
1093 | 1110 |
$form['elements']['#attributes']['class'][] = 'rules-condition-container'; |
1094 | 1111 |
$form['elements']['#caption'] = t('Conditions'); |
1095 | 1112 |
|
1096 |
// By default skip |
|
1113 |
// By default skip.
|
|
1097 | 1114 |
if (!empty($options['init']) && !$this->element->isRoot()) { |
1098 | 1115 |
$config = $this->element->root(); |
1099 | 1116 |
$form['init_help'] = array( |
... | ... | |
1124 | 1141 |
$this->element->negate($form_values['negate']); |
1125 | 1142 |
} |
1126 | 1143 |
} |
1144 |
|
|
1127 | 1145 |
} |
1128 | 1146 |
|
1129 | 1147 |
/** |
... | ... | |
1132 | 1150 |
class RulesActionContainerUI extends RulesContainerPluginUI { |
1133 | 1151 |
|
1134 | 1152 |
public function form(&$form, &$form_state, $options = array(), $iterator = NULL) { |
1135 |
parent::form($form, $form_state, $options, $iterator);
|
|
1153 |
parent::form($form, $form_state, $options, $iterator); |
|
1136 | 1154 |
// Add the add-* operation links. |
1137 | 1155 |
$form['elements']['#add'] = self::addOperations(); |
1138 | 1156 |
$form['elements']['#attributes']['class'][] = 'rules-action-container'; |
1139 | 1157 |
$form['elements']['#caption'] = t('Actions'); |
1140 | 1158 |
} |
1159 |
|
|
1141 | 1160 |
} |
1142 | 1161 |
|
1143 | 1162 |
/** |
... | ... | |
1167 | 1186 |
* (optional) Whether group labels for grouping inside a category should be |
1168 | 1187 |
* return. Defaults to FALSE. |
1169 | 1188 |
* |
1170 |
* @return string|boolean
|
|
1189 |
* @return string|bool |
|
1171 | 1190 |
* The group label to use, or FALSE if none can be found. |
1172 | 1191 |
*/ |
1173 | 1192 |
public static function getItemGroup($item_info, $in_category = FALSE) { |
1174 | 1193 |
if (isset($item_info['category']) && !$in_category) { |
1175 | 1194 |
return self::getCategory($item_info, 'label'); |
1176 | 1195 |
} |
1177 |
else if (!empty($item_info['group'])) {
|
|
1196 |
elseif (!empty($item_info['group'])) { |
|
1178 | 1197 |
return $item_info['group']; |
1179 | 1198 |
} |
1180 | 1199 |
return FALSE; |
... | ... | |
1202 | 1221 |
} |
1203 | 1222 |
|
1204 | 1223 |
/** |
1205 |
* Returns an array of options to use with a select for the items specified |
|
1224 |
* Returns an array of options to use with a select. |
|
1225 |
* |
|
1226 |
* Returns an array of options to use with a selectfor the items specified |
|
1206 | 1227 |
* in the given hook. |
1207 | 1228 |
* |
1208 | 1229 |
* @param $item_type |
... | ... | |
1211 | 1232 |
* @param $items |
1212 | 1233 |
* (optional) An array of items to restrict the options to. |
1213 | 1234 |
* |
1214 |
* @return |
|
1235 |
* @return array
|
|
1215 | 1236 |
* An array of options. |
1216 | 1237 |
*/ |
1217 | 1238 |
public static function getOptions($item_type, $items = NULL) { |
... | ... | |
1219 | 1240 |
$ungrouped = array(); |
1220 | 1241 |
$data = $items ? $items : rules_fetch_data($item_type . '_info'); |
1221 | 1242 |
foreach ($data as $name => $info) { |
1222 |
// Verfiy the current user has access to use it.
|
|
1243 |
// Verify the current user has access to use it.
|
|
1223 | 1244 |
if (!user_access('bypass rules access') && !empty($info['access callback']) && !call_user_func($info['access callback'], $item_type, $name)) { |
1224 | 1245 |
continue; |
1225 | 1246 |
} |
... | ... | |
1256 | 1277 |
} |
1257 | 1278 |
return $ungrouped + $sorted_groups; |
1258 | 1279 |
} |
1280 |
|
|
1259 | 1281 |
} |
1260 | 1282 |
|
1261 | 1283 |
/** |
Formats disponibles : Unified diff
Weekly update of contrib modules