Crop this image button appears only after the picture is attached in media widget, which is not intuitive if the cropping has already been applied by default after the file selection but the user doesn't see Crop button until he presses Attach button.
Then, when the button Crop this image appears in media widget and you press it, the preview area for manual cropping is blank in the newly opened window.

Comments

almc’s picture

Issue summary: View changes
almc’s picture

Issue summary: View changes
ianthomas_uk’s picture

What version are you running? This sounds like #1294890: Media module support broken for media-2.x branch (fixed in dev but not RC3).

almc’s picture

Yes, I tried rc3 version, I'll try the current dev version then, thank you.

seanr’s picture

Even with the dev version, I cannot get the crop link to show up when using the multimedia file selector. I don't think it is a duplicate of 1294890. Looks like that issue is looking for the crop tool on the actual file edit page? We really need it on the node edit page where the file is uploaded - the client will never know how to get to it otherwise.

seanr’s picture

Title: Doesn't work with Media 7.x-2.x-dev » Doesn't work with Multimedia File Selector with Media 7.x-2.x-dev
seanr’s picture

Title: Doesn't work with Multimedia File Selector with Media 7.x-2.x-dev » Doesn't work with Media 7.x-2.x-dev

Please disregard my last comment. I had to go here and enable it: admin/config/media/imagecrop. Ufortunately, it still didn't save my crop, but that may be a separate issue that I'll need to investigate further

jeebsuk’s picture

I'm not sure if this is directly related to the original issue raised in here or separate but with the latest dev versions of Media 2 and Imagecrop you get the following JS error:

Uncaught TypeError: Cannot read property 'global' of undefined on line 21 of imagecrop_field_media_v1.js

and no crop button appears next to the appropriate media selector that imagecrop is enabled on.

aasarava’s picture

I think the issue @JeebsUK reported is very relevant. In looking at the code for imagecrop, it seems the module has to completely override one of the Media module's javascript functions: Drupal.behaviors.mediaElement, which it does in imagecrop/js/imagecrop_field_media_v1.js.

In the latest 2.x-dev version of Media, the Drupal.behaviors.mediaElement function was completely overhauled.

Unfortunately, imagecrop's version of that function doesn't clearly denote the changes that were made, so it's not easy to manually reapply the changes to the new version of the function. Perhaps the maintainer or someone who is familiar with what's going in on imagecrop_field_media_v1.js can take a look and give a hand?

Update: In looking at this further, it seems imagecrop_field_media_v1.js shouldn't even be getting attached when using Media 2. In imagecrop.module, there's code that looks for the existence of $element['remove'] as a sign that Media 2 is in use and is supposed to attach the proper imagecrop_field.js file.

Something must have changed in the very latest Media 2.x-dev so that this check no longer works. Unfortunately, simply editing imagecrop.js and forcing imagecrop_field.js to get attached doesn't fix the problem. It gets rid of the js error but doesn't make the Crop button appear.

haleagar’s picture

aasarava
You are right the method to detect old vs new media module seems to be a problem, however for me just fixing the detection so that the old JS is not added fixed things and got things working for me again.

This seems like a bit much to get module version, but it's what I used.

  // get the major revision of the media module
  $mpath = drupal_get_path('module', 'media') . '/' . 'media' . '.info';
  $minfo = drupal_parse_info_file($mpath);
  preg_match("|7.*-(\d)\.|", $minfo['version'], $mver);
  $media_version = $mver[1];

aasarava: what changes did you think were needed in imagecrop.js none were needed for me, try reverting your changes and only blocking imagecrop_field_media_v1.js from being loaded.

girishmuraly’s picture

Status: Active » Needs review
StatusFileSize
new6.6 KB
new40.06 KB

Here is a patch I spent two days working on. It places the 'Crop media' button on the wysiwyg edit media modal too. Also for those who don't see anything in the Crop popup, there is a bit to fix it - it is mostly because your site uses contexts and not the block system to place blocks.

Media: 2.x latest version (changeset: e8f9228fe759ac3cc7ecb0c9c2baa027721f467e of 2014-05-05)
File_entity: 2.0-alpha3

Also attaching a screenshot of my configuration.

haleagar’s picture

OK so forced to update to a newer dev version 7.x-2.0-alpha3+37-dev
Now I'm once again missing the link, poked around and found the problem now in

imagecrop_element_info_alter

['#after_build'] is no longer being triggered. Why I don't know, still learning my way down that path.
however using #process works.

//$type['media']['#after_build'][] = 'imagecrop_process_form_element';
$type['media']['#process'][] = 'imagecrop_process_form_element';

But I suppose the question is why #after_build is broken. I see in your patch girishmuraly that you just deleted "imagecrop_element_info_alter" and just come at it another way. And though I don't know how the wysiwyg edit media modal is built but I see it also tries to use #after_build, so using #process may provide a much simpler workaround to that problem in both cases.

girishmuraly’s picture

I don't feel that 'imagecrop_element_info_alter' is required now that Media has changed its edit modal. Previously it was acting on a field but now it is pulling up a whole new form.

haleagar’s picture

StatusFileSize
new13.75 KB

It's used to generate the link next to the thumb on the node form.
I find a problem with the link on the popup since it opens the imagecrop modal behind the edit modal.
imagecrop_element_info_alter -> imagecrop_process_form_element is responsible for inserting the link here for a file field.
example image crop link

It's also seems required for inserting the iframe if you choose that for the popup window type.

Sorry I was not able to test your patch for WYSIWYG use as I don't have that set up, but it needs to not remove other functionally.

haleagar’s picture

Here is my patch to imagecrop 7.x-1.0-rc3+68-dev
For compatibility with Media 7.x-2.0-alpha3+80-dev

girishmuraly’s picture

Ah, you see haleagar, I don't get those links next to the thumb on fields. What is the field widget you are using. I am using Image with Media Field Selector and see no edit button as well. Hence the confusion!

dave.erwin’s picture

patch in #15 worked for me

ianthomas_uk’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev

If anyone knows which media issues/commits broke this then it would help for reviewing that the changes suggested are correct and permanent.

slippast’s picture

I applied patch #15 for the current dev of Media. With that patch I was also able to get this amazing patch working: https://www.drupal.org/node/951004. So, so awesome!

Thank you!

akalam’s picture

I think #15 has yet a small bug.

If you have an image field, with media widget, and you delete de file (click in the "remove" link) appears a kind of textfield with and a "attach" button that does not work any more, insted of the "explore" button.

Without this behavioiur happen allways without the #15 patch. With the patch still happen after deleting a file, but not when adding a new node.

akalam’s picture

My fault! the bug i mentioned in #20 happend to me anyway with the imagecrop module disabled, so, I said nothing :)

brunodbo’s picture

Patch in #15 applies cleanly against the current Imagecrop 7.x-1.x-dev, and works with Media 7.x-2.0-alpha4. Not sure about which changes in Media caused this though.

wpatt’s picture

It looks like the incompatibility came from this commit in Media 7.x-2.0-alpha4
https://www.drupal.org/node/2187837#comment-8451757

Specifically the 'remove' button was given a new array key and became 'remove_button'. This patch is against imagecrop 7.x-1.0-rc3+68-dev and skips detecting the version of media in favor of checking the changed render array. Perhaps there were some other changes committed since #15 but I am not seeing the #after_build problem that haleagar mentioned.

wpatt’s picture

StatusFileSize
new853 bytes

Oops, patch in #23 accidentally reverted 98d1faa

lunazoid’s picture

#24 worked for me with Media 7.x-2.0-alpha4.

legovaer’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch in #24 and it fixes the issue with the latest version in the dev branch. RTBC I'd say.

wranvaud’s picture

+1 for #24 on latest 7.x-2.26.