The function _themekey_property_field($value, $path) contains a cast to array that destroys the actual value here.

function _themekey_property_field($value, $path) {
  //
  $parts = explode('/', $path);
  foreach ($parts as $part) {
    if (is_array($value) && isset($value[$part])) {
      $value = (array)$value[$part];
    }
    else {
      return NULL;
    }
  }
  
  return is_array($value) ? array_keys($value) : $value;
}

If I, say, had a path of "node:nid" and the (scalar) value of "14" as actual nid then the cast to array would result in array(0 => "14").

The is_array() in the return statement is then true, of course, and as a result what is returned is an array with just the keys, which means an array with a single element: array(0 => 0). The actual data is lost.

If I remove the cast to array the code works for me:

$value = $value[$part];

Comments

cspitzlay’s picture

Is there anyone else experiencing this?
I.e. defined rules for nid or hostname not working?

mkalkbrenner’s picture

Status: Active » Needs review
StatusFileSize
new659 bytes

This issue was already mentioned at http://drupal.org/node/369065#comment-1252638 but wasn't fixed.
I confirm that the bug still exists in Release 6.x-1.1 2009-Mar-29.
Here's a patch to fix it.

muhleder’s picture

Works for me too, was seeing the same issue and tracked down the bug to the same place independently.

mkalkbrenner’s picture

Status: Needs review » Reviewed & tested by the community
davemybes’s picture

Priority: Normal » Critical

Great catch! I noticed that the theme wasn't changing on book:bid and I was happy to see a patch out already for this bug. By adding the patch, the theme changes as expected, and if I remove it, theme switching stops. Bumping to critical as things simply don't work properly without it.

mkalkbrenner’s picture

Due to the fact that ThemeKey currently seems to be unmaintained (see #552994: Maintenance? ThemeKey appears to be abandoned) you can download a patched version of ThemeKey 6.x-1.1 from
http://drupal.cocomore.com/de/project/themekey
that fixes these critical issues:

mkalkbrenner’s picture

Assigned: Unassigned » mkalkbrenner
sinasalek’s picture

I see that you're the maintainer of this module, is this comment still valid?

mkalkbrenner’s picture

Status: Reviewed & tested by the community » Needs review

I'm currently reviewing my own patch from #2 again if it breaks any other feature within ThemeKey I'm currently nor aware of.
This part of the code seems to be written for paths initially. But now it's also used for properties.

@sinasalek #8:
You can still download a patched version from the link provided at #6 until ThemeKey 6.x-1.2 is released. This version seems to work for some users better than the unpatched one. I'll remove the external package as soon as ThemeKey 6.x-1.2 is released.
I'm maintaining this module for two days now. So it will take some time until I'm familiar with all the code.

sinasalek’s picture

Great, wish you luck.

mkalkbrenner’s picture

Status: Needs review » Fixed
StatusFileSize
new9.15 KB

Unfortunately the patch wasn't as easy as expected in comment #2.

The main issue was that all properties where handled as objects because isset($object) always returned true:

function _themekey_match_properties($parameters, $object = NULL) {
  if (isset($object)) {
    $parameters = _themekey_prepare_object(array_merge($parameters, (array)drupal_clone($object)));
  }
  ...
}

But to fix it completely a lot of additional stuff was required ...

mkalkbrenner’s picture

Status: Fixed » Closed (fixed)

released as 6.x-1.2-alpha1