Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Summary:
D7 patch #12: Committed in #54
D8 patch #60: Needs review
Original Report
Hello everyone,
found out that it is pretty practical to use the imce with the admin theme so nothing of the JQuery stuff from the front page interferes with IMCE.
<?php
function imce_custom_theme() {
// If imce page is called the admin theme will be used
if (arg(0) == 'imce') {
return variable_get('admin_theme');
}
}
?>
What do you think?
Comment | File | Size | Author |
---|---|---|---|
#60 | 2357871-d8_imce_page_admin_route-60.patch | 2.77 KB | akalata |
#57 | 2357871-d8_imce_page_admin_route.patch | 349 bytes | akalata |
#24 | imce-n2357871-d8-24.patch | 1.5 KB | juanolalla |
#12 | imce-n2357871-12.patch | 2.69 KB | DamienMcKenna |
Comments
Comment #1
Timo VogtComment #2
alphex CreditAttribution: alphex commentedHow do you use this?
Comment #3
Timo VogtJust copy it into the imce.module
Comment #4
sammarks15 CreditAttribution: sammarks15 commentedIt's probably better in this case to use
hook_admin_paths()
instead ofhook_custom_theme()
. hook_admin_paths allows modules (like IMCE) to define which paths are considered administrative. Since IMCE is part of content management, I very much consider it to be administrative. Therefore, it should be using the administration theme.That way, if the site theme is doing something like overriding jQuery, it won't have an effect on how IMCE works.
I've attached a patch that solves this.
Comment #5
gwheelerky CreditAttribution: gwheelerky commentedTo expand on my colleague's post, if you need this in a pinch you can do it from your own module as well:
Comment #6
joelpittetBeen using this for some time would like to avoid custom hooks to get contrib to work.
Comment #7
ufku CreditAttribution: ufku commentedI think this should be optional in order to preserve existing imce customizations(css, tpl, etc) in themes.
Comment #8
joelpittet@ufku Any issue related to buttons "disappearing" in IMCE, are likely related to this issue by the way. For me that's why it was a bug report.
Comment #9
capfive CreditAttribution: capfive commentedThis also works with the following code for the file browser
Comment #10
baltazarz3 CreditAttribution: baltazarz3 commentedThe patch worked for me, thanks so much guys
Comment #11
DamienMcKennaThis updates the first patch to include the user/*/imce path, and I moved the hook up to right after imce_menu to make it easier to see the connection between the menu paths and the admin paths.
Comment #12
DamienMcKennaThis version adds a checkbox to control whether the admin theme is used.
Comment #13
DamienMcKennaBTW for existing sites the patch will disable the admin theme integration, to avoid breaking sites, admins will have to specifically turn it on via the common settings. This covers the potential problem that ufku mentioned in #7.
Comment #14
DamienMcKennaBTW if you need to override the admin theme setting for an existing site, you can add this to a custom module (tailor as needed):
Comment #15
joelpittetThanks @DamienMcKenna
Comment #16
joelpittetAlso you can just set in your settings.php to force the value.
$conf['imce_settings_admin_theme'] = TRUE;
Comment #17
darvanenThis is good, +1 for commit.
Comment #18
capfive CreditAttribution: capfive commentedawesome, lets get this committed!
Comment #19
inman CreditAttribution: inman as a volunteer commented#4 Thank you!
Comment #20
gregpymm CreditAttribution: gregpymm commentedIs there a Drupal 8 solution to force the admin theme?
Comment #21
gregpymm CreditAttribution: gregpymm commentedI found a Drupal 8 solution that worked for me... Using services, in a custom module... Which I am very new to, so please feel free to jump in here.
I created:
my_module.services.yml
With.
And the associated class file:
IMCENegotiator.php
I found my start here:
https://www.drupal.org/node/2158619
Comment #22
DamienMcKenna@gregpymm: If that was able to load the correct config object that represented the admin theme it could be turned into a patch. Anyone know how to load the appropriate config object that controls the admin theme?
Comment #23
MediaFormat CreditAttribution: MediaFormat commentedCan we get a D7 commit for #2357871-12: Permit IMCE to use the Administration Theme?
thx
Comment #24
juanolalla CreditAttribution: juanolalla at Lullabot commentedI've continued working from #21 and here is a patch for Drupal 8.
Comment #25
MediaFormat CreditAttribution: MediaFormat commentedD7 patch #2357871-12: Permit IMCE to use the Administration Theme RTBC
D8 patch Needs review
Comment #26
joseph.olstadRTBC patch 12 for 7.x-1.x, IMCE was not working for me until I forced it to use the admin theme because my front end theme doesn't use the same version of jQuery as the back-end theme and IMCE would use the front end theme while the wysiwyg editing on my site is being done entirely with the admin theme.
When I inspected the javascript console on the imce popup the error I was previously getting was:
Drupal.settings.extlink is undefined
Using patch 12 resolved the issue because it allows imce to open its dialog in the same theme that is running the wysiwyg editor and consequently using the same jQuery version as the wysiwyg editor so they will talk together in the same namespace. Without this imce is like, what , no one else is listenning, and the wysiwyg editor is like, hey, where's imce? Thats what happens when you've got two versions of jQuery running and plugins trying to talk with the api thats expecting you to be using the same jQuery version.
I might add, that to make an even better improvement would be to rather than use the 'admin' theme imce should use the theme that its dialog popup was spawned from , that way it would work even on the front end theme should you be brave enough to have a wysiwyg editor on there. However, generally to use the imce you'd probably want to have elevated priviledges, so its probably ok as it is. That change would be a new issue. As for this issue, I'm sticking to RTBC.
Thanks!
Comment #27
caspervoogt CreditAttribution: caspervoogt at Plethora commentedD7 patch #2357871-12: Force IMCE to use the Administration Theme RTBC. Works great
Comment #28
MediaFormat CreditAttribution: MediaFormat commentedEveryone keeps adding RTBC for D7 patch #12, can we get a commit?
Anyone up for testing/reviewing D8 patch #24?
Comment #29
joelpittetWe could split them out into related separate issues as we do in core now?
Comment #30
yaminoscott CreditAttribution: yaminoscott commentedTested #24 on my local instance of a D8 website where IMCE was trying to use my custom theme. I can confirm it works perfectly.
Comment #31
joseph.olstadSetting this as critical, because (for many of us forced to use different versions of jQuery between admin and front end), imce is completely 100% broken without this patch.
Comment #32
joseph.olstadI propose an improvement to this patch.
Rather than simply using a variable to decide whether or not to use the admin theme for imce, we could use a combination of variable (default value as true to allow disabling) AND then check if
module_exists('jquery_update')
and then do ajQuery version test
and compare the jQuery version between the admin theme or the front end theme.depending on the result of the module_exists and the jQuery version test, automatically make the decision for the end user on which theme to use for the front end, but still allow this functionality to be disabled/enabled however default value would be enabled and if so, the tests for module_exists and jQuery version would run.
This would make the ultimate improvement in usability.
However, for expediency, we should commit the patch as-is and then spin off my idea into a new issue.
Comment #33
joelpittet@joseph.olstad it only works if you are using jquery_update and jqmulti or replacing the jquery in your front end theme manually. Not to mention
jquery_update
can be used on the admin theme as well. I'd avoid any implicit dependency if possible.It would be good to find out what change is causing the jquery version change and maybe all it needs is a polyfill? I did this for VBO similar issues: https://www.drupal.org/node/2608360#comment-11620927
Comment #34
joseph.olstad@joelpittet I followed the link in your comment, if you've fixed something similar like this before , by all means take the ball and run, thx
***edit***
This issue is probably not a jQuery compatibility problem as much as a name space problem, two jQuery libraries loaded at the same time, not talking with each other. Creditor in one, imce in the other***edit***Comment #35
joelpittetThe reason I want the admin theme had nothing to do with jquery and is why I'm watching this issue because the CSS from my theme was conflicting and hiding all the buttons in D7. So I don't know what the jQuery problem is actually and it's actually not clear from the IS what the jQuery bug is.
Comment #36
joseph.olstad@joelpittet , you bring up some good points. Luckily we have this patch that provides so many of us with a working solution.
Comment #37
DamienMcKennaAny changes to jquery logic should be moved to a separate issue, this one is for a very specific feature request and has sat as RTBC for a year.
Comment #38
MediaFormat CreditAttribution: MediaFormat commentedD7 Patch RTBC
D8 Patch RTBC by @yaminoscott #30
I think we are good to commit!
Comment #39
wheretoplaygames CreditAttribution: wheretoplaygames commentedI used the D8 patch and nothing happened. Is there an additional step? I am using Drupal 8.3.0-rc2 and AdaptiveTheme v.8.x-1.0-rc2+104-dev
Comment #40
joseph.olstad@Wheretoplaygames please re-read the thread, for D7 and maybe D8 it is likely that this feature will do nothing for you but for my sites using D7 bootstrap and jQuery 1.10 on the front side and jQuery 1.xyz on the admin theme, this is needed to be able to control which theme imce will be rendered in, otherwise imce will not work correctly
Comment #41
wheretoplaygames CreditAttribution: wheretoplaygames commentedThanks, j.o, I've read and re-read, but not being a developer, it seems like a few too many hoops... I'm on DP 8.3 and haven't added jquery updater at this point and everything has been peachy so far w/ other modules.
I'm a little wary to start going too far of the path. Guess i have to weigh the "want" vs. the need to keep things tidy. Of course, this could be much simpler than i'm perceiving it, but i keep trying to look at Droooooopal through the lens of a user. Is that so wrong? :)
Comment #42
joseph.olstadYa, I agree that from the lens of a user, imce should just work all the time in all circumstances, however, until someone finds a better way, to get imce working with jquery_update is possible with this patch and a couple mouse clicks. Otherwise imce won't work in my case at all, and that's a real fail in terms of usability. I don't see any reason to delay this solution, its already been delayed enough.
IMHO, commit this solution, open a new issue for new related improvements and reference this one. This is just to avoid more delays so that we can move forward asap.
Comment #43
MediaFormat CreditAttribution: MediaFormat commentedThis really seems like a bug, apparent only when one has a different jQuery on front theme.
I assume the most common use of IMCE would be in admin theme anyways...
So yes, please at least commit to the 7.x branch.
Comment #44
wheretoplaygames CreditAttribution: wheretoplaygames commentedIs the patch from #24 supposed to load the IMCE in my front-end theme? Nothing is happening.
Comment #45
MediaFormat CreditAttribution: MediaFormat commentedThe patch from #24 si meant to load the IMCE in back-end theme.
Note I have not been able to review it personally.
Comment #46
joseph.olstadon D7
install bootstrap , set it as your default front-end theme
requires jquery_update , configure bootstrap theme to jQuery 1.10 or 1.11 as recommended/required by bootstrap.
then try to use IMCE on your admin theme. like create a node and use your imce widget when your admin theme is on jQuery 1.4, 1.5, 1.6, 1.7, 1.8, or 1.9
You'll notice that you won't get full functionality of imce, it will be broken because the popup is rendered by the front end theme using a different jQuery namespace/instance.
To remediate; install the above patch, set the IMCE theme to the backend theme, then you'll notice that it works because the IMCE popup will be rendered by the same theme that the widget was clicked.
it's pretty simple.
Comment #47
wheretoplaygames CreditAttribution: wheretoplaygames commentedj.o, I'm on D8, and the #24 patch is for D8.
I asked about which theme because i need it to load in my front-end theme for an intranet.
Comment #48
Mile23Patch in #12 is part of the recommended installation process for IMCE with CKEditor and Media in this script: https://www.drupal.org/node/2843391
Comment #49
MediaFormat CreditAttribution: MediaFormat commented@wheretoplaygames
IMCE loads jQuery & CSS from the front-end theme, which can cause conflicts when accessing from the admin theme.
D7 Patch #12 adds an option to Common settings to allow loading jQuery & CSS from the admin theme.
I retested the D8 patch #24 and noticed that there is no option to load from admin theme, in fact the patch modifies IMCE to automatically load from admin theme.
I think this would be a breaking change, so I am reverting the status for 8.x-1.x-dev
Patch #12 for D7 is still RTBC, if anyone that can, wants to commit it.
Comment #50
MediaFormat CreditAttribution: MediaFormat commentedwrong status
Comment #51
Mile23Based on #49, the patch in #12 is RTBC from #15.
I'm rescoping to 7.x-1.x and adding 'needs port to D8' tag. When the D7 version is committed, this issue can be set back to 8.x-1.x and the tag removed.
This is critical since it's apparently part of the process of applying security updates for media module.
Comment #52
joseph.olstadcommitting this patch will improve IMCE usability for novice hobbyists that might not know how to apply patches, or for those that would rather not have to patch it will make this module easier to install and reduce the barriers to using it.
Comment #53
MediaFormat CreditAttribution: MediaFormat commentedComment #55
ufku CreditAttribution: ufku commentedCommitted, thanks.
Comment #56
joseph.olstadset back to 8.x branch
Comment #57
akalata CreditAttribution: akalata commentedWhile the approach in #24 works for D8, here's a simpler patch that defines imce.page as an admin route (versus adding a new ThemeNegotiator service).
Comment #58
akalata CreditAttribution: akalata commentedComment #59
ufku CreditAttribution: ufku commentedSince it should be an optional feature the proper way seems to be implementing a RouteSubscriber.
Comment #60
akalata CreditAttribution: akalata commented@ufku I'd realized that a few minutes after I posted #57. Here's an implementation that should have parity with the D7 version.
Comment #61
MediaFormat CreditAttribution: MediaFormat commentedConfirming that saving the option, clearing caches, IMCE file popup uses admin theme.
Comment #63
ufku CreditAttribution: ufku commentedCommitted, thanks.