将按钮类型添加到Joomla插件XML配置中

huangapple go评论61阅读模式
英文:

Adding a button type to joomla plugin xml config

问题

我已创建一个 Joomla 插件,并在 XML 文件中添加了以下代码中的 2 个字段。我想要添加一个按钮类型。由于我在 Joomla 中找不到按钮类型,该如何实现?我正在使用 Joomla v4。
请参考下面的截图以更清楚地了解我正在寻找的内容。
[![Joomla 配置屏幕][1]][1]
英文:

I have created a joomla plugin and added 2 fields in xml file with the below code. I want to add a button type. As I don't find the button type in joomla, how to achieve this? I am using Joomla v4.

             <fieldset name="basic">
                 <field
						name="email"
						type="text"
						filter="raw"
						default=""
						label="PLG_EDITORS-XTD_XXX_FIELD_EMAIL"
						description="Enter your XXX Email"
						size="50"/>
				<field
						name="password"
						type="password"
						label="PLG_EDITORS-XTD_XXX_FIELD_PASSWORD"
						description="Enter the password"
						maxlength="25"
						size="30"/>
			</fieldset>

Please refer the screenshot for better clarity on what I was looking for.
将按钮类型添加到Joomla插件XML配置中

答案1

得分: 1

你需要构建一个自定义字段类型,将其存储在你的插件中,并在你的插件的XML文件中加载它。

参考 plugins/system/stats 插件。它像这样定义了自定义字段类型 data

			<fieldset name="basic" addfieldprefix="Joomla\Plugin\System\Stats\Field">
				<field
					name="data"
					type="data"
					label=""
				/>
			</fieldset>

data 字段存储在 plugins/system/stats/src/Field/DataField.php 中,最终的HTML从布局 plugins/system/stats/layouts/field/data.php 渲染。在你的情况下,你自定义字段类型的布局是用于渲染登录按钮的。

英文:

You need to build a custom field type, store it in your plugin and load it in your plugin's XML file.

Take a look at plugins/system/stats plugin. It defines the custom field type data like this:

			&lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\System\Stats\Field&quot;&gt;
				&lt;field
					name=&quot;data&quot;
					type=&quot;data&quot;
					label=&quot;&quot;
				/&gt;
			&lt;/fieldset&gt;

The data field is stored in plugins/system/stats/src/Field/DataField.php, the final HTML is rendered from the layout plugins/system/stats/layouts/field/data.php. In your case, your custom field type's layout is the one rendering the login button.

答案2

得分: 0

Sure, here are the translated parts:

  1. 为登录按钮添加一个字段,该字段将是自定义类型,让我们称之为 loginbtn:
&lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\&lt;Your plugin group&gt;\&lt;Your plugin name&gt;\Field&quot;&gt;
    &lt;field
        name=&quot;email&quot;
        type=&quot;text&quot;
        filter=&quot;raw&quot;
        default=&quot;&quot;
        label=&quot;PLG_EDITORS-XTD_XXX_FIELD_EMAIL&quot;
        description=&quot;输入您的XXX电子邮件&quot;
        size=&quot;50&quot;/&gt;
    &lt;field
        name=&quot;password&quot;
        type=&quot;password&quot;
        label=&quot;PLG_EDITORS-XTD_XXX_FIELD_LOGINBTN&quot;
        description=&quot;登录&quot;/&gt;
&lt;/fieldset&gt;
  1. 在 plugins/<Your plugin group>/<Your plugin name>/src/Field 中创建一个名为 Loginbtn.php 的文件。

Loginbtn.php 代码:

&lt;?php
defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;

class JFormFieldLoginbtn extends FormField
{
    protected $type = 'loginbtn';

    protected function getInput()
    {
        $html = '&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; class=&quot;your btn class&quot; /&gt;';

        return $html;
    }

    public function getLabel() {
        return '&lt;span style=&quot;text-decoration: underline;&quot;&gt;' . parent::getLabel() . '&lt;/span&gt;';
    }
}
  1. 在插件的 XML 文件中添加一个 Field 文件夹:
<files>
    <folder>field</folder>
</files>

请注意,这些是您提供的代码的翻译部分,不包括任何问题的回答。如果您需要进一步的帮助,请随时提出。

英文:
  1. Add a field for the Login button, the field will be custom type, lets name it loginbtn:

          &lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\&lt;Your plugin group&gt;\&lt;Your plugin name&gt;\Field&quot;&gt;
              &lt;field
                     name=&quot;email&quot;
                     type=&quot;text&quot;
                     filter=&quot;raw&quot;
                     default=&quot;&quot;
                     label=&quot;PLG_EDITORS-XTD_XXX_FIELD_EMAIL&quot;
                     description=&quot;Enter your XXX Email&quot;
                     size=&quot;50&quot;/&gt;
             &lt;field
                     name=&quot;password&quot;
                     type=&quot;password&quot;
                     label=&quot;PLG_EDITORS-XTD_XXX_FIELD_LOGINBTN&quot;
                     description=&quot;Login&quot;/&gt;
         &lt;/fieldset&gt;
    
  2. Create a file, Loginbtn.php in plugins/< Your plugin group >/< Your plugin name >/src/Field

Loginbtn.php code:

&lt;?php
defined(&#39;JPATH_PLATFORM&#39;) or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;

class JFormFieldLoginbtn extends FormField
{
	protected $type = &#39;loginbtn&#39;;

	protected function getInput()
    {
        $html = &#39;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; class=&quot;your btn class&quot; /&gt;&#39;;

		return $html;
	}

	public function getLabel() {
		return &#39;&lt;span style=&quot;text-decoration: underline;&quot;&gt;&#39; . parent::getLabel() . &#39;&lt;/span&gt;&#39;;
	}
}
  1. Add a folder for Field in plugin's xml <files>
    < folder >field< /folder >

huangapple
  • 本文由 发表于 2023年6月18日 18:29:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定