定制块在Drupal 8中不工作 [英] Custom blocks not working in Drupal 8
问题描述
我审查了我的代码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屋!