If there are two crop tools on one page, it will set Drupal.settings.manualcrop.styles twice which will cause Drupal to turn all the values into arrays.

For example, normally:

Drupal.settings.manualcrop.styles.IMAGESTYLENAME.data.keepproportions === 1

However, with two crop tools on one page, then:

Drupal.settings.manualcrop.styles.IMAGESTYLENAME.data.keepproportions === [1, 1]

Which causes the tool to NOT keep the proportions as it should.

I'll attach a patch in a moment to fix!

CommentFileSizeAuthor
#1 manualcrop-two-crop-tools-2237835.patch933 bytesdsnopek

Comments

dsnopek’s picture

Status: Active » Needs review
StatusFileSize
new933 bytes

Attached is a patch that will cause the style settings to only be placed on the page once.

Please let me know what you think!

matthijs’s picture

Status: Needs review » Needs work

Weird, I don't seem to have that problem... The patch looks okay, but I think it will fail if the first form is build but not rendered (if #access is set to FALSE)?

dsnopek’s picture

It might also be related to AJAX.. It happens on the Spotlight widget in Panoply, where there are several upload elements placed on a single form and the user can click an "Add more" AJAX button.

I'm not sure if #attached won't get used if an element has #access set to FALSE! I'll need to test that..

matthijs’s picture

I would be very thankful if you could investigate this some more :-)

dsnopek’s picture

Yep, that's my plan! I'm going to do some testing to see if it's AJAX-related and if #access => FALSE will remove the Javascript. I'll let you know when I do. :-)

cthshabel’s picture

I am experiencing a problem related to this I believe. I have two crop tools on the same page. Neither of them save the new crop and the proportions are messed up in the preview too.

dsnopek’s picture

Added related issue #2255095: Add "Crop" tool to Spotlight widget, since it's that patch to Panopoly that needs the patch here to work. Unfortunately, I haven't had any time to work on this since that functionality was pulled out.

candelas’s picture

Hello

I am using Panopoly. I have a content type that has an image that in its style uses Manual Crop: Crop and scale with Respect minimum dimensions. When I add a new image, I can make a selection of any size, even 1x1px. When I edit an image that was previously cropped, then it works perfect.

I checked and the Drupal.settings.manualcrop.styles is empty when the image is new. I dig until I arrived to this patch. If I revert it, everything works.

Sorry that I have not enough knowledge to give a solution. Thanks

dsnopek’s picture

Status: Needs work » Closed (cannot reproduce)

Coming back to this after a few years. :-) I've been testing #2255095: Add "Crop" tool to Spotlight widget and can't reproduce the issue this patch was meant to fix anymore, so I'm going to just close this.