定制块在Drupal 8中不工作 [英] Custom blocks not working in Drupal 8

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

问题描述

我正在Drupal 8 beta 9中构建一个带有自定义块的模块。当我在模块中创建一个块时,将其放在src\Plugin\Block目录中。 块结构列表中的块显示,但是当我按链接添加它时,没有任何反应。
我审查了我的代码10次,试图将我的文件放入核心模块的目录(仅用于测试显然),试图将一些核心块文件放在我的目录下,以复制粘贴代码。这些都不行。以下是我的封锁文件的代码:

 <?php 
/ **
*文件
*包含\Drupal\internetdevels\Plugin\Block\TestBlock。
* /

命名空间Drupal\internetdevels\Plugin\Block;
使用Drupal\Core\Block\BlockBase;

/ **
*提供我的自定义块。
*
* @Block(
* id =my_custom_block,
* admin_label = @Translation(我的自定义块),
* category = @Translation (系统),
*)
* /
class TestBlock扩展BlockBase {

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

}


解决方案

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


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 src\Plugin\Block 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 \Drupal\internetdevels\Plugin\Block\TestBlock.
 */

namespace Drupal\internetdevels\Plugin\Block;
use Drupal\Core\Block\BlockBase;

/**
 * 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');
  }

}

解决方案

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天全站免登陆