I installed Hierarchical Select (+Hierarchical Select nodereference) on an OpenAtrium distribution. During creation of new nodes, HS forms worked fine, but while editing a node I get 'Received an Invalid Response from the Server' error. In OpenAtrium, the URL for editing a post within a group 'mygroup' is not mysite.com/node/34/edit, but instead mysite.com/mygroup/node/34/edit. PURL is handling the prefixing (among other things). The prefix 'mygroup' was lacking in the URL contained in the JS setting HierarchicalSelect->basePath. Lack of this group prefix caused the error (PURL redirected to the corrected URL and the request data was lost).

I managed to get HS working by hacking _hierarchical_select_setup_js function in the hierarchical_select.module file to correct the JS property "settings->HierarchicalSelect->basePath". In my case it was enough to pass the $url through purl_url_rewrite function + correct the resulting double slashes.

if (module_exists('purl')) { // this works for clean URLs only
  $dummyarr = array();   
  purl_url_rewrite($url, $dummyarr, $url);  
  $url = str_replace('//', '/', '/' . $url);   
}

I hope this duct-tape hack saves someone some time and maybe Wim will be able to come up with a better solution for future releases.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Title: HS with PURL+spaces+og (Open Atrium) requires path prefixing fix /similar to i18n/ » HS + PURL compatibility: PURL+spaces+og (Open Atrium) requires path prefixing fix similar to i18n
Category: bug » feature
Status: Active » Needs work

Please roll a proper patch.

I'm not going to test this patch, it requires too much time. I won't commit it until at least one other person has confirmed that the patch works and has no side effects.

randallknutson’s picture

Status: Needs work » Needs review
FileSize
1006 bytes

We ran into this exact same problem using purl and hierarchical select. I tried out his ideas and it worked for us. Here is the patch of our modifications.

rbenhase’s picture

Hi,
I'm running Open Atrium with HS + HS Nodereference as well, and I had the exact problem you described. However, neither your tadeusz.zimirsk's hack nor randallknutson's patch has solved the problem for me.

I did notice one thing, however; before the patch, in addition to the "Received an Invalid Response from the Server" error, I would get three error messages printed after a refresh or navigating to another page:

warning: Missing argument 2 for drupal_retrieve_form() in /var/www/Atrium/includes/form.inc on line 326.
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '' was given in /var/www/Atrium/includes/form.inc on line 372.
warning: uasort() [function.uasort]: The argument should be an array in /var/www/Atrium/includes/common.inc on line 2884.

After patching, these error messages do not appear--I just get the "Received an Invalid Response from the Server" error. So, it appears the patches did SOMETHING, but perhaps my problem is elsewhere. I've come across threads regarding HS and compatibility with Ctools and Content Profile, but those issues appear to have been resolved. Is there anything else that this could be?

Wim Leers’s picture

Status: Needs review » Fixed

I'm going to tentatively commit randallknutson's patch: http://drupal.org/cvs?commit=412124

If people still have problems with this, please reopen this issue!

Status: Fixed » Closed (fixed)

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

alexku’s picture

Status: Closed (fixed) » Active
FileSize
1.47 KB

I have a problem with current solution and a setup with $base_path other than /

The problem is that if you have something like '/subfolder' in $base_path purl_url_outbound_alter() thinks that it is part of the query and in the result you get url like '/og_group_name/subfolder'.

So I think the logic should be:

1. add clean_url part if it is necessary (at this point we might have 'index.php?q=')
2. add language prefix if it is necessary (at this point we might have 'index.php?q=lt/')
3. ask purl_url_outbound_alter if it wants to add something (it might give us 'og_group_name/' for example)
4. get $base_path (it might be something like '/subfolder/')
5. combine three parts and get for example: /subfolder/index.php?q=lt/og_group_name/

I have attached a patch which works for me with openatrium in a subfolder multisite install. I have also tested it with clean urls off and with language prefix on.

Wim Leers’s picture

Status: Active » Needs review
paolomainardi’s picture

FileSize
874 bytes

Same problem here, i've just found another solution, removing base_path() from $url before to get it processed by purl and re-added just after, in order to preserve language, cleanurl, etc.

Patch in the attachment.

Wim Leers’s picture

If alexku could confirm that your patch is working, I could commit it. I'd need a proper patch though, this patch can't be applied with the patch command. And you'd need to make some changes to comply with the Drupal coding standards.

paolomainardi’s picture

FileSize
724 bytes

In the attachment the corrected patch in order to be applied with usual patch command, sorry it was previously created within my git repository.

I've just fixed the space on string concatenation as requested by Drupal coding standard, i think it will be enough.

Wim Leers’s picture

Thanks for the re-roll! :) Now all we need is confirmation from alexku!

alexku’s picture

I can confirm that it does work, but I wouldn't rely on str_replace

Maybe it would be safer to check if string begins with base_path?

Wim Leers’s picture

Status: Needs review » Needs work

Agreed, let's fix that.

alexku’s picture

Status: Needs work » Needs review

Sorry, I didn't test the language prefix properly.

Patch by paolomainardi doesn't work with language prefix, because purl still gets it and thinks that it is part of the query.

I'm staying with my patch in #6 because it has been on a live site for almost two month without any issue

vectoroc’s picture

FileSize
2.51 KB

I dont understand why you used these hacks?

There is my patch (works with purl+spaces / lang prefix).

vectoroc’s picture

@Wim Leers: what do you think about my patch? is it sufficient?

btopro’s picture

Can confirm that this patch works in PURL / OG / Spaces based environments like open atrium.

alippai’s picture

Works with OpenAtrium.