【发布时间】:2020-06-03 22:00:54
【问题描述】:
我正在构建一个自定义 Drupal 8 模块,它将根据衍生插件 ID 对 Webform 进行更改。我可以使用 $this->getDerivativeId() 从基本块的 build() 函数中获取派生插件 ID,但不清楚如何从 @ 调用 getDerivativeId() 987654323@ 我使用的是hook_form_alter。
任何帮助将不胜感激。这是我迄今为止尝试过的但没有成功的方法:
-
我首先直接从
hook_form_alter厌倦了$this->getDerivativeId(),但我得到了一个错误“不在对象上下文中使用 $this”
-
然后我尝试在我的基块类中创建一个名为“getCurrentBlockId()”的新函数,我将尝试返回
getDerivativeId()值,但它迫使我将函数设为静态,一旦我这样做了,我就不能再使用$this->getDerivativeId()。$block_id = \Drupal\transcode_profile\Plugin\Block\TranscodeBlockDerivative::getCurrentBlockId(); 我还尝试创建一个构造函数来将派生块 ID 保存到一个变量,该变量可以在我的模块范围内访问,但也失败了。
总之,我可以使用$this->getDerivativId()...
\Drupal\transcode_profile\Plugin\Block\TranscodeBlockDerivative
但需要使用...
\Drupal\transcode_profile\transcode_profile.module
不知道该怎么做。
提前致谢!
【问题讨论】:
标签: php oop drupal block drupal-8