首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法触发带注释的插件发现

无法触发带注释的插件发现
EN

Drupal用户
提问于 2021-01-31 21:49:26
回答 1查看 163关注 0票数 -1

我检查了调试插件发现,并尝试重新启动Apache并设置$settings = FALSE;在settings.php中,没有进行任何更改。

我有一个定制模块。在我所知道的任何位置设置一个断点应该可以工作,包括我的模块的配置表单。

该模块定义了带注释类型的插件,我无法在插件管理器中触发任何代码。我还注意到,我使用了一个cont肋骨模块作为模型,它的插件管理器中的代码也不能中断。

如果我将该模块称为'x',则在x/src/XManager.php中有:

代码语言:javascript
复制
namespace Drupal\x;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\x\Annotation\X;

/**
 * Class XManager
 *
 * @package \Drupal\x
 */
class XManager extends DefaultPluginManager {

  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    $subdir = 'Plugin/X';
    $plugin_interface = XInterface::class;
    $plugin_definition_annotation_name = X::class;
    parent::__construct($subdir, $namespaces, $module_handler, $plugin_interface, $plugin_definition_annotation_name);
    $this->alterInfo('x_info');
    $this->setCacheBackend($cache_backend, 'x_plugins');
  }
  
}

以及在x/src/注释/x.php中

代码语言:javascript
复制
namespace Drupal\x\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
 * @see plugin_api
 *
 * @Annotation
 */
class X extends Plugin {

  /**
   * The plugin ID.
   *
   * @var string
   */
  public $id;

  /**
   * The plugin label.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $label;

  /**
   * The plugin field type IDs.
   *
   * @var array
   */
  public $field_type_ids = [];

}

以及在x/src/Plugin/X/XTest.php中

代码语言:javascript
复制
namespace Drupal\x\Plugin\XTest;

/**
 * Class XTest.
 *
 * @X(
 *   id = "x_test",
 *   label = @Translation("X Test"),
 *   field_types = {
 *     "text",
 *     "text_long",
 *     "text_with_summary",
 *   },
 *
 * )
 */
class XTest {

}
EN

回答 1

Drupal用户

回答已采纳

发布于 2021-02-02 07:41:00

要调试插件管理器,请将其用作服务并获取已发现的插件:

代码语言:javascript
复制
$type = \Drupal::service('plugin.manager.archiver');
$plugin_definitions = $type->getDefinitions();

这将从缓存中获取插件定义。如果由于添加或修改了插件注释而希望重新运行发现过程,则清除整个Drupal缓存,或者只清除特定于插件管理器的缓存:

代码语言:javascript
复制
$type->clearCachedDefinitions();

参考资料:https://www.drupal.org/docs/drupal-apis/plugin-api/creating-your-own-plugin-manager

票数 1
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/299871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档