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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Timo Vogt’s picture

Version: 7.x-1.9 » 7.x-1.x-dev
alphex’s picture

How do you use this?

Timo Vogt’s picture

Just copy it into the imce.module

sammarks15’s picture

Title: Add function to use IMCE in admin theme » Force IMCE to use the Administration Theme
Category: Feature request » Bug report
Status: Active » Needs review
FileSize
391 bytes

It's probably better in this case to use hook_admin_paths() instead of hook_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.

gwheelerky’s picture

To expand on my colleague's post, if you need this in a pinch you can do it from your own module as well:

function mymodule_admin_paths() {
	$paths = array(
		'imce' => TRUE,
	);
	return $paths;
}
joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Been using this for some time would like to avoid custom hooks to get contrib to work.

ufku’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs work

I think this should be optional in order to preserve existing imce customizations(css, tpl, etc) in themes.

joelpittet’s picture

@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.

capfive’s picture

This also works with the following code for the file browser

<?php
function mymodule_admin_paths() {
    $paths = array(
        'user/*/imce' => TRUE,
    );
    return $paths;
}
?>
baltazarz3’s picture

The patch worked for me, thanks so much guys

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
399 bytes

This 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.

DamienMcKenna’s picture

FileSize
2.69 KB

This version adds a checkbox to control whether the admin theme is used.

DamienMcKenna’s picture

BTW 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.

DamienMcKenna’s picture

BTW if you need to override the admin theme setting for an existing site, you can add this to a custom module (tailor as needed):

/**
 * Implements hook_update_dependencies().
 */
function MYMODULE_update_dependencies() {
  $deps = array();
  // Make sure this runs *after* IMCE update 7100 so that the variable can be
  // set to TRUE, i.e. turn on admin theme integration.
  $deps['MYMODULE'][7100] = array('imce' => 7100);
  return $deps;
}

/**
 * Implementations of hook_update_N().
 */

/**
 * Turn on admin theme integration for IMCE.
 */
function MYMODULE_update_7100() {
  variable_set('imce_settings_admin_theme', TRUE);
}
joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @DamienMcKenna

joelpittet’s picture

Also you can just set in your settings.php to force the value.
$conf['imce_settings_admin_theme'] = TRUE;

darvanen’s picture

This is good, +1 for commit.

capfive’s picture

awesome, lets get this committed!

inman’s picture

#4 Thank you!

gregpymm’s picture

Is there a Drupal 8 solution to force the admin theme?

gregpymm’s picture

I 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.

services:
  theme.negotiator.imce:
    class: Drupal\my_module\Theme\IMCENegotiator
    tags:
      - { name: theme_negotiator, priority: 1000 }

And the associated class file:

IMCENegotiator.php

<?php

namespace Drupal\my_module\Theme;

use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Drupal\Core\Routing\RouteMatchInterface;

class IMCENegotiator implements ThemeNegotiatorInterface {
  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    // Use this theme on a certain route.
    return $route_match->getRouteName() == 'imce.page';
  }

  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    // Here you return the actual theme name.
    return 'classy';
  }

}

I found my start here:
https://www.drupal.org/node/2158619

DamienMcKenna’s picture

@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?

MediaFormat’s picture

juanolalla’s picture

FileSize
1.5 KB

I've continued working from #21 and here is a patch for Drupal 8.

MediaFormat’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
joseph.olstad’s picture

RTBC 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!

caspervoogt’s picture

MediaFormat’s picture

Issue summary: View changes

Everyone keeps adding RTBC for D7 patch #12, can we get a commit?

Anyone up for testing/reviewing D8 patch #24?

joelpittet’s picture

We could split them out into related separate issues as we do in core now?

yaminoscott’s picture

Tested #24 on my local instance of a D8 website where IMCE was trying to use my custom theme. I can confirm it works perfectly.

joseph.olstad’s picture

Priority: Normal » Critical

Setting 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.

joseph.olstad’s picture

I 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 a jQuery 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.

joelpittet’s picture

@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

joseph.olstad’s picture

@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***

joelpittet’s picture

The 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.

joseph.olstad’s picture

@joelpittet , you bring up some good points. Luckily we have this patch that provides so many of us with a working solution.

DamienMcKenna’s picture

Any 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.

MediaFormat’s picture

Status: Needs review » Reviewed & tested by the community

D7 Patch RTBC
D8 Patch RTBC by @yaminoscott #30

I think we are good to commit!

wheretoplaygames’s picture

I 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

joseph.olstad’s picture

@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

wheretoplaygames’s picture

Thanks, 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? :)

joseph.olstad’s picture

Ya, 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.

MediaFormat’s picture

This 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.

wheretoplaygames’s picture

Is the patch from #24 supposed to load the IMCE in my front-end theme? Nothing is happening.

MediaFormat’s picture

The patch from #24 si meant to load the IMCE in back-end theme.
Note I have not been able to review it personally.

joseph.olstad’s picture

on 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.

wheretoplaygames’s picture

j.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.

Mile23’s picture

Patch in #12 is part of the recommended installation process for IMCE with CKEditor and Media in this script: https://www.drupal.org/node/2843391

MediaFormat’s picture

Status: Reviewed & tested by the community » Needs review

@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.

MediaFormat’s picture

Status: Needs review » Needs work

wrong status

Mile23’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community
Issue tags: +needs port to Drupal 8

Based 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.

joseph.olstad’s picture

committing 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.

MediaFormat’s picture

Title: Force IMCE to use the Administration Theme » Permit IMCE to use the Administration Theme
Issue summary: View changes

  • ufku committed 8786b63 on 7.x-1.x
    Issue #2357871 by Timo Vogt, DamienMcKenna: Permit IMCE to use the...
ufku’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks.

joseph.olstad’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Fixed » Needs review

set back to 8.x branch

akalata’s picture

While 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).

akalata’s picture

Issue tags: -needs port to Drupal 8
ufku’s picture

Priority: Critical » Normal
Status: Needs review » Needs work

Since it should be an optional feature the proper way seems to be implementing a RouteSubscriber.

akalata’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.77 KB

@ufku I'd realized that a few minutes after I posted #57. Here's an implementation that should have parity with the D7 version.

MediaFormat’s picture

Status: Needs review » Reviewed & tested by the community

Confirming that saving the option, clearing caches, IMCE file popup uses admin theme.

  • ufku committed f66cbcb on 8.x-1.x
    Issue #2357871 by akalata: Permit IMCE to use the Administration Theme
    
ufku’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.