我创建了Joomla插件,我希望在登录表单中添加iframe。首先,我创建了用于添加自定义字段的组件,使用它来添加到我的插件中的xml,使用" onContentPrepareForm"。我想知道在不更改核心joomla文件的情况下这样做的最佳实践。
myPlugin.php
public function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option) {
case 'com_users':
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('iframe', false);
return true;
}
return true;
}
com_myfield
class JFormFieldIframe extends JFormField {
protected $type = 'iframe';
// getLabel() left out
public function getInput() {
// generate and empty object
$plgParams = new JRegistry();
// get plugin details
$plugin = JPluginHelper::getPlugin('system','myPlugin');
// load params into our params object
if ($plugin && isset($plugin->params)) {
$plgParams->loadString($plugin->params);
}
$my_code = $plgParams->get('code','');
return '<iframe src="//yourdomain.com/abc.php?key='. $my_code
. '" id="'.$this->id.'" name="'.$this->name.'" />';
}
}
iframe.xml
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="iframe" >
<fieldset name="iframe" addfieldpath="/administrator/components/com_myfield/fields">
<field name="myiframe" type="iframe" default="" label="" description=""/>
</fieldset>
</fields>
</form>
请尽快回复我有截止日期。
谢谢!
答案 0 :(得分:0)
您是否考虑过使用组件模板覆盖?这听起来就像你正在尝试做的那样。
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
或者,您可以使用JDocument / getBuffer(&#39;组件&#39;)获取组件的内容,修改它,然后将其缓存回JDoc。 api.joomla.org/cms-3/classes/JDocument.html虽然我坚持使用模板覆盖,但它是一个更清洁的解决方案。