insert.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Insert module integration.
  5. */
  6. /**
  7. * Implements hook_insert_styles().
  8. */
  9. function custom_formatters_insert_styles() {
  10. $insert_styles = array();
  11. $supported = array('image', 'file');
  12. $settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
  13. foreach (custom_formatters_crud_load_all() as $formatter) {
  14. if (array_intersect($supported, drupal_explode_tags($formatter->field_types))) {
  15. $label = $settings['label_prefix'] ? "{$settings['label_prefix_value']}: {$formatter->label}" : $formatter->label;
  16. $insert_styles["custom_formatters_{$formatter->name}"] = array(
  17. 'label' => $label,
  18. );
  19. }
  20. }
  21. return $insert_styles;
  22. }
  23. /**
  24. * Implements hook_insert_content().
  25. */
  26. function custom_formatters_insert_content($item, $style, $widget) {
  27. $menu_item = menu_get_item();
  28. $form_build_id = end($menu_item['page_arguments']);
  29. if (is_string($form_build_id)) {
  30. $form = form_get_cache($form_build_id, $form_state = array());
  31. $obj_type = $form['#entity_type'];
  32. $object = $form["#{$obj_type}"];
  33. $field = field_info_field($menu_item['page_arguments'][0]);
  34. $instance = field_info_instance($obj_type, $field['field_name'], $form['#bundle']);
  35. $langcode = field_language($obj_type, $object, $field['field_name']);
  36. $items = array((array) file_load($item['fid']));
  37. $display = $instance['display']['default'];
  38. $formatter = custom_formatters_crud_load(drupal_substr($style['name'], 18));
  39. $display['cf_options'] = array(
  40. '#contextual_links' => FALSE,
  41. );
  42. return render(custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter));
  43. }
  44. return FALSE;
  45. }