I’ve massaged this enough times but apparently it’s not enough. Hopefully this resolves any remaining issues.

Setting values

Take this example.

settings[foo.a.b.c] = abc
settings[foo.c.a.b] = cab
settings[foo.b.c.a] = bca
print var_dump(hex_setting('foo'));
// will output:
//  array
//    'a' => 
//      array
//        'b' => 
//          array
//            'c' => 'abc'
//    'c' => 
//      array
//        'a' => 
//          array
//            'b' => 'cab'
//    'b' => 
//      array
//        'c' => 
//          array
//            'a' => 'bca'

// And to get a sub-section, these work too:
print var_dump(hex_setting('foo.a'));
// will output:
//  array
//    'b' => 
//      array
//        'c' => 'abc'

print var_dump(hex_setting('foo.a.b'));
// will output:
//  array
//    'c' => 'abc'

print var_dump(hex_setting('foo.a.b.c'));
// will output:
//  string 'abc'

The above is the expected behavior. Each '.' is converted into a multidimensional array but this next example runs into problems.

settings[foo.a.b.c][] = abc
settings[foo.c.a.b][] = cab
settings[foo.b.c.a][] = bca
print var_dump(hex_setting('foo'));
// will output NULL.

Appending values like an array by using the empty square brackets will not register.

Parent conditional values

This is a parent conditional setting.

settings[parent_switch] = true
settings[parent_switch:foo] = foo
settings[parent_switch:bar] = bar
print var_dump(hex_setting('parent_switch:foo'));
// if parent_switch is true then this will output foo.
print var_dump(hex_setting('parent_switch:bar'));
// if parent_switch is true then this will output bar.

That works just fine but what happens with the following?

// Get setting from child-most theme.
hex_setting('parent_switch:foo', NULL, HEX_CASCADE);
// Get setting from parent-most theme.
hex_setting('parent_switch:foo', NULL, HEX_REVERSE_CASCADE));

It's currently not accounted for and will give unpredictable results. The following patch will enforce the following behavior.

HEX_CASCADE
The child-most theme takes precedence but the setting will only register if it also enables the parent switch. If it is disabled, it will fallback to its closest parent with the values AND parent switch. (emphasis: this check didn’t exist before.)
HEX_REVERSE_CASCADE
The exact opposite of HEX_CASCADE. First parent with the setting and parent switch will determine what gets returned.

With both cascade types, each setting can be picked up from separate themes. Information is passed through and this also applies to the saved theme api form settings.

base theme:

settings[some_feature.foo] = base

sub-theme:

settings[some_feature.bar] = sub-theme
hex_setting('some_feature', NULL, HEX_CASCADE);
// will output:
//  array
//    ‘foo' => ‘base’
//    ‘bar’ => ‘sub-theme'
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dvessel’s picture

Status: Active » Fixed
FileSize
9.9 KB

This also removes hex_settings (plural). It might come back but there’s no use for it right now. That was old copied code from another theme I was working on.

dvessel’s picture

Whoops, small followup. There’s a similar function to hex_setting when dealing with form settings ‘ hex_themeapi_setting’. It didn’t get the needed changes.

Status: Fixed » Closed (fixed)

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