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

CommentFileSizeAuthor
at_pass_theme_name.diff5.92 KBJacobSingh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JacobSingh’s picture

Status: Active » Needs review
agupta’s picture

Status: Needs review » Active

+1 This patch works well.

agupta’s picture

Status: Active » Needs review
Jeff Burnz’s picture

Indeed 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() and at_build_page_layout() be:

  if ($theme_name == NULL) {
    global $theme_key;
    $theme_name = $theme_key;
  }

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.

JacobSingh’s picture

Yeah, 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.

Jeff Burnz’s picture

Status: Needs review » Fixed

Great, I committed it. Thanks for the patch Jacob, very much appreciated.

Status: Fixed » Closed (fixed)

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