Currently, when you install commons 3.x you get this:
WD php: Warning: Invalid argument supplied for foreach() in [warning]
responsive_page_layouts_data_structure() (line 192 of
/home/u6195/domains/u6195.moko.vps-private.net/profiles/commons/themes/contrib/adaptivetheme/at_core/inc/plugins.inc).
I spent awhile tracking it down.
Commons does this to automate saving the theme settings form:
(from commons.install)
<?php
foreach (array('adaptivetheme', 'commons_origins') as $theme_name) {
$form_state = form_state_defaults();
$form_state['build_info']['args'][0] = $theme_name;
$form_state['values'] = array();
drupal_form_submit('system_theme_settings', $form_state);
}
?>
This is anyway a little hacky, but there isn't any other way to automate it.
This issue is that at_core_submit_reponsive() takes $theme_name as an argument, but it calls at_build_page_layout() several times without passing in $theme_name. at_build_page_layout() doesn't take $theme_name, it uses a global $theme_key or $theme_name, as does responsive_page_layouts_data_structure() which it calls (where the error happens, because it is using "seven", not the passed in theme.
This patch adds $theme_name arguments to both those functions, allowing them to use the global var if it is not provided.
I don't think this is an ideal solution, but it's better than what it is there now which is sorta lying to the implementor who believes they can actually pass in a theme and have it used.
I recommend committing this as a stop gap, but following up by removing global variables from any supporting functions. If we are going to use a global var it should only be in the a submit handler or callback IMO so it is easily traceable and the API remains flexible.
Thanks!
J
Comment | File | Size | Author |
---|---|---|---|
at_pass_theme_name.diff | 5.92 KB | JacobSingh |
Comments
Comment #1
JacobSingh CreditAttribution: JacobSingh commentedComment #2
agupta CreditAttribution: agupta commented+1 This patch works well.
Comment #3
agupta CreditAttribution: agupta commentedComment #4
Jeff Burnz CreditAttribution: Jeff Burnz commentedIndeed nothing is ideal here, reliance on globals is quite problematic as I discovered on numerous occasions when building many of these functions.
The patch looks good and a nice improvement, I just have one niggle.
Shouldn't the logic to determine the theme name in both
responsive_page_layouts_data_structure()
andat_build_page_layout()
be:I.E consistently use $theme_name as the argument and always use global $theme_key if its NULL.
In the patch at_build_page_layout() correctly ask if $theme_name is NULL but then declares a global $theme_name but sets no value for it - which looks like a mistake to me, and that it should declare the existing global $theme_key and set that as the value of $theme_name (as I do in the code example above.
In the patch responsive_page_layouts_data_structure() uses $theme_key as the argument, then ask if its empty, and if so declares global $theme_key, which sets the value of $theme_name - correct, this will work and is not a mistake.
Unless I am missing something I will use the code example above which to my mind is correct for both functions. Have I missed something here?
If I havent no need for a new patch, I can commit this with my small changes.
Comment #5
JacobSingh CreditAttribution: JacobSingh commentedYeah, totally. The code was already using both variants, so I tried to minimally invasive and not change the variable names being used. Feel free to re-roll and commit.
Comment #6
Jeff Burnz CreditAttribution: Jeff Burnz commentedGreat, I committed it. Thanks for the patch Jacob, very much appreciated.