devel_generate.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @file
  4. * Devel Generate module integration.
  5. */
  6. /**
  7. * Implements hook_custom_formatters_form_alter_alter on behalf of
  8. * devel_generate.module.
  9. */
  10. function devel_generate_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
  11. if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters'])) {
  12. $item = !empty($form_state['values']) ? $form_state['values'] : (array) $form_state['item'];
  13. $entity_type = !empty($item['preview']['entity_type']) ? $item['preview']['entity_type'] : 'node';
  14. $info = module_invoke_all('custom_formatters_devel_generate_info');
  15. if (in_array($entity_type, array_keys($info)) && count($form['engine']['preview']['field']['#options']) > 0) {
  16. $form['engine']['preview']['entity']['#options']['devel_generate'] = 'Devel generate';
  17. $form['engine']['preview']['entity']['#disabled'] = FALSE;
  18. $form['engine']['preview']['button']['#ajax']['callback'] = 'custom_formatters_export_ui_form_js_preview_devel_generate';
  19. $form['engine']['preview']['button']['#disabled'] = FALSE;
  20. }
  21. }
  22. }
  23. /**
  24. * Submit callback for Custom Formatters live preview via Devel Generate.
  25. */
  26. function custom_formatters_export_ui_form_js_preview_devel_generate($form, $form_state) {
  27. $info = module_invoke_all('custom_formatters_devel_generate_info');
  28. if ($form_state['values']['preview']['entity'] !== 'devel_generate' || !function_exists($function = $info[$form_state['values']['preview']['entity_type']]['process callback'])) {
  29. return custom_formatters_export_ui_form_js_preview($form, $form_state);
  30. }
  31. $object = $function($form_state);
  32. return custom_formatters_export_ui_form_js_preview($form, $form_state, $object);
  33. }