自定义块在 Drupal 8 中不起作用 [英] Custom blocks not working in Drupal 8

查看:26
本文介绍了自定义块在 Drupal 8 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Drupal 8 beta 9 中构建一个带有自定义块的模块.当我在我的模块中创建一个块时,我将它放在 srcPluginBlock 目录中.该块显示在块结构"列表中,但是当我按链接添加它时,没有任何反应.我检查了我的代码 10 次,尝试将我的文件放入核心模块的目录中(显然仅用于测试),尝试将一些核心块文件放入我的目录中,以复制粘贴代码.这些都不起作用.这是我的块文件的代码:

I'm building a module with custom block in Drupal 8 beta 9. When I create a block in my module I'm placing it in srcPluginBlock directory. The block show in 'Block structure' list, but when I press link to add it, nothing happens. I reviewed my code 10 times, tried to put my files into core module's directories (only for test obviously), tried to put some core block files to my directory, to copy-paste code. None of this works. Here is a code of my block file:

<?php
/**
 * @file
 * Contains DrupalinternetdevelsPluginBlockTestBlock.
 */

namespace DrupalinternetdevelsPluginBlock;
use DrupalCoreBlockBlockBase;

/**
 * Provides 'my custom' block.
 *
 * @Block(
 *   id = "my_custom_block",
 *   admin_label = @Translation("My Custom Block"),
 *   category = @Translation("System"),
 * )
 */
class TestBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    return array('#markup' => 'hello world');
  }

}

推荐答案

在 D8 中,禁用的块不再自动出现在 admin/structure/block 上的禁用下.首先,您必须单击禁用区域的放置块"按钮.然后您可以从您的自定义模块中选择块.

In D8, disabled blocks no longer automatically appear under Disabled on admin/structure/block. First, you have to click the 'Place block' button for the Disabled region. Then you can select the block from your custom module.

这篇关于自定义块在 Drupal 8 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆