I haven't tried a Coder Upgrade. Just a place to keep track of progress.

Comments

Jackinloadup’s picture

Please see #786900-26: Drupal 7 Port for information about the Context D7 port.

jerrac’s picture

So, Context itself has had several alpha releases for D7. Is this module going to get an update? Or does the new version of Context provide the same functionality?

real_ate’s picture

Any word on this port? Now that context is on beta-1 the API won't (shouldn't) change and it is well into the right time to create a port. Has any work been done on this yet?

chaosmind’s picture

bump, subscribe, +1... etc.

jlyon’s picture

+1. In the meantime, themekey has a D7 release: http://drupal.org/project/themekey.

jlyon’s picture

I created a sandbox project, and made some progress with the upgrade, but ran into a stumbling block.

http://drupal.org/sandbox/jlyon/1290746
git clone --branch master jlyon@git.drupal.org:sandbox/jlyon/1290746.git context_reaction__theme_7_x_1_x_dev

------

This is a clean upgrade of the D6 version of this module. All of the context-related functions work, however, I cannot get Drupal to listen to the value of $custom_theme (set in $plugin->execute, called from the hook_init()).

I also explored using hook_custom_theme(), like themekey does, however I was unable to get the plugin to load from this hook. It seems like it is called earlier in the bootstrap process than even hook_init().

Are there any more ideas out there?

minoroffense’s picture

Maybe the module weight would help.

xiong’s picture

any news?

Alumei’s picture

I spend some time looking into this, as i wanted to use this module in conjuction with context, on my drupal 7 site.

hook_custom_theme() is indeed called before hook_init(), hence no context is initialised at that point.

Also it seems that there is no way to change the theme in hook_init, as the theme has already been initialised by drupal_theme_initialize() earlier in bootstrap.

ThemeKey seems to be working with hook_custom_theme() because it does all it's condition checking within hook_custom_theme().

Alumei’s picture

It seems that the theme could be set, if the following happens in hook_custom_theme:

  1. the context condition for path is executed
  2. active_ theme reaction is executed and retuns the theme
  3. hook_custom theme returns the result of the reaction execution
Alumei’s picture

Status: Active » Needs review
StatusFileSize
new2.56 KB

I made a patch against the sandbox version mentioned above.

The solution is not ideal, but working.

jorditr’s picture

Hi, I'm not a coder and I have no access to GIT.

Brinbellomy, jlion, Alumei, or someone else, would you mind to upload as an attachment a version of the module in d7 version to be able to test and apply the patches :-)

I'm very interested on using that module, all my last sites relly on Context and that is a very desirable feature eagerly missing on it! Thanks to all in advance :-)

lahode’s picture

Yeah, it worked awesome, thanks!

To answer to JordiTR, here is the geek recipe...

Type on linux shell, the following lines:

git clone http://git.drupal.org/sandbox/jlyon/1290746.git context_reaction__theme_7_x_1_x_dev
wget http://drupal.org/files/context_reaction_theme-port-to-D7-920990-11.patch
cd context_reaction__theme_7_x_1_x_dev
git apply -v http://drupal.org/files/context_reaction_theme-port-to-D7-920990-11.patch
rm context_reaction_theme-port-to-D7-920990-11.patch

jorditr’s picture

Thanks a lot lahode. I told you I was not a coder (although I code small things) ;-) moreover I don't use Linux :-P

Anyway, I work with netBeans and your suggestions has inspired me to use several functions on it to git the sandbox module and then apply the patch :-) Thanks to both.

jorditr’s picture

Hi, I've installed this build and it works properly, beautifully!! I should say :-)

But, it displays a warning on my system on every single context I enter in to edit (except if that context has set a reaction for theme change):

Notice: Undefined index: theme en context_reaction_active_theme->options_form() (línea 28 de /usr/home/decidess.com/web/sites/all/modules/context_reaction_theme/plugins/context_reaction_active_theme.inc).

and it's pointing to "'#default_value' => $settings['theme']," on the $form array of "function options_form($context)".

Just to try to avoid any confusion here is how that function looks on my build on "plugins/context_reaction_active_theme.inc":

<?php
/**
   * Allow admins to provide a section title, section subtitle and section class.
   */
  function options_form($context) {
    $options = array();
    $themes = list_themes();
    foreach($themes as $name => $theme) {
      if($theme->status == 1) $options[$name] = $name;
    }
    
    $settings = $this->fetch_from_context($context);
    
    $form = array(
      '#tree' => TRUE,
      '#title' => t('Theme'),
      'theme' => array(
        '#title' => t('Active theme'),
        '#description' => t('Choose a theme to activate when this context is active.'),
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => $settings['theme'],
      ),
    );
    return $form;
  }
?>

Any idea?

jlyon’s picture

@Alumei: Thanks for the patch. I finally just applied it to my git sandbox project at http://drupal.org/sandbox/jlyon/1290746.

@JordiTR: It looks like you must not have set a theme in the context administration interface. Could that be? The error is saying that $settings['theme'] is empty.

jorditr’s picture

Yes, that's right, but most of the context don't have each and every reaction set and don't complain :-)

I have not written the code, I just ask if I applied the patch correctly and others are having or not the same behaviour.

jorditr’s picture

I've been experimenting with "Context Reaction: theme" converted to Drupal 7 in order to make it compatible with "Context Mobile Detect" on that thread: http://drupal.org/node/1792868

kpa’s picture

@JordiTR: replace line 28
'#default_value' => $settings['theme'],

with:
'#default_value' => isset($settings['theme']) ? $settings['theme'] : '',

It's a non-critical bug and this will fix.

jlyon’s picture

Thanks kpa, I just updated the sandbox project: http://drupal.org/sandbox/jlyon/1290746.

kpa’s picture

It may also be an idea to add a module_invoke into the hook_custom_theme implementation to allow other modules (with custom plugins) the ability to run their conditions prior to active_theme being called.

At present this will only run conditions from the path, language and user context conditions - is there a reason for limiting this?

I had to add:

  if ($plugin = context_get_plugin('condition', 'mycustomcondition')) {
    $plugin->execute();
  }

into context_reaction_theme_custom_theme() to get my custom condition to load..

Other than that - great module - and saved me a lot of time (and the MASSIVE overhead of the themekey module). Thanks.

jorditr’s picture

Thanks kpa (Phillip), I wrote something similar to keep my site from warning each time I use context :-)

I was not sure if that was the proper way to do it, because I looked how other context complement modules solve this and some use that approach and other I'm not capable to understand if the are doing something different. Anyway, your proposal works efficiently :-)

jorditr’s picture

Regarding that point look how I had to face exactly the same solution for being able to change theme when using "Context Mobile Detect" on #18.

Context family of module provide a huge range of possibilities. Combining "Context Mobile Detect" with other Context complements (add assets, disable context, ssl, session, overlay, get, geo ip, http headers) open a real solution for Mobile webs with Drupal (specially 7) using Context as the central tool. I'm not sure how solid it is, but all my testing has been quite promising until now. By now only 24 sites are registered as using "Context Mobile Detect" :-)

Anonymous’s picture

Title: Port to Drupal 7 » Port Context Reaction: Theme to Drupal 7

Changing the title so it's easier to follow in global issue queues.

jorditr’s picture

I find very weird that the port proposed here for that module to Drupal 7 is working perfectly and it has not received any attention from the maintainer. I got it perfectly working with the mentioned "Context Mobile Detect" and even I proposed a patch that has not been reviewed... Well...

Anonymous’s picture

It appears that the project has been abandoned by its former maintainer.

There's an official drupal.org process for taking over an unmaintained project. It's quite straightforward, so if you are willing to take the module forward, you might want to step up and do that!

Michsk’s picture

StatusFileSize
new2.15 KB

Here's 'my' version of the D7 port... Really have to get started with git. The zip contains the whole module.

Basically:
- it has some sort of 'auto finding' all the conditions
- use the themes info['name'], so we show the theme name with captions where it should
- small tweak in #default_value for the themes select list

justadropofwater’s picture

This unfortunately is not switching the theme based on 'path' or 'user role' contexts and produces a Missing Argument Warning. I'll try to find some time to debug...

kpa’s picture

Hi all, just a brief update note to say that (finally) I'm getting round to sorting this out. I've been using this module on a D7 site since September with no problems, and I'll be reviewing everyone's contributions above over the next week or so. Hoping to get a 7.x-dev by the weekend... watch this space :)

damienmckenna’s picture

Issue summary: View changes

@kpa: Any updates?

eric_a’s picture

There's D7 code in 7.x-1.x (http://cgit.drupalcode.org/context_reaction_theme/commit/?id=9e119e080b3...).

Has anybody tried this?