While this has been discussed for the D6 version, there's nothing for the D7 version as yet.

The attached patch provides insert module integration with imagefield_crop.

/**
 * Implementation of hook_insert_widgets().
 */
function image_insert_widgets() {
  return array(
    'image_image' => array(
      'element_type' => 'managed_file',
      'wrapper' => '.image-widget',
      'fields' => array(
        'alt' => 'input[name$="[alt]"], textarea[name$="[alt]"]',
        'title' => 'input[name$="[title]"], textarea[name$="[title]"]',
        'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
      ),
    ),
    'imagefield_crop_widget' => array(
      'element_type' => 'managed_file',
      'wrapper' => '.imagefield-crop-widget',
      'fields' => array(
        'alt' => 'input[name$="[alt]"], textarea[name$="[alt]"]',
        'title' => 'input[name$="[title]"], textarea[name$="[title]"]',
        'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
      ),
    ),
  );
}

There's also a required theme markup patch to apply to imagefield_crop to put the elements inside the correct wrapper for insert.js
Posted here: http://drupal.org/node/749272#comment-5967414

or you can use this theme override

/**
 * @ingroup Theme overrides
 * Adjust markup to work with default insert.js
 * See imagefield_crop_imagefield_crop_widget
 */
function THEMENAME_imagefield_crop_widget($variables) {
  $element = $variables['element'];
  $output = '';
  $output .= '<div class="imagefield-crop-widget form-managed-file clearfix">';

  if (isset($element['preview'])) {
    $output .= '<div class="imagefield-crop-preview">';
    $output .= drupal_render($element['preview']);
    $output .= '</div>';
  }
  if (isset($element['cropbox'])) {
    $output .= '<div class="imagefield-crop-cropbox">';
    $output .= drupal_render($element['cropbox']);
    $output .= '</div>';
  }
  if(isset($element['insert'])){
    $output .= drupal_render($element['insert']);
    $output .= drupal_render($element['insert_templates']);
    $output .= drupal_render($element['insert_filename']);
  }
  // For insert to insert the title
  if(isset($element['title'])){
    $output .= drupal_render($element['title']);
  }
  $output .= '</div>';
  $output .= drupal_render_children($element);
  return $output;
}

Thanks for the awesome module.

Cheers,

DT

Comments

davidwhthomas’s picture

Oh, here's the patch ;)

Note, after applying, make sure you edit the image field settings to enable insert for that field.

quicksketch’s picture

Title: D7 support for imagefield_crop widget » D7 ImageField Crop support for Insert
Project: Insert » Imagefield Crop
Status: Needs review » Needs work

Moving this over to ImageField Crop. Insert currently only provides support for the core modules. Other modules may easily put the exact code you've posted in to their own hook_insert_widgets(). Insert is simply providing these hooks *on behalf* of core, since Insert obviously isn't in core itself.

TudorC’s picture

I have a problem with this patch, by trying to add 2 or more images I will always get the first image whenever I click Insert.

rv0’s picture

Just want to add this:
the first image problem seems to have been reported in 2011:
#1240838: imagefield_crop doesnt work with Insert: just

Also, dunno what this is #749272: ImageField Crop / Insert integration

vagelis-prokopiou’s picture

I don't know if I am 100% on topic, but this is how I made the imagefield_crop and the insert modules co-operate (Imagefield Crop Version = 7.x-1.1 && Insert Version = 7.x-1.3).

1. Install and enable both modules.
2. Add an image field to your content type.
3. Under the 'Operations' choose 'Edit' for the image field.
4. In the options, locate the 'Insert' option, and enable the 'Insert button' option from there.
5. Change the widget type to 'image with cropping'.
Now, you will be able to crop your image, and then insert it, if you want, in your body field.

PS: Be sure to install any dependencies that these modules require (e.g. imagemagick).