Closed (fixed)
Project:
Focal Point
Version:
8.x-1.x-dev
Component:
Media Integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Nov 2019 at 17:27 UTC
Updated:
6 May 2026 at 15:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pavel.bulatThe patch works for me in drupal 8.8.0
Also I used https://www.drupal.org/project/focal_point/issues/3098235#comment-13386688 for fix issue with preview button.
Comment #3
pavel.bulatComment #4
pookmish commentedThis solution appears to work in combination with the patch in the issue #3098235: Preview Modal Conflicts with Media Library Modal
Comment #5
phenaproximaThere may be a better way to do this. In Drupal 8.8, the add form has a base form ID (media_library_add_form) -- we should target that if we can, like so:
I don't know if this is the approach I would take here, either. The fields are displayed with a form mode (called media_library); IMHO, the site builder should configure the source field to be displayed in that form mode using the Focal Point widget, and then hide the preview. I don't think Focal Point should take on that responsibility; the preview was never meant to be treated as a live field, and doing it will likely cause trouble in the future.
Comment #6
sebastixThe patch from #2 is not working for me with the module using version 1.x-dev.
No focal point settings are being displayed when uploading an image through the media library.
Comment #7
alison(cross-posting on #3098235 because I'm not sure which parts are relevant to which issue)
Tried the patch at #2 here *and* the patch on 3098235 (comment #6) -- and, of course, with my "form display" settings using "focal point" for my image field. Here are my results:
An AJAX HTTP error occurred. HTTP Result Code: 200Log message details (see above for context):
...................
Drupal 8.8.0
Focal point 8.x-1.2
(Crop API 8.x-2.0-rc1)
Comment #8
davidferlay commentedI confirm patch #2 working fine with core 8.8.1 + focal_point 8.x-1.2)
I also confirm dblog warning mentioned by @alisonjo315 is brought by this patch (and not patch from this other issue)
So remaining todo here : Fix that warning
Comment #9
davidferlay commentedComment #10
aleevasMy last patch good working with this patch https://www.drupal.org/files/issues/2019-12-11/focal_point-3098235-6.patch
Comment #11
mandclu commentedUsing this latest patch I don't get an error when trying to submit an image through the media library, as part of a node's media reference field. That said, it didn't seem to enable the control to actually place the focal point, so I assume it was able to use the default (50, 50). I checked and didn't see any console or watchdog errors.
This may be something of a tangent, but when I tried the same operation within a workspace, I got an error that the form couldn't be submitted within the workspace, only live.
Comment #12
skaughtisset($element['#parents'][1])i suspect no digit should be hardcoded like this.
Comment #13
rob230 commentedTested with Drupal 8.7.7 and patch #10 appears to be working for us, we can specify the focal point and it saves.
Comment #14
rkdesantos commentedTested with 8.7.11 and v1.2 using both patches as in #10 and so far, so good.
Comment #15
ocastle commentedConfirm patch #10 is working with Drupal 8.8.1 against focal_point 1.2.
Comment #16
thetaPCTested with Drupal 8.8.2 and v1.2 using both the patches in #10, Focal Point appears. However, I received the same issues as #7. I then tried patch #2 instead (still with this patch) and it still failed. I get the same issues as #7 along with #8.
I've also tried path #10 by itself and I get the same issues as #7.
Comment #17
thetaPCComment #18
thetaPCComment #19
thetaPCI've been testing out the cause for the AJAX error. It seems that Focal Point is missing a few attributes when rendering in the media library preview (when using the patch #10).
The first image shows what the image widget looks like with the correct attributes when it's not using the media library.
The second image shows what the preview in the media library without the correct attributes when using the patch.
I also noticed that the media library (src/Form/FileUploadForm.php) is hiding the image from displaying in the fields section:
It might be beneficial to show the image in the fields section instead of the media library preview.
I'm still learning about Drupal and it's taking me longer than expected to find a solution. I'm hoping my findings can push forward a patch that shows Focal Point and allows the users to move the indicator and click on the preview link without issues.
Thanks.
Comment #20
yahyaalhamadPatch #10 works for me.
Comment #21
capellicPatch file in #10 works for me. (https://www.drupal.org/files/issues/2020-01-09/3094478-10.patch)
Comment #22
thetaPCI've been getting the same AJAX error as #7 mentions:
I have found out that
from a comment on ticket "Preview Modal Conflicts with Media Library Modal #4" after moving the cross hair.
I have combined patch #10 from here and some of patch #4 (effulgentsia) from "Preview Modal Conflicts with Media Library Modal". The combination seems to be working great.
However, I am unsure if this ticket is the correct location to include the server-side code or if it should be posted at "Preview Modal Conflicts with Media Library Modal".
Comment #23
thetaPCIgnore, wrong patch
Comment #24
thetaPCIgnore
Comment #25
thetaPCHow do I delete my bad patches? I've finally included the correct one. Sorry, I'm having an off day.
Here's the correct patch tied to #22
Comment #26
alison(re: hiding/deleting the other patches -- you got it, they're hidden from the top of the issue, etc.!)
Attached is an interdiff of 10 to "23_1" "goes with #22, posted on #25" :)
@thetaPC Are you saying your patch includes parts of the changes they're doing on our partner issue #3098235? I don't think you'd want to combine the two efforts, right? Sorry if I'm misunderstanding.
(At this point, though, I can't apply #25 and 3098235 comment #13 together, and I can apply #10 and that patch from the other thread together... I'm not sure what that means, but, that's what I've run into at this point. But also, I haven't gotten to test the functionality itself, ack, sorry! Anyway, sharing what I can share. Thank you!)
Comment #27
thetaPC@alisonjo315 thank you for the interdiff! I'm very new to creating patches.
I didn't combine them. I just used the partner issue #3098235 caching code that effulgentsia points out that is missing. I believe his caching code should be pushed to this ticket instead of the partner issue.
I do have the same conflict issue when apply #25 and 3098235 comment #13. I'm not sure if I should fix #25 when this issue is stand alone. Plus 3098235 ticket appears to be a duplicate from a core ticket.
Comment #28
nkoporecTested the latest patch #25, and it works! I'm using Drupal 8.8.1 with focal point 1.4 and a media entity reference field with a media library widget.
Comment #29
mandclu commentedNot sure what/where everyone else is testing. I'm trying to edit an image media entity, directly at
/media/[eid]/edit.With #25 applied I briefly see the focal point form elements (until the JS loads, presumably) but then they disappear and the focal point drag-and-drop widget does not appear.
I also tried the patch from #10 (no better for me), and the patch from #10 with the latest patch from #3098235: Preview Modal Conflicts with Media Library Modal (still no better). #25 appears to conflict with the patch from this other issue.
I couldn't observe any JS or db errors. Anything else I should try?
Comment #30
phenaproximaHere's another attempt. It needs tests, but in manual testing it adds Focal Point to the preview when adding an image in the media library, and it avoids the problem reported in #29. It's very targeted and only affects the media library.
Comment #31
phenaproximaSlight refactoring, and bumped the minimum required version of core to 8.8 in order to support my use of the entity_display.repository service. We could loosen that, of course, but I'd prefer to do that in a later patch if we decide we want to support 8.7.
Comment #32
phenaproximaMore cleanup and comments to make it clearer what the code is doing.
Comment #33
thetaPC@mandclu I'm testing it through the media library modal (media library form display). I believe that "/media/[eid]/edit" uses the default form display which shouldn't render the media library modal.
(Please correct me if I'm wrong especially since I don't know your setup.)
"Preview Modal Conflicts with Media Library Modal" appears to be a duplicate ticket of "Nested modals don't work: opening a modal from a modal closes the original." We might want to consider closing ticket #3098235 as a duplicate.
Comment #34
thetaPC@phenaproxima I can't help with testing since I couldn't apply the patch through composer. I'm not sure what caused it to fail. Sorry that I can't help.
Comment #35
katherinedThis patch adds a test to the patch in #32.
Comment #36
katherinedborrowed something from Media Library. :)
Comment #37
acbramley commentedNice work on these tests! However I think that all of this setup can be done programatically instead of stepping through the UI. Testing the UI can be done separately as we're only concerned here with the integration between media library and focal point.
This function is unnecessary, you can simply wrap the calls inline so waitForElement is inside assertNotEmpty.
Comment #38
phenaproximaThat test looks great! I streamlined it to do the setup programmatically and was able to remove the helper method. I also made a couple of assertions a bit more specific.
Comment #39
phenaproximaAdded a little comment to explain a previous choice.
Comment #40
mandclu commentedThe latest patch applies clean for me, but I still am not seeing the focal point widget, either in the standalone media edit form or the modal. That said, even though I have selected the focal point widget for both the default and Media Library form view modes, I don't see the preview link, even though I have selected that too. Is there maybe an additional patch I need?
Comment #41
phenaproxima@mandclu, there shouldn't be any additional patch needed. Can you post screenshots of what you're seeing in the modal, and of how the media library form display is configured for the media type you're trying to add? If you can, a full config export would also be really useful to see if we can reproduce your problem. It's totally possible that something is broken and we're missing test coverage. :)
Comment #42
ckrinaThanks @phenaproxima! It does work for me: I changed the form display both in the default form mode (/admin/structure/media/manage/image/form-display) and in the Media Library one (/admin/structure/media/manage/image/form-display/media_library) and it worked.
Comment #43
bleen commentedI did a bunch of playing around with the patch in #42 and it seems to work well... When looking at the code one thing worries me:
How confident are we in these array_parent values? That `-4` sticks out like a hard-coded sore thumb... is there another way to achieve this?
Comment #44
phenaproximaI feel pretty confident about it.
That structure comes from the Media Library's AddFormBase, which is (as the name implies) a base class that's meant to be extended (I helped write it, and continue to maintain it ;-). Therefore, that form array is basically an API.
Besides that, I've seen this same pattern used elsewhere, relying on a specific "distance" between levels of a form array. Obviously, because of the inherent flexibility of PHP arrays and the existence of so many alter hooks and callbacks, no form structure is 100% reliable, but that's par for the course in Drupal, and I'm not sure how else we could achieve this.
Comment #46
bleen commentedOk ... sold!
Thanks for all the work on this one!
Comment #47
mandclu commented@phenaproxima thanks for the offer to investigate why this isn't working for me. One obvious difference I notice vs. your screen captures is that your appear to be using Claro as your admin them, where as I am using Adminimal. I did also switch to Claro but there was no difference, functionally.
Default form setting:

Media Library form setting:

Editing in the Media Library:

Note that the no-js form is in the page markup, and is briefly visible on page load, then disappears (gets assigned a class of visually-hidden). But the interactive widget never loads as a replacement, so there is no way to set the focal point.
Same form, within the Media Library modal. Same as above, the standard form loads then is hidden, but the widget never loads. No JS errors logged in either case.

Comment #48
mandclu commentedI did some more investigation, after I realized that I wasn't getting the Preview link either. As an experiment, I went into the FocalPointImageWidget and changed line 158 from

$element['preview'] = $preview;to$element['preview_link'] = $preview;. The result was very interesting:I now had two previews, one of which has the Preview button and the focal point widget! I was able to find another module that also overwrites $element['preview'], namely cohesion_elements, in a preprocess function. If I comment out the relevant code, the focal point displays as expected.
Should I file this as a bug report with Cohesion?
Comment #49
thetaPCI finally managed to test the patch that was committed and the AJAX error is back.
The interdiff from comment #26 fixed the AJAX error but it's missing in the committed code. This code flushes the cache when the cursor is moved.
Steps to reproduce:
Comment #50
phenaproxima@mandclu and @thetaPC, will you file separate bug reports for these things? They look like legitimate issues to me, but this issue is basically done, so IMHO we should fix further integration bugs in new issues.
Comment #51
thetaPC@phenaproxima Got it, thank you!! I'll go ahead and make a ticket for it.
Comment #52
mandclu commented@phenaproxima roger that, added #3144968: Incompatible with Acquia Cohesion. Will also open an issue with Acquia.
Comment #54
lstirk commentedIs there a release planned for this patch?
Comment #55
maacl commentedI created a follow-up for #49: #3173647: Preview button broken when using media_library for uplading
Comment #56
rembrandx commentedWas there a release for this? It's marked as fixed but not sure what version is supposed to include the fix.
Comment #57
lpeabody commented@rembrandx it's included in the latest stable release 8.x-1.5.
Comment #58
basseye commentedWould it be wise to acknowledge that this module is not yet compatible with Drupal media/Library (Drupal 9+)? To be sure, It works perfectly fine with regular image field, but doesn't show when using media library. Perhaps, this limitation needs to be flagged up, rather than encouraging tinkering with patches which works for some and not for others. Just a thought.
Comment #59
superfluousapostrophe commented@Basseye - this does in fact work with media library, but you have to configure the form view for media library to use Focal Point. Documentation absolutely needs to be updated to let the non-developer know about how to reconfigure Media Library to use this module.
Comment #60
robert_t_taylor commentedTo @SuperfluousApostrophe''s point, I struggled to find this and I've been using Drupal for a long time. It is not readily apparent.
For anyone who might stumble upon this, I found this at /admin/structure/media/manage/image/form-display/media_library. Choose the "Image (Focal Point)" widget. Then when you edit any image at /admin/content/media you will see the Focal Point crosshairs.
Lastly, after installing and enabling the Focal Point module be sure to run drush updb or visit /update.php or Focal Point may not work.
Comment #61
malcomio commentedI've created #3268541: Document how to integrate focal point with media library for the documentation.
Comment #62
devkinetic commentedI've created a module that allows you to set the focal point on the embed token with a media embed. I actually found this issue after building it.
https://www.drupal.org/project/media_embed_focal_point.
I stumbled across https://www.drupal.org/project/media_library_media_modify and https://www.drupal.org/project/multi_crop and saw a gap where we could pass focal point data from the embed tokens.
Can someone explain how this patch compares to my module? In the end, I really want this feature so want to plug in wherever is best.
Comment #63
phjouIt seems like the patch #25 was working with the media library ckeditor but the code that has been commited does not (works fine when adding media through field widget, but not in modal through ckeditor).
Comment #64
phjouJust putting a reroll of #25 that fixes the issue in ckeditor in case anybody needs it.
Comment #65
jgjg commentedReroll of #64 to fix ckeditor issue to work with 2.1.2