我检查了调试插件发现,并尝试重新启动Apache并设置$settings = FALSE;在settings.php中,没有进行任何更改。
我有一个定制模块。在我所知道的任何位置设置一个断点应该可以工作,包括我的模块的配置表单。
该模块定义了带注释类型的插件,我无法在插件管理器中触发任何代码。我还注意到,我使用了一个cont肋骨模块作为模型,它的插件管理器中的代码也不能中断。
如果我将该模块称为'x',则在x/src/XManager.php中有:
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中
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中
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 {
}发布于 2021-02-02 07:41:00
要调试插件管理器,请将其用作服务并获取已发现的插件:
$type = \Drupal::service('plugin.manager.archiver');
$plugin_definitions = $type->getDefinitions();这将从缓存中获取插件定义。如果由于添加或修改了插件注释而希望重新运行发现过程,则清除整个Drupal缓存,或者只清除特定于插件管理器的缓存:
$type->clearCachedDefinitions();参考资料:https://www.drupal.org/docs/drupal-apis/plugin-api/creating-your-own-plugin-manager
https://drupal.stackexchange.com/questions/299871
复制相似问题