Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有processOutbound和preg_replace的Drupal 8 Url更改_Php_Url_Drupal_Drupal 8_Alter - Fatal编程技术网

Php 带有processOutbound和preg_replace的Drupal 8 Url更改

Php 带有processOutbound和preg_replace的Drupal 8 Url更改,php,url,drupal,drupal-8,alter,Php,Url,Drupal,Drupal 8,Alter,我在一个Drupal网站上工作,我需要将所有包含“成员”的URL更改为“追随者” 例: www.site.com/member==>www.site.com/follower www.site.com/members==>www.site.com/followers www.site.com/members/1/info==>www.site.com/followers/1/info www.site.com/something/member==>www.site.com/something/

我在一个Drupal网站上工作,我需要将所有包含“成员”的URL更改为“追随者”

例:

  • www.site.com/member==>www.site.com/follower
  • www.site.com/members==>www.site.com/followers
  • www.site.com/members/1/info==>www.site.com/followers/1/info
  • www.site.com/something/member==>www.site.com/something/follower
等等

我尝试了一些不起作用的东西,然后我发现processOutbound似乎是在我所有URL中用“follower”替换“member”的正确方法

但它也不起作用。你们能帮我解决这个问题吗

请在下面找到我的班级代码

class SquarePathProcessor implements InboundPathProcessorInterface, OutboundPathProcessorInterface {

  public function processInbound($path, Request $request) {

    return $path;
  }

  public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    return preg_replace('@^/member(.*)@', '/follower$1', $path);
  }
}

我做到了!!!以下是解决方案:

class SquarePathProcessor implements InboundPathProcessorInterface, OutboundPathProcessorInterface {

  public function processInbound($path, Request $request) {
    if (strpos($path, '/follower') === 0) {
      $path = preg_replace('#^/follower#', '/member', $path);
    }
    return $path;
  }

  public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    if (strpos($path, '/member') === 0) {
      $path = preg_replace('#^/member#', '/follower', $path);
    }
    return $path;
  }

}
谢谢大家