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

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

Adding a button type to joomla plugin xml config

问题

  1. 我已创建一个 Joomla 插件,并在 XML 文件中添加了以下代码中的 2 个字段。我想要添加一个按钮类型。由于我在 Joomla 中找不到按钮类型,该如何实现?我正在使用 Joomla v4
  2. 请参考下面的截图以更清楚地了解我正在寻找的内容。
  3. [![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.

  1. <fieldset name="basic">
  2. <field
  3. name="email"
  4. type="text"
  5. filter="raw"
  6. default=""
  7. label="PLG_EDITORS-XTD_XXX_FIELD_EMAIL"
  8. description="Enter your XXX Email"
  9. size="50"/>
  10. <field
  11. name="password"
  12. type="password"
  13. label="PLG_EDITORS-XTD_XXX_FIELD_PASSWORD"
  14. description="Enter the password"
  15. maxlength="25"
  16. size="30"/>
  17. </fieldset>

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

答案1

得分: 1

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

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

  1. <fieldset name="basic" addfieldprefix="Joomla\Plugin\System\Stats\Field">
  2. <field
  3. name="data"
  4. type="data"
  5. label=""
  6. />
  7. </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:

  1. &lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\System\Stats\Field&quot;&gt;
  2. &lt;field
  3. name=&quot;data&quot;
  4. type=&quot;data&quot;
  5. label=&quot;&quot;
  6. /&gt;
  7. &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:
  1. &lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\&lt;Your plugin group&gt;\&lt;Your plugin name&gt;\Field&quot;&gt;
  2. &lt;field
  3. name=&quot;email&quot;
  4. type=&quot;text&quot;
  5. filter=&quot;raw&quot;
  6. default=&quot;&quot;
  7. label=&quot;PLG_EDITORS-XTD_XXX_FIELD_EMAIL&quot;
  8. description=&quot;输入您的XXX电子邮件&quot;
  9. size=&quot;50&quot;/&gt;
  10. &lt;field
  11. name=&quot;password&quot;
  12. type=&quot;password&quot;
  13. label=&quot;PLG_EDITORS-XTD_XXX_FIELD_LOGINBTN&quot;
  14. description=&quot;登录&quot;/&gt;
  15. &lt;/fieldset&gt;
  1. 在 plugins/<Your plugin group>/<Your plugin name>/src/Field 中创建一个名为 Loginbtn.php 的文件。

Loginbtn.php 代码:

  1. &lt;?php
  2. defined('JPATH_PLATFORM') or die;
  3. use Joomla\CMS\Factory;
  4. use Joomla\CMS\Form\FormField;
  5. class JFormFieldLoginbtn extends FormField
  6. {
  7. protected $type = 'loginbtn';
  8. protected function getInput()
  9. {
  10. $html = '&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; class=&quot;your btn class&quot; /&gt;';
  11. return $html;
  12. }
  13. public function getLabel() {
  14. return '&lt;span style=&quot;text-decoration: underline;&quot;&gt;' . parent::getLabel() . '&lt;/span&gt;';
  15. }
  16. }
  1. 在插件的 XML 文件中添加一个 Field 文件夹:
  1. <files>
  2. <folder>field</folder>
  3. </files>

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

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

    1. &lt;fieldset name=&quot;basic&quot; addfieldprefix=&quot;Joomla\Plugin\&lt;Your plugin group&gt;\&lt;Your plugin name&gt;\Field&quot;&gt;
    2. &lt;field
    3. name=&quot;email&quot;
    4. type=&quot;text&quot;
    5. filter=&quot;raw&quot;
    6. default=&quot;&quot;
    7. label=&quot;PLG_EDITORS-XTD_XXX_FIELD_EMAIL&quot;
    8. description=&quot;Enter your XXX Email&quot;
    9. size=&quot;50&quot;/&gt;
    10. &lt;field
    11. name=&quot;password&quot;
    12. type=&quot;password&quot;
    13. label=&quot;PLG_EDITORS-XTD_XXX_FIELD_LOGINBTN&quot;
    14. description=&quot;Login&quot;/&gt;
    15. &lt;/fieldset&gt;
  2. Create a file, Loginbtn.php in plugins/< Your plugin group >/< Your plugin name >/src/Field

Loginbtn.php code:

  1. &lt;?php
  2. defined(&#39;JPATH_PLATFORM&#39;) or die;
  3. use Joomla\CMS\Factory;
  4. use Joomla\CMS\Form\FormField;
  5. class JFormFieldLoginbtn extends FormField
  6. {
  7. protected $type = &#39;loginbtn&#39;;
  8. protected function getInput()
  9. {
  10. $html = &#39;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; class=&quot;your btn class&quot; /&gt;&#39;;
  11. return $html;
  12. }
  13. public function getLabel() {
  14. return &#39;&lt;span style=&quot;text-decoration: underline;&quot;&gt;&#39; . parent::getLabel() . &#39;&lt;/span&gt;&#39;;
  15. }
  16. }
  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:

确定