Active
Project:
Mockable: Mock objects for Drupal
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
29 Sep 2013 at 12:11 UTC
Updated:
29 Sep 2013 at 12:24 UTC
Here is an example with the current mockable_time module's implementation of the mockable_info_submit hook:
function mockable_time_mockable_info_submit($form, &$form_state) {
if ($form_state['complete form']['mockable_time_time_main']['#value']) {
$time = $form_state['complete form']['mockable_time_time_fieldset']['mockable_time_time']['#value'];
$old_time = $form_state['complete form']['mockable_time_time_fieldset']['mockable_time_time']['#default_value'];
if ($time != $old_time) {
variable_set('mockable_time_time', strtotime('Wed Nov 09 2011 ' . $time));
drupal_set_message(t('Now simulating the time @t.', array('@t' => $time)));
}
variable_set('mockable_time_javascript', $form_state['complete form']['mockable_time_time_fieldset']['mockable_time_javascript']['#value'] * 10);
}
}
If one wants to change mockable time settings outside the form API, one must examine the code and figure out which variables to set, and set them, at which point no validation is done. This approach is rampant throughout Drupal, but wrong (see the soon-to-be-published http://dcycleproject.org/node/27): changing settings through the API or the FAPI should be on the same footing.