如何在drupal 8中创建外部菜单链接?

时间:2017-11-16 06:20:39

标签: symfony menuitem drupal-8

我想创建一个外部菜单链接,这是我的代码。

class MyClass extends DeriverBase implements ContainerDeriverInterface {
    public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];

    $sites = [
        'www.google.com' => 'http://gwa-caromaww2.netsol.local/',
        'www.drupal.org' => 'http://drupal.org/'
    ];

    foreach ($sites as $key => $site) {
      $links['sites'.$key] = [
        'title' => $key,
        'path' => $site,
      ] + $base_plugin_definition;
    }

    return $links;
  }
}

当我安装自定义模块时,它会产生一个错误:

  

Symfony \ Component \ Routing \ Exception \ RouteNotFoundException:路由“”不存在。在Drupal \ Core \ Routing \ RouteProvider-> getRouteByName()中(D:\ workspace \ projects \ caromaww \ core \ lib \ Drupal \ Core \ Routing \ RouteProvider.php的第190行)。

1 个答案:

答案 0 :(得分:0)

尝试:

 passing 'url' => $site 

代替路径。

外部指向菜单链接将使用url值 https://www.drupal.org/docs/8/api/menu-api/providing-module-defined-menu-links