简体   繁体   English

升级Drupal后表单中的$ base_url问题

[英]$base_url problems in forms after upgrading Drupal

I believe I followed the instructions when upgrading Drupal (7.33 -> 7.39), but managed to break it. 我相信我在升级Drupal(7.33-> 7.39)时遵循了说明,但是设法打破了它。

The setup: The Drupal site is behind a reverse proxy: 设置:Drupal站点位于反向代理后面:

<Location /app>
  ProxyPass http://back.example.com/drupal
  ProxyPassReverse http://back.example.com/drupal
  ProxyPassReverseCookiePath /drupal /app
</Location>

And in the sites/default/settings.php , there's this bit: sites/default/settings.php ,有以下内容:

$conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR';
if (!empty($_SERVER[$conf['reverse_proxy_header']])) {
  $base_url = 'http://front.example.com/app';
}

The problem: While some forms seem to work, generating a correct action attribute ( <form action="/app/..." ...> ), most (notably, everything in Admin area) are ignoring the $base_url , generating <form action="/drupal/..." ...> , so submit obviously fails. 问题:虽然某些表单似乎可以工作,但生成正确的action属性( <form action="/app/..." ...> )时,大多数(尤其是Admin区域中的所有内容)都忽略了$base_url ,生成了<form action="/drupal/..." ...> ,所以提交显然失败了。

I took a look at the source, but I can't figure out how it worked in the first place, because, as far as I can see, action is generated from drupal_build_form , which reads the action data from element_info('form') , which is populated by system_element_info , which, in turn, calls request_uri() - and there is nothing in request_uri() about $base_url . 我查看了源代码,但一开始我不知道它是如何工作的,因为据我drupal_build_formaction是从drupal_build_form生成的,它从element_info('form')读取动作数据,这是由人口system_element_info ,这反过来,调用request_uri() -并且在没有request_uri()$base_url

I tried to clear caches with drush just in case I was missing something in the database, and it did not help. 我试图用drush清除缓存, drush万一我丢失了数据库中的某些内容,但是这样做没有帮助。

EDIT: It seems most of the links are calling the url($path) function, which does the right thing. 编辑:似乎大多数链接都在调用url($path)函数,该函数做了正确的事。 But it is not being called for the form's action attribute, except for a form that is being rendered from a plugin (and which doesn't seem to use element_info , but calls url to construct its action ). 但这不是为表单的action属性调用的,除了从插件中呈现的表单(它似乎并没有使用element_info ,而是调用url构造其action )。

EDIT2: If it was not clear, $base_url has the correct value; EDIT2:如果不清楚,则$base_url具有正确的值; it is just not getting applied (and I can't see where it would be applied). 它只是没有被应用(我看不到它将在哪里应用)。

The problem is indeed in system_element_info calling request_uri which is not taking care of $base_url... 问题确实出在system_element_info调用request_uri而不照顾$ base_url ...

But as always in drupal you can alter things: 但是像往常一样,您可以更改:

function yourmodule_element_info_alter(&$type) {
  global $base_url;

  // Use $base_url for form action
  $type['form']['#action'] = $base_url . request_path();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM