我有一个名为hello_world的drupal模块。
我在drupal/web/modules/custom/hello_world
中有一个名为 hello_world.info.yml
的信息文件,其中包含:
name: Hello World
description: Hello World module
type: module
core: 8.x
package: Custom
这工作得很好;模块在扩展列表中。
现在我尝试制作一个帮助钩子,所以我在同一文件夹中使用以下代码制作了一个hello_world.module
文件:
<?php
use DrupalCoreRoutingRouteMatchInterface;
/**
* Implements hook_help().
*/
function hello_world_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.hello_world':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This is an example module.') . '</p>';
return $output;
break;
}
}
这根本行不通。不显示帮助页面。
我还尝试在drupal/web/modules/custom/hello_world/src/HelloWOrldCOntroller.php
中使用此控制器制作一个hello world页面:
<?php
namespace Drupalhello_worldController;
use DrupalCoreControllerControllerBase;
/**
* Controller for the salutation message.
*/
class HelloWorldController extends ControllerBase
{
/**
* Hello World.
*
* @return string
*/
public function helloWorld()
{
return [
'#markup' => $this->t('Hello World')
];
}
}
而这条路线在drupal/web/modules/custom/hello_world
称为hello_world.routing.yml
:
hello_world.hello:
path: '/hello'
defaults:
_controller:
'Drupalhello_worldControllerHelloWorldController::helloWorld'
_title: 'Our first route'
requirements:
_permission: 'access content'
即使在清除缓存后,这也不起作用。正如我所说,hello_world.info.yml
工作得很好,但帮助钩子和控制器/路由不能。其余的核心模块工作。如果重要的话,我正在使用流浪者。
尝试重新安装模块并清除缓存和路由,否则会遇到错误
hello_world.hello:
path: '/hello'
defaults:
_controller:'Drupalhello_worldControllerHelloWorldController::helloWorld'
_title: 'Our first route'
requirements:
_permission: 'access content'