Révision 7e72b748
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/ctools/plugins/export_ui/ctools_export_ui.class.php | ||
---|---|---|
13 | 13 |
* constructor because we are retaining PHP4 compatibility, which |
14 | 14 |
* would require all child classes to implement their own constructor. |
15 | 15 |
*/ |
16 |
function init($plugin) { |
|
16 |
public function init($plugin) {
|
|
17 | 17 |
ctools_include('export'); |
18 | 18 |
|
19 | 19 |
$this->plugin = $plugin; |
... | ... | |
22 | 22 |
/** |
23 | 23 |
* Get a page title for the current page from our plugin strings. |
24 | 24 |
*/ |
25 |
function get_page_title($op, $item = NULL) { |
|
25 |
public function get_page_title($op, $item = NULL) {
|
|
26 | 26 |
if (empty($this->plugin['strings']['title'][$op])) { |
27 | 27 |
return; |
28 | 28 |
} |
... | ... | |
43 | 43 |
* This can be overridden for modules that want to be able to export |
44 | 44 |
* items currently being edited, for example. |
45 | 45 |
*/ |
46 |
function load_item($item_name) { |
|
46 |
public function load_item($item_name) {
|
|
47 | 47 |
$item = ctools_export_crud_load($this->plugin['schema'], $item_name); |
48 | 48 |
return empty($item) ? FALSE : $item; |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
// ------------------------------------------------------------------------ |
52 |
// Menu item manipulation |
|
52 |
// Menu item manipulation.
|
|
53 | 53 |
|
54 | 54 |
/** |
55 | 55 |
* hook_menu() entry point. |
... | ... | |
57 | 57 |
* Child implementations that need to add or modify menu items should |
58 | 58 |
* probably call parent::hook_menu($items) and then modify as needed. |
59 | 59 |
*/ |
60 |
function hook_menu(&$items) { |
|
60 |
public function hook_menu(&$items) {
|
|
61 | 61 |
// During upgrades, the schema can be empty as this is called prior to |
62 | 62 |
// actual update functions being run. Ensure that we can cope with this |
63 | 63 |
// situation. |
... | ... | |
99 | 99 |
* @return |
100 | 100 |
* TRUE if the current user has access, FALSE if not. |
101 | 101 |
*/ |
102 |
function access($op, $item) { |
|
102 |
public function access($op, $item) {
|
|
103 | 103 |
if (!user_access($this->plugin['access'])) { |
104 | 104 |
return FALSE; |
105 | 105 |
} |
... | ... | |
144 | 144 |
* It is unlikely that a child object will need to override this method, |
145 | 145 |
* unless the listing mechanism is going to be highly specialized. |
146 | 146 |
*/ |
147 |
function list_page($js, $input) { |
|
147 |
public function list_page($js, $input) {
|
|
148 | 148 |
$this->items = ctools_export_crud_load_all($this->plugin['schema'], $js); |
149 | 149 |
|
150 | 150 |
// Respond to a reset command by clearing session and doing a drupal goto |
... | ... | |
224 | 224 |
* get the base form and then modify it as necessary to add search |
225 | 225 |
* gadgets for custom fields. |
226 | 226 |
*/ |
227 |
function list_form(&$form, &$form_state) { |
|
227 |
public function list_form(&$form, &$form_state) {
|
|
228 | 228 |
// This forces the form to *always* treat as submitted which is |
229 | 229 |
// necessary to make it work. |
230 | 230 |
$form['#token'] = FALSE; |
... | ... | |
269 | 269 |
'#title' => t('Enabled'), |
270 | 270 |
'#options' => $all + array( |
271 | 271 |
'0' => t('Enabled'), |
272 |
'1' => t('Disabled') |
|
272 |
'1' => t('Disabled'),
|
|
273 | 273 |
), |
274 | 274 |
'#default_value' => 'all', |
275 | 275 |
); |
... | ... | |
324 | 324 |
* It is very rare that a filter form needs validation, but if it is |
325 | 325 |
* needed, override this. |
326 | 326 |
*/ |
327 |
function list_form_validate(&$form, &$form_state) { } |
|
327 |
public function list_form_validate(&$form, &$form_state) { }
|
|
328 | 328 |
|
329 | 329 |
/** |
330 | 330 |
* Submit the filter/sort form. |
... | ... | |
336 | 336 |
* For the most part, you should not need to override this method, as the |
337 | 337 |
* fiddly bits call through to other functions. |
338 | 338 |
*/ |
339 |
function list_form_submit(&$form, &$form_state) { |
|
339 |
public function list_form_submit(&$form, &$form_state) {
|
|
340 | 340 |
// Filter and re-sort the pages. |
341 | 341 |
$plugin = $this->plugin; |
342 | 342 |
|
... | ... | |
381 | 381 |
* @return |
382 | 382 |
* TRUE if the item should be excluded. |
383 | 383 |
*/ |
384 |
function list_filter($form_state, $item) { |
|
384 |
public function list_filter($form_state, $item) {
|
|
385 | 385 |
$schema = ctools_export_get_schema($this->plugin['schema']); |
386 | 386 |
if ($form_state['values']['storage'] != 'all' && $form_state['values']['storage'] != $item->{$schema['export']['export type string']}) { |
387 | 387 |
return TRUE; |
... | ... | |
411 | 411 |
* This widget will search against whatever fields are configured here. By |
412 | 412 |
* default it will attempt to search against the name, title and description fields. |
413 | 413 |
*/ |
414 |
function list_search_fields() { |
|
414 |
public function list_search_fields() {
|
|
415 | 415 |
$fields = array( |
416 | 416 |
$this->plugin['export']['key'], |
417 | 417 |
); |
... | ... | |
432 | 432 |
* Override this if you wish to provide more or change how these work. |
433 | 433 |
* The actual handling of the sorting will happen in build_row(). |
434 | 434 |
*/ |
435 |
function list_sort_options() { |
|
435 |
public function list_sort_options() {
|
|
436 | 436 |
if (!empty($this->plugin['export']['admin_title'])) { |
437 | 437 |
$options = array( |
438 | 438 |
'disabled' => t('Enabled, title'), |
... | ... | |
458 | 458 |
* |
459 | 459 |
* Override this if you need custom CSS for your list. |
460 | 460 |
*/ |
461 |
function list_css() { |
|
461 |
public function list_css() {
|
|
462 | 462 |
ctools_add_css('export-ui-list'); |
463 | 463 |
} |
464 | 464 |
|
465 | 465 |
/** |
466 | 466 |
* Builds the operation links for a specific exportable item. |
467 | 467 |
*/ |
468 |
function build_operations($item) { |
|
468 |
public function build_operations($item) {
|
|
469 | 469 |
$plugin = $this->plugin; |
470 | 470 |
$schema = ctools_export_get_schema($plugin['schema']); |
471 | 471 |
$operations = $plugin['allowed operations']; |
... | ... | |
515 | 515 |
* method, so this is building up a row suitable for theme('table'). |
516 | 516 |
* This doesn't have to be true if you override both. |
517 | 517 |
*/ |
518 |
function list_build_row($item, &$form_state, $operations) { |
|
518 |
public function list_build_row($item, &$form_state, $operations) {
|
|
519 | 519 |
// Set up sorting |
520 | 520 |
$name = $item->{$this->plugin['export']['key']}; |
521 | 521 |
$schema = ctools_export_get_schema($this->plugin['schema']); |
... | ... | |
563 | 563 |
* If you've added columns via list_build_row() but are still using a |
564 | 564 |
* table, override this method to set up the table header. |
565 | 565 |
*/ |
566 |
function list_table_header() { |
|
566 |
public function list_table_header() {
|
|
567 | 567 |
$header = array(); |
568 | 568 |
if (!empty($this->plugin['export']['admin_title'])) { |
569 | 569 |
$header[] = array('data' => t('Title'), 'class' => array('ctools-export-ui-title')); |
... | ... | |
585 | 585 |
* Whatever you do if this method is overridden, the ID is important for AJAX |
586 | 586 |
* so be sure it exists. |
587 | 587 |
*/ |
588 |
function list_render(&$form_state) { |
|
588 |
public function list_render(&$form_state) {
|
|
589 | 589 |
$table = array( |
590 | 590 |
'header' => $this->list_table_header(), |
591 | 591 |
'rows' => $this->rows, |
... | ... | |
600 | 600 |
* |
601 | 601 |
* This will appear after the filter/sort widgets. |
602 | 602 |
*/ |
603 |
function list_header($form_state) { } |
|
603 |
public function list_header($form_state) { }
|
|
604 | 604 |
|
605 | 605 |
/** |
606 | 606 |
* Render a footer to go after thie list. |
607 | 607 |
* |
608 | 608 |
* This is a good place to add additional links. |
609 | 609 |
*/ |
610 |
function list_footer($form_state) { } |
|
610 |
public function list_footer($form_state) { }
|
|
611 | 611 |
|
612 | 612 |
// ------------------------------------------------------------------------ |
613 | 613 |
// These methods are the API for adding/editing exportable items |
... | ... | |
623 | 623 |
* The item in use; this may be necessary as item IDs are often embedded in |
624 | 624 |
* redirects. |
625 | 625 |
*/ |
626 |
function redirect($op, $item = NULL) { |
|
626 |
public function redirect($op, $item = NULL) {
|
|
627 | 627 |
if (isset($this->plugin['redirect'][$op])) { |
628 | 628 |
$destination = (array) $this->plugin['redirect'][$op]; |
629 | 629 |
if ($item) { |
... | ... | |
638 | 638 |
} |
639 | 639 |
} |
640 | 640 |
|
641 |
function add_page($js, $input, $step = NULL) { |
|
641 |
public function add_page($js, $input, $step = NULL) {
|
|
642 | 642 |
drupal_set_title($this->get_page_title('add'), PASS_THROUGH); |
643 | 643 |
|
644 | 644 |
// If a step not set, they are trying to create a new item. If a step |
... | ... | |
675 | 675 |
/** |
676 | 676 |
* Main entry point to edit an item. |
677 | 677 |
*/ |
678 |
function edit_page($js, $input, $item, $step = NULL) { |
|
678 |
public function edit_page($js, $input, $item, $step = NULL) {
|
|
679 | 679 |
drupal_set_title($this->get_page_title('edit', $item), PASS_THROUGH); |
680 | 680 |
|
681 | 681 |
// Check to see if there is a cached item to get if we're using the wizard. |
... | ... | |
711 | 711 |
/** |
712 | 712 |
* Main entry point to clone an item. |
713 | 713 |
*/ |
714 |
function clone_page($js, $input, $original, $step = NULL) { |
|
714 |
public function clone_page($js, $input, $original, $step = NULL) {
|
|
715 | 715 |
drupal_set_title($this->get_page_title('clone', $original), PASS_THROUGH); |
716 | 716 |
|
717 | 717 |
// If a step not set, they are trying to create a new clone. If a step |
... | ... | |
768 | 768 |
* Add and Edit both funnel into this, but they have a few different |
769 | 769 |
* settings. |
770 | 770 |
*/ |
771 |
function edit_execute_form(&$form_state) { |
|
771 |
public function edit_execute_form(&$form_state) {
|
|
772 | 772 |
if (!empty($this->plugin['use wizard'])) { |
773 | 773 |
return $this->edit_execute_form_wizard($form_state); |
774 | 774 |
} |
... | ... | |
782 | 782 |
* |
783 | 783 |
* By default, export UI will provide a single form for editing an object. |
784 | 784 |
*/ |
785 |
function edit_execute_form_standard(&$form_state) { |
|
785 |
public function edit_execute_form_standard(&$form_state) {
|
|
786 | 786 |
$output = drupal_build_form('ctools_export_ui_edit_item_form', $form_state); |
787 | 787 |
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) { |
788 | 788 |
$this->edit_save_form($form_state); |
... | ... | |
803 | 803 |
* @param array $form_state |
804 | 804 |
* The already created form state. |
805 | 805 |
*/ |
806 |
function get_wizard_info(&$form_state) { |
|
806 |
public function get_wizard_info(&$form_state) {
|
|
807 | 807 |
if (!isset($form_state['step'])) { |
808 | 808 |
$form_state['step'] = NULL; |
809 | 809 |
} |
... | ... | |
878 | 878 |
* Using 'add order' or 'edit order' can be used to ensure that add/edit order |
879 | 879 |
* is different. |
880 | 880 |
*/ |
881 |
function edit_execute_form_wizard(&$form_state) { |
|
881 |
public function edit_execute_form_wizard(&$form_state) {
|
|
882 | 882 |
$form_info = $this->get_wizard_info($form_state); |
883 | 883 |
|
884 | 884 |
// If there aren't any forms set, fail. |
... | ... | |
919 | 919 |
* |
920 | 920 |
* The wizard callback delegates this back to the object. |
921 | 921 |
*/ |
922 |
function edit_wizard_back(&$form_state) { |
|
922 |
public function edit_wizard_back(&$form_state) {
|
|
923 | 923 |
// This only exists so child implementations can use it. |
924 | 924 |
} |
925 | 925 |
|
... | ... | |
928 | 928 |
* |
929 | 929 |
* The wizard callback delegates this back to the object. |
930 | 930 |
*/ |
931 |
function edit_wizard_next(&$form_state) { |
|
931 |
public function edit_wizard_next(&$form_state) {
|
|
932 | 932 |
$this->edit_cache_set($form_state['item'], $form_state['form type']); |
933 | 933 |
} |
934 | 934 |
|
... | ... | |
937 | 937 |
* |
938 | 938 |
* The wizard callback delegates this back to the object. |
939 | 939 |
*/ |
940 |
function edit_wizard_cancel(&$form_state) { |
|
940 |
public function edit_wizard_cancel(&$form_state) {
|
|
941 | 941 |
$this->edit_cache_clear($form_state['item'], $form_state['form type']); |
942 | 942 |
} |
943 | 943 |
|
... | ... | |
946 | 946 |
* |
947 | 947 |
* The wizard callback delegates this back to the object. |
948 | 948 |
*/ |
949 |
function edit_wizard_finish(&$form_state) { |
|
949 |
public function edit_wizard_finish(&$form_state) {
|
|
950 | 950 |
$form_state['complete'] = TRUE; |
951 | 951 |
|
952 | 952 |
// If we are importing, and overwrite was selected, delete the original so |
... | ... | |
961 | 961 |
/** |
962 | 962 |
* Retrieve the item currently being edited from the object cache. |
963 | 963 |
*/ |
964 |
function edit_cache_get($item, $op = 'edit') { |
|
964 |
public function edit_cache_get($item, $op = 'edit') {
|
|
965 | 965 |
ctools_include('object-cache'); |
966 | 966 |
if (is_string($item)) { |
967 | 967 |
$name = $item; |
... | ... | |
980 | 980 |
/** |
981 | 981 |
* Cache the item currently currently being edited. |
982 | 982 |
*/ |
983 |
function edit_cache_set($item, $op = 'edit') { |
|
983 |
public function edit_cache_set($item, $op = 'edit') {
|
|
984 | 984 |
ctools_include('object-cache'); |
985 | 985 |
$name = $this->edit_cache_get_key($item, $op); |
986 | 986 |
return $this->edit_cache_set_key($item, $name); |
987 | 987 |
} |
988 | 988 |
|
989 |
function edit_cache_set_key($item, $name) { |
|
989 |
public function edit_cache_set_key($item, $name) {
|
|
990 | 990 |
return ctools_object_cache_set('ctui_' . $this->plugin['name'], $name, $item); |
991 | 991 |
} |
992 | 992 |
|
993 | 993 |
/** |
994 | 994 |
* Clear the object cache for the currently edited item. |
995 | 995 |
*/ |
996 |
function edit_cache_clear($item, $op = 'edit') { |
|
996 |
public function edit_cache_clear($item, $op = 'edit') {
|
|
997 | 997 |
ctools_include('object-cache'); |
998 | 998 |
$name = $this->edit_cache_get_key($item, $op); |
999 | 999 |
return ctools_object_cache_clear('ctui_' . $this->plugin['name'], $name); |
... | ... | |
1002 | 1002 |
/** |
1003 | 1003 |
* Figure out what the cache key is for this object. |
1004 | 1004 |
*/ |
1005 |
function edit_cache_get_key($item, $op) { |
|
1005 |
public function edit_cache_get_key($item, $op) {
|
|
1006 | 1006 |
$export_key = $this->plugin['export']['key']; |
1007 | 1007 |
return $op == 'edit' ? $item->{$this->plugin['export']['key']} : "::$op"; |
1008 | 1008 |
} |
... | ... | |
1010 | 1010 |
/** |
1011 | 1011 |
* Called to save the final product from the edit form. |
1012 | 1012 |
*/ |
1013 |
function edit_save_form($form_state) { |
|
1013 |
public function edit_save_form($form_state) {
|
|
1014 | 1014 |
$item = &$form_state['item']; |
1015 | 1015 |
$export_key = $this->plugin['export']['key']; |
1016 | 1016 |
|
... | ... | |
1029 | 1029 |
/** |
1030 | 1030 |
* Provide the actual editing form. |
1031 | 1031 |
*/ |
1032 |
function edit_form(&$form, &$form_state) { |
|
1032 |
public function edit_form(&$form, &$form_state) {
|
|
1033 | 1033 |
$export_key = $this->plugin['export']['key']; |
1034 | 1034 |
$item = $form_state['item']; |
1035 | 1035 |
$schema = ctools_export_get_schema($this->plugin['schema']); |
... | ... | |
1102 | 1102 |
/** |
1103 | 1103 |
* Validate callback for the edit form. |
1104 | 1104 |
*/ |
1105 |
function edit_form_validate(&$form, &$form_state) { |
|
1105 |
public function edit_form_validate(&$form, &$form_state) {
|
|
1106 | 1106 |
if (!empty($this->plugin['form']['validate'])) { |
1107 | 1107 |
// Pass $form by reference. |
1108 | 1108 |
$this->plugin['form']['validate']($form, $form_state); |
... | ... | |
1113 | 1113 |
* Perform a final validation check before allowing the form to be |
1114 | 1114 |
* finished. |
1115 | 1115 |
*/ |
1116 |
function edit_finish_validate(&$form, &$form_state) { |
|
1116 |
public function edit_finish_validate(&$form, &$form_state) {
|
|
1117 | 1117 |
if ($form_state['op'] != 'edit') { |
1118 | 1118 |
// Validate the export key. Fake an element for form_error(). |
1119 | 1119 |
$export_key = $this->plugin['export']['key']; |
... | ... | |
1135 | 1135 |
* If the keys all match up to the schema, this method will not need to be |
1136 | 1136 |
* overridden. |
1137 | 1137 |
*/ |
1138 |
function edit_form_submit(&$form, &$form_state) { |
|
1138 |
public function edit_form_submit(&$form, &$form_state) {
|
|
1139 | 1139 |
if (!empty($this->plugin['form']['submit'])) { |
1140 | 1140 |
// Pass $form by reference. |
1141 | 1141 |
$this->plugin['form']['submit']($form, $form_state); |
... | ... | |
1157 | 1157 |
/** |
1158 | 1158 |
* Callback to enable a page. |
1159 | 1159 |
*/ |
1160 |
function enable_page($js, $input, $item) { |
|
1160 |
public function enable_page($js, $input, $item) {
|
|
1161 | 1161 |
return $this->set_item_state(FALSE, $js, $input, $item); |
1162 | 1162 |
} |
1163 | 1163 |
|
1164 | 1164 |
/** |
1165 | 1165 |
* Callback to disable a page. |
1166 | 1166 |
*/ |
1167 |
function disable_page($js, $input, $item) { |
|
1167 |
public function disable_page($js, $input, $item) {
|
|
1168 | 1168 |
return $this->set_item_state(TRUE, $js, $input, $item); |
1169 | 1169 |
} |
1170 | 1170 |
|
... | ... | |
1174 | 1174 |
* If javascript is in use, this will rebuild the list and send that back |
1175 | 1175 |
* as though the filter form had been executed. |
1176 | 1176 |
*/ |
1177 |
function set_item_state($state, $js, $input, $item) { |
|
1177 |
public function set_item_state($state, $js, $input, $item) {
|
|
1178 | 1178 |
ctools_export_crud_set_status($this->plugin['schema'], $item, $state); |
1179 | 1179 |
|
1180 | 1180 |
if (!$js) { |
... | ... | |
1188 | 1188 |
/** |
1189 | 1189 |
* Page callback to delete an exportable item. |
1190 | 1190 |
*/ |
1191 |
function delete_page($js, $input, $item) { |
|
1191 |
public function delete_page($js, $input, $item) {
|
|
1192 | 1192 |
$form_state = array( |
1193 | 1193 |
'plugin' => $this->plugin, |
1194 | 1194 |
'object' => &$this, |
... | ... | |
1211 | 1211 |
/** |
1212 | 1212 |
* Deletes exportable items from the database. |
1213 | 1213 |
*/ |
1214 |
function delete_form_submit(&$form_state) { |
|
1214 |
public function delete_form_submit(&$form_state) {
|
|
1215 | 1215 |
$item = $form_state['item']; |
1216 | 1216 |
|
1217 | 1217 |
ctools_export_crud_delete($this->plugin['schema'], $item); |
... | ... | |
1223 | 1223 |
/** |
1224 | 1224 |
* Page callback to display export information for an exportable item. |
1225 | 1225 |
*/ |
1226 |
function export_page($js, $input, $item) { |
|
1226 |
public function export_page($js, $input, $item) {
|
|
1227 | 1227 |
drupal_set_title($this->get_page_title('export', $item), PASS_THROUGH); |
1228 | 1228 |
return drupal_get_form('ctools_export_form', ctools_export_crud_export($this->plugin['schema'], $item), t('Export')); |
1229 | 1229 |
} |
... | ... | |
1231 | 1231 |
/** |
1232 | 1232 |
* Page callback to import information for an exportable item. |
1233 | 1233 |
*/ |
1234 |
function import_page($js, $input, $step = NULL) { |
|
1234 |
public function import_page($js, $input, $step = NULL) {
|
|
1235 | 1235 |
drupal_set_title($this->get_page_title('import'), PASS_THROUGH); |
1236 | 1236 |
// Import is basically a multi step wizard form, so let's go ahead and |
1237 | 1237 |
// use CTools' wizard.inc for it. |
... | ... | |
1272 | 1272 |
* Import form. Provides simple helptext instructions and textarea for |
1273 | 1273 |
* pasting a export definition. |
1274 | 1274 |
*/ |
1275 |
function edit_form_import(&$form, &$form_state) { |
|
1275 |
public function edit_form_import(&$form, &$form_state) {
|
|
1276 | 1276 |
$form['help'] = array( |
1277 | 1277 |
'#type' => 'item', |
1278 | 1278 |
'#value' => $this->plugin['strings']['help']['import'], |
... | ... | |
1298 | 1298 |
* |
1299 | 1299 |
* Evaluates code and make sure it creates an object before we continue. |
1300 | 1300 |
*/ |
1301 |
function edit_form_import_validate($form, &$form_state) { |
|
1301 |
public function edit_form_import_validate($form, &$form_state) {
|
|
1302 | 1302 |
$item = ctools_export_crud_import($this->plugin['schema'], $form_state['values']['import']); |
1303 | 1303 |
if (is_string($item)) { |
1304 | 1304 |
form_error($form['import'], t('Unable to get an import from the code. Errors reported: @errors', array('@errors' => $item))); |
... | ... | |
1315 | 1315 |
* |
1316 | 1316 |
* Stores the item in the session. |
1317 | 1317 |
*/ |
1318 |
function edit_form_import_submit($form, &$form_state) { |
|
1318 |
public function edit_form_import_submit($form, &$form_state) {
|
|
1319 | 1319 |
// The validate function already imported and stored the item. This |
1320 | 1320 |
// function exists simply to prevent it from going to the default |
1321 | 1321 |
// edit_form_submit() method. |
Formats disponibles : Unified diff
Weekly update of contrib modules