【问题标题】:Drupal 8 custom block shows up in block list but can't be addedDrupal 8 自定义块显示在块列表中但无法添加
【发布时间】:2016-08-25 13:28:30
【问题描述】:

我在创建自定义块时遇到了问题。同一模块内还有其他块,可以添加并且工作正常。

这是代码(文件名是 /modules/custom/custom_blocks/Plugin/Block/ 中的 TourLink.php):

<?php
/**
 * Provides a block that links to /tour
 *
 * @Block(
 *   id = "tour_link",
 *   admin_label = @Translation("Tour Link"),
 * )
 */

namespace Drupal\custom_blocks\Plugin\Block;

use Drupal\Core\Block\BlockBase;

class TourLink extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    $output = '
    <span>test</span>
    ';

    return array(
      '#type' => 'markup',
      '#markup' => $output,
    );
  }

}

提前致谢!

【问题讨论】:

  • 类注释位于类声明之前的文档块的末尾(参见Annotations)。我不确定,但也许这真的很重要。
  • 谢谢,但事实并非如此。

标签: drupal module drupal-8


【解决方案1】:

将课程(当然还有文件)重命名为 LinkToTourBlock 解决了这个问题。为什么,我不知道。此外,TourLinkBlock 也不起作用。好奇怪!

【讨论】:

    猜你喜欢
    • 2020-06-11
    • 2016-10-05
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 1970-01-01
    相关资源
    最近更新 更多