Reviewed & tested by the community
Project:
Image javascript crop
Version:
7.x-1.x-dev
Component:
Javascript
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Feb 2014 at 04:10 UTC
Updated:
22 Jul 2020 at 14:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
almc commentedComment #2
almc commentedComment #3
ianthomas_ukWhat version are you running? This sounds like #1294890: Media module support broken for media-2.x branch (fixed in dev but not RC3).
Comment #4
almc commentedYes, I tried rc3 version, I'll try the current dev version then, thank you.
Comment #5
seanrEven 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.
Comment #6
seanrComment #7
seanrPlease 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
Comment #8
jeebsuk commentedI'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.
Comment #9
aasarava commentedI 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.
Comment #10
haleagar commentedaasarava
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.
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.
Comment #11
girishmuraly commentedHere 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.

Comment #12
haleagar commentedOK 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.
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.
Comment #13
girishmuraly commentedI 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.
Comment #14
haleagar commentedIt'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.
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.
Comment #15
haleagar commentedHere is my patch to imagecrop 7.x-1.0-rc3+68-dev
For compatibility with Media 7.x-2.0-alpha3+80-dev
Comment #16
girishmuraly commentedAh, 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!
Comment #17
dave.erwin commentedpatch in #15 worked for me
Comment #18
ianthomas_ukIf anyone knows which media issues/commits broke this then it would help for reviewing that the changes suggested are correct and permanent.
Comment #19
slippast commentedI 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!
Comment #20
akalam commentedI 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.
Comment #21
akalam commentedMy fault! the bug i mentioned in #20 happend to me anyway with the imagecrop module disabled, so, I said nothing :)
Comment #22
brunodboPatch 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.
Comment #23
wpatt commentedIt 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.
Comment #24
wpatt commentedOops, patch in #23 accidentally reverted 98d1faa
Comment #25
lunazoid commented#24 worked for me with Media 7.x-2.0-alpha4.
Comment #26
legovaerI tested the patch in #24 and it fixes the issue with the latest version in the dev branch. RTBC I'd say.
Comment #27
wranvaud commented+1 for #24 on latest 7.x-2.26.