I'm using themekey for a particular Organic Group (it's supposed to allow you to specify a theme for a group but I haven't been able to figure out how). This basically works when I assign the rule to the OG's URL, and allow the themekey settings to retain the theme until a new one is set - but it's still pretty fiddly.

Would it be easy to add "organic groups:nid" to the list of properties in the pulldown? so that you could allocate a theme to any pages which belong to a particular organic group?

I suspect this would be easy for someone who understands PHP... as opposed to someone like me who stands at a safe distance and prods it carefully, fearful of explosions :(

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkalkbrenner’s picture

Category: feature » support

Organic Groups itself comes with a feature to assign a different theme to a group. Did you try it?

adam_b’s picture

(it's supposed to allow you to specify a theme for a group but I haven't been able to figure out how)

Yes, I tried it. It didn't work, and it also messed up the display of that group (gave an error message for anyone attempting to view the group who wasn't logged in). I took a look through the OG issues list and other people had reported the problem, with no help forthcoming - so I thought I'd explore an alternative method.

mkalkbrenner’s picture

Category: support » feature
Status: Active » Postponed

Strange, it worked in my test setup when I resolved #669376: ThemeKey UI is incompatible to Organic Groups (Illegal choice when I select a theme using themekey).
From my point of view the issue should be resolved by th OG developers.

Nevertheless we could think about adding some organic group properties for ThemeKey. But currently we focus on the final release of ThemeKey 6.x-2.0. So I'll postpone this feature request to have a look at it after the 2.0 release.

adam_b’s picture

That's fair enough, thanks. I'll have another go at the OG implementation in the meantime.

adam_b’s picture

hmmm... now the OG system is working, which is irritating. I'm still having problems getting the different theme to apply to a view based on a groupnid, so if that could be tackled with themekey it would be nice.

spudette77’s picture

This may not be helpful at all, but I am having the same issues, plus I am very new at Drupal which doesn't help. I am having all sorts of issues with the Organic groups. Firstly, the default view does not work because I cannot get the path to register... Second, how do you create a new group using organic groups with the default group home page? I have confused myself completely!!!!!
I have created a 'group' page and set it as the group node and that works fine. However, I want to design two different style of groups with two different themes. So I am having trouble with this. Plus I HATE the tabs that come up on the groups page.... how the hell do you style these? Or how do set what tabs you want... so instead of RSS and OUTLINE tabs, I want a custom PHOTOS tab and Wiki tab. If anyone can help I would really appreciate it!!! I have read 3 drupal books and none of them addresses these issues!!

adam_b’s picture

spudette - you're better off posting this in the OG Issues area or in one of the support forums, as your problem has nothing to do with Themekey. You can refer to this URL if you don't want to repeat your rant :)

mkalkbrenner’s picture

"I'm still having problems getting the different theme to apply to a view based on a groupnid, so if that could be tackled with themekey it would be nice."

... sounds reasonable.

SocialNicheGuru’s picture

Take a look at http://drupal.org/node/548430

@adam_b, did you make any progress with themekey and og?

adam_b’s picture

Not really - for the moment I've been concentrating on relating themekey to varying subdomains, which is working well. I'll probably have to come back later to the themekey/OG issue.

SocialNicheGuru’s picture

I am using OG/atrium for subdomains and the functionality is nice. But I need this last piece to make it sing.

ShaneOnABike’s picture

+1 For now I got it working by making all the paths something like /group/ and then matching the path based on the /group/*

This isn't that ideal mainly because sometimes content has different paths but still within the same group. It would be great if we could select the appropriate theme for a node based on which group it was part of :)

My issue was that the og theme was getting overwritten by other modules and I had to force it to work with a custom theme. Your module is great, but having this element would be super!

daggerhart’s picture

I've written a custom module for a job that handles theme swtiching for specific group nids, and provides a path for the permalink module.

/**
 * Implements hook_themekey_properties().
 *
 * @return
 *   array of themekey properties and mapping functions
 */
function themekey_custom_themekey_properties() {
  if (module_exists('og')){
    // Attributes for properties
    $attributes = array();
    $attributes['group:nid'] = array(
      'description' => t('Group: NID - The id of a og group'),
      'validator' => 'themekey_validator_ctype_digit',
      'page cache' => THEMEKEY_PAGECACHE_SUPPORTED,
    );

    // Mapping functions
    $maps = array();
    $maps[] = array('src'       => 'node:nid',
                    'dst'       => 'group:nid',
                    'callback'  => 'themekey_custom_nid2gnid');

    return array('attributes' => $attributes, 'maps' => $maps);
  }
}

/**
 * Implements hook_themekey_paths().
 */
function themekey_custom_themekey_paths() {
  $paths = array();
  // permalink path
  if (module_exists('permalink')){
    $paths[] = array('path' => 'comment/#comment:cid');
  }
  return $paths;
}
/*
 * Get the group's nid base on a node's nid
 */
function themekey_custom_nid2gnid($nid){
  if ($group = og_determine_context()){
    return $group->nid;
  }
  else {
    // if it's a legitimate group nid
    $sql = 'SELECT COUNT(nid) FROM {og} WHERE nid = %d';
    if ($count = db_result(db_query($sql, $nid))){
      // return the currently discovered nid
      return $nid;
    }
  }
}

This uses the og function to get the group context, and if that is not found, checks to see if the current nid is a group.

Since is detects in these two ways, it will also adjust for views tabs that are built on a group.

It would be easy to add more group related properties if you need them.
Would love a review of this.

Thanks

ShaneOnABike’s picture

Is it possible for you to roll that as a patch for Themekey rather than a custom module instead? Then the maintainer could add it into their module :)

daggerhart’s picture

FileSize
1.4 KB

@ShaneOnABike sure.

Here is the patch for just the organic groups nid stuff, since that is the purpose of this issue.
I'm sure needs review.

[edit] Btw, if this is helpful, but someone needs other og group properties besides nid, just let me know. Themekey is so well written, it's a breeze to add these things.

mkalkbrenner’s picture

Version: 6.x-2.0-beta7 » 6.x-4.x-dev
Status: Postponed » Needs review

Themekey is so well written, it's a breeze to add these things.

Thanks for the compliment.

The patch is for 6.x, right?
I'll integrate your patch, if there's a chance to port it to 7.x. Are you familiar with with OG 7.x?

daggerhart’s picture

Thanks for the great module!

This patch is for 6.x-4.x. I do know OG 7.x as well, but don't have a current 7.x site with themekey. I'll put something together, take a look at it this evening if possible, and see if I can put one together for you.

I'll be looking at OG 7.2x since that is the future of OG in 7.

daggerhart’s picture

Patch for new group:nid property

Themekey 7.x-2.0
OG 7.x-2.0(alpha2)

Requires the og_context module to use the existing functionality to determine current group context.

daggerhart’s picture

Found some more that needs to be added to themekey.og.inc for 6.x

/**
 * Implementation of hook_themekey_paths().
 */
function themekey_og_themekey_paths() {
  $paths = array();
  $paths[] = array('path' => 'og/%/#node:nid');
  $paths[] = array('path' => 'og/%/#node:nid/%');
  $paths[] = array('path' => 'og/%/#node:nid/%/%');
  return $paths;
}

Sorry this isn't in patch form, I'm not currently in a position to make it so. Please let me know if you need me to re-roll the above 6.x patch with this included and I can take care of it when I get some time.

mkalkbrenner’s picture

@daggerhart : no need for a new patch file. I will assemble it by myself.

Aren't there any paths required for OG 7.x-2.x?

Thanks for your work so far.

daggerhart’s picture

Here are the paths for the previous themekey 7.x patch (#18) and OG-7.x-2.x

/**
 * Implements hook_themekey_paths().
 */
function themekey_og_themekey_paths() {
  $paths = array();
  if (module_exists('og_ui')){  
    $paths[] = array('path' => 'group/%/#node:nid/%');
  }
  return $paths;
}
mkalkbrenner’s picture

Version: 6.x-4.x-dev » 7.x-2.x-dev
Assigned: Unassigned » mkalkbrenner
Status: Needs review » Needs work

I started a review of your patches for 7.x and have some questions.

og_ui_menu only defines these paths:

group/%/%/subscribe
group/%/%/unsubscribe
group/%/%/admin/people/add-user
group/%/%/admin/people
group/%/%/admin/roles
group/%/%/admin/role/%/edit
group/%/%/admin/permissions
group/%/%/admin/permission/%/edit

foreach (og_get_all_group_entity() as $entity => $value) {
  $entity/%/group
}

Are we sure that there's no path like 'group/%/#node:nid' ('group/%/%')?

I suggest to name the property group:id instead of group:nid.

If we declare the path as group/%/#group:id, we can set the property without a need for a mapping function.

If we depend on og_context we should replace module_exists() by the file name themekey.og_context.inc

module_exists('og_ui') in mapping function is not needed because this one is safe, even if the module gets disabled.

What about a group:type property? path: group/%group:type/#group:id

You missed to return the NULL value if no mapping applied.

Can you please verify this implementation (I'm still not familar with OG):


// filename: modules/themekey.og_context.inc

/**
* Implements hook_themekey_properties().
*
* Provides additional properties for module ThemeKey:
* - group:id
* - group:type
*
* @return
* array of themekey properties and mapping functions
*/
function themekey_og_themekey_properties() {
  // Attributes for properties
  $attributes = array();
  $attributes['group:id'] = array(
    'description' => t('Group: ID - The og group ID'),
    'validator' => 'themekey_validator_ctype_digit',
    'page cache' => THEMEKEY_PAGECACHE_SUPPORTED,
  );
  $attributes['group:type'] = array(
    'description' => t('Group: Type - The type of a og group'),
    // TODO
    // 'validator' => 'themekey_validator_og_group_type',
    'page cache' => THEMEKEY_PAGECACHE_SUPPORTED,
  );

  // Mapping functions
  $maps = array();
  $maps[] = array('src' => 'node:nid',
                  'dst' => 'group:id',
                  'callback' => 'themekey_og_nid2gid');
  // TODO
  // $maps[] = array('src' => 'node:nid',
  //                 'dst' => 'group:type',
  //                 'callback' => 'themekey_og_nid2type');

  return array('attributes' => $attributes, 'maps' => $maps);
}

/**
* Implements hook_themekey_paths().
*/
function themekey_og_themekey_paths() {
  $paths = array();
  
  $paths[] = array('path' => 'group/%group:type/#group:id/%');
  
  return $paths;
}

/**
 * ThemeKey mapping function to set a
 * ThemeKey property's value (destination)
 * with the aid of another ThemeKey property (source).
 *
 * src: node:nid
 * dst: group:id
 *
 * @param $nid
 *   a node id
 *
 * @return
 *   int
 *   or NULL if no value could be mapped
 */
function themekey_og_nid2gid($nid){
  // look for group info from context
  if ($group = og_context()){
    return $group['gid'];
  }
  
  return NULL;
}

I will commit this one to git, so you could easily test it.

daggerhart’s picture

mkalkbrenner,

That all looks good and makes sense to me. I've been too busy to test this so far, but will get to it this week.

Just for reference, if you want the group_type property it works almost the same way as the group_id.

Example:

function themekey_og_nid2type($nid){
  // look for group info from context
  if ($group = og_context()){
    return $group['group_type'];
  }
 
  return NULL;
}
mkalkbrenner’s picture

Just committed themekey_og_nid2type() to git.

Would be great if you can test all this stuff.

Last thing to implement: A validator for property group:type that verifies the input in the chain against the available group types.

mkalkbrenner’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

SocialNicheGuru’s picture

it might be nice to incorporate https://drupal.org/project/og_theme features here so that the theme can be changed on a per group basis