简体   繁体   English

自定义模块未出现在Drupal中

[英]Custom Module does not appear in Drupal

I am required to build a Drupal module that collects data from an API and create a block on the page displaying the data in a specified format. 我需要构建一个Drupal模块,该模块从API收集数据并在页面上创建一个块,以指定格式显示数据。 I have downloaded and installed Drupal 8.0 Alpha2. 我已经下载并安装了Drupal 8.0 Alpha2。

According to all the scattered un-infomal bits and pieces of information I have gotten I am really struggling to even see what I am trying to do. 根据我得到的所有零散的非零散的信息,我真的很难甚至看不到我要做什么。

Inside modules I have created a directory called custom and inside it placed a folder named "sidebar_currency". 在模块内部,我创建了一个名为custom的目录,并在其中放置了一个名为“ sidebar_currency”的文件夹。

The *.info.yml * .info.yml

I have created this file with its minimum requirements: 我创建的文件具有最低要求:

name: Sidebar Currency module
description: 'Exercise Module.'
package: Custom
hidden: false
type: module
core: 8.x

I added the hidden:false entry since I have been getting a "page not found" error. 我添加了hidden:false条目,因为出现了“找不到页面”错误。

The routing is as follows: 路由如下:

sidebar_currency.content:
  path: '/currency'
    defaults:
      _controller: 'Drupal\sidebar_currency\Controller\SidebarCurrencyController::content'
      _title: 'Sidebar Currency'
      requirements:
        _permission: 'access content'

In the controller entry I have tried to add a backslash before the Drupal namespace eg '\\Drupal\\sidebar_currency...'. 在控制器条目中,我尝试在Drupal名称空间之前添加反斜杠,例如'\\ Drupal \\ sidebar_currency ...'。 This did not help at all. 这根本没有帮助。

Below is my structure of my module: 以下是我的模块结构:

DRUPAL_INSTALL_DIR
|_ modules
  |_ custom
    |_ sidebar_currency
      }_ src
        |_ Controller
          |_ SidebarCurrencyController.php
      |_ sidebar_currency.info.yml
      |_ sidebar_currency.routing.yml
      |_ composer.json

Below is my controller which I would very much expect to see popping up something on my screen. 下面是我的控制器,我非常希望看到它在屏幕上弹出。

namespace Drupal\sidebar_currency\Controller;

use Drupal\Core\Controller\ControllerBase;

class SidebarCurrencyController extends ControllerBase
 {
   public function content()
   {
       return array(
          '#type' => 'markup',
          '#markup' => $this->t('List of currency'),
        );
     }
  }

I am struggling to see this module in my Extend tab on the CMS except for all the rest of modules that have been pre-installed. 我很难在CMS的“扩展”选项卡中看到此模块,除了已预安装的所有其余模块之外。 I have clear all cache from the configuration menu and still cannot see anything. 我已经从配置菜单中清除了所有缓存,但仍然看不到任何内容。

Do I need to write my code inside sites instead of where it currently is sitting? 我需要在站点内部而不是当前位置编写代码吗? Can somebody please help and point me to the right direction as to how I am suppose to go about doing this? 有人可以帮助我,向我指出正确的方向吗? Thanks in advance. 提前致谢。

It turns out that all I need to do in order for my module to show up was to add module_name .module file even if it is empty ie with no contents. 事实证明,要显示我的模块,我要做的就是添加module_name .module文件,即使该文件为空(即不包含任何内容)。

在此处输入图片说明

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

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