Mailinglist
 All Data Structures Files Functions Variables Pages
MailinglistExportUI.class.php
Go to the documentation of this file.
1 <?php
11 abstract class MailinglistExportUI extends ctools_export_ui {
35  public function edit_form(&$form, &$form_state) {
36  $form_state['orig_item'] = clone($form_state['item']);
37  // Check if we need to rebuild object to change its type.
38 
39  if (isset($form_state['input']['object_type']) && $form_state['input']['object_type'] != $form_state['item']->object_type) {
40  // Request Type different than current type lets change it to get right menu
41  $export_type = $form_state['item']->export_type;
42  $schema = ctools_export_get_schema($form_state['plugin']['schema']);
43  $data = (array) $form_state['item'];
45  $data = mailinglist_array_merge_recursive_distinct($data, $form_state['input']);
46  dpm($schema);
47  dpm($form_state);
48  dpm($data);
49  // Serialize the fields that need it
50  foreach ($schema['fields'] as $field => $field_schema) {
51  if (isset($field_schema['serialize']) && $field_schema['serialize']) {
52  $data[$field] = serialize($data[$field]);
53  }
54  }
55  $data = (object)$data;
56  $form_state['item'] = _mailinglist_object_factory($schema, $data);
57  $form_state['item']->export_type = $export_type;
58  }
59  parent::edit_form($form, $form_state);
60 
61  // disable caching as it gets in the way of changing the object's type.
63  $form_state['no_cache'] = TRUE;
64 
65  if (method_exists($form_state['item'], 'edit_form')) {
66  $form_state['item']->edit_form($form, $form_state);
67  }
68 
69  $form['info']['object_type_menu'] = array(
70  '#type' => 'hidden',
71  '#value' => isset($form_state['item']->object_type) ? $form_state['item']->object_type : NULL,
72  );
73  }
74 
78  function edit_form_validate(&$form, &$form_state) {
79  dpm($form_state, 'mailinglist_export_ui::edit_form_validate');
80  if ($form_state['input']['object_type_menu'] != $form_state['input']['object_type']) {
82  form_set_error('object_type', 'Type Changed, Check Settings!');
83  watchdog('Mailinglist', 'Type Change Verify', array(), WATCHDOG_DEBUG);
84  }
85 
86  parent::edit_form_validate($form, $form_state);
87 
88  if (method_exists($form_state['item'], 'edit_form_validate')) {
89  $form_state['item']->edit_form_validate($form, $form_state);
90  }
91  }
92 
96  function edit_form_submit(&$form, &$form_state) {
97  dpm($form_state, 'mailinglist_export_ui::edit_form_submit');
98  // Do our hook before parent:: as parent copies over item, and there may be values there we want save in settings.
99  if (method_exists($form_state['item'], 'edit_form_submit')) {
100  $form_state['item']->edit_form_submit($form, $form_state);
101  }
102 
103  watchdog('mailinglist form', 'xx', array(), WATCHDOG_DEBUG );
104  watchdog('mailinglist state', 'xx', array(), WATCHDOG_DEBUG );
105  parent::edit_form_submit($form, $form_state);
106  }
107 
108  /*
109  * Implements ctools_export_ui::edit_save_form()
110  *
111  * Called on saving object (which is the main part of ctools_export)ui::edit_save_form()
112  * generate hooks on items being created or changed.
113  */
114  function edit_save_form($form_state) {
115  dpm(debug_backtrace(), 'mailinglist_export_ui::edit_save_form()');
116 
117  // This call will end up doing the actual form save
118  parent::edit_save_form($form_state);
119 
120  $item = &$form_state['item'];
121  if ($form_state['op'] == 'add') {
122  $item->table = $this->plugin['schema']; // New objects don't seem to get a table item.
123  $item->created();
124  }
125  else {
126  $orig_item = $form_state['orig_item'];
127  if ($item->object_type != $orig_item->object_type) {
128  $item->changedType($orig_item);
129  }
130 
131  $item->edited($orig_item);
132  }
133  }
134 
140  function delete_form_submit(&$form_state) {
141  $item = $form_state['item'];
142  dpm($item, 'Delete');
143  $item->delete();
144  parent::delete_form_submit($form_state);
145  }
147  /* Add any other hooks that might be needed here, like above */
148 
149 };
150 
151 
edit_form_validate(&$form, &$form_state)
Implements ctools_export_ui::edit_form_validate().
mailinglist_array_merge_recursive_distinct(array &$array1, array &$array2)
array_merge_recursive does indeed merge arrays, but it converts values with duplicate keys to arrays ...
Place for common code for export_ui classes Forwards a lot of ctools_export_ui hooks to the exportabl...
edit_form_submit(&$form, &$form_state)
Implements ctools_export_ui::edit_form_submit().
delete_form_submit(&$form_state)
Implements ctools_export_ui::delete_form_submit().
_mailinglist_object_factory($schema, $data)
Builds an type variable object from a database table entry.
edit_form(&$form, &$form_state)
Implements ctools_export_ui::edit_form().