如何在 Joomla 中修改类别表单?
我正在努力创建一个小插件来修改 Joomla 中的类别表单(在添加/编辑类别视图上)。
我能够使用Joomla 网站上的教程来修改用户个人资料、文章和菜单上的表单;但是,类别似乎无法正常工作。
这是我正在使用的代码:
defined('JPATH_BASE') or die;
class plgContentCategoryType extends JPlugin {
function onContentPrepareForm($form, $data) {
// Load plugin language
$lang = JFactory::getLanguage();
$lang->load('plg_content_categorytype', JPATH_ADMINISTRATOR);
if (!($form instanceof JForm)) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_categories.category'))) {
return true;
}
if ($form->getName()=='com_categories.category') {
// Add the fields to the form.
JForm::addFormPath(dirname(__FILE__).'/forms');
$form->loadFile('categorytype', false);
}
}
}
这就是 XML 表单的样子:
<form>
<fields name="params">
<fieldset name="categorytype" label="PLG_CONTENT_CATEOGRYTYPE_FIELDSET_LABEL">
<field name="category_type" type="list" label="PLG_CONTENT_CATEGORYTYPE_LABEL" description="PLG_CONTENT_CATEGORYTYPE_DESC">
<option value=""></option>
<option value="features">PLG_CONTENT_CATEGORYTYPE_FEATURES</option>
<option value="columns">PLG_CONTENT_CATEGORYTYPE_COLUMNS</option>
<option value="spotlights">PLG_CONTENT_CATEGORYTYPE_SPOTLIGHTS</option>
<option value="slices">PLG_CONTENT_CATEGORYTYPE_SLICES</option>
<option value="news">PLG_CONTENT_CATEGORYTYPE_NEWS</option>
</field>
</fieldset>
</fields>
</form>
如果对我做错的事情有任何帮助,我们将不胜感激!就像我说的,它适用于任何其他类型的内容,例如,要使其适用于菜单,只需更改代码中的“名称”。
谢谢!
I'm working on creating a small plugin to modify the Category Forms (on the add/edit category view) in Joomla.
I was able to use the tutorial on Joomla's site to modify the forms on User Profiles, Articles, and Menus; however, Categories do not seem to work properly.
This the code that I am using:
defined('JPATH_BASE') or die;
class plgContentCategoryType extends JPlugin {
function onContentPrepareForm($form, $data) {
// Load plugin language
$lang = JFactory::getLanguage();
$lang->load('plg_content_categorytype', JPATH_ADMINISTRATOR);
if (!($form instanceof JForm)) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_categories.category'))) {
return true;
}
if ($form->getName()=='com_categories.category') {
// Add the fields to the form.
JForm::addFormPath(dirname(__FILE__).'/forms');
$form->loadFile('categorytype', false);
}
}
}
and this is what the form XML looks like:
<form>
<fields name="params">
<fieldset name="categorytype" label="PLG_CONTENT_CATEOGRYTYPE_FIELDSET_LABEL">
<field name="category_type" type="list" label="PLG_CONTENT_CATEGORYTYPE_LABEL" description="PLG_CONTENT_CATEGORYTYPE_DESC">
<option value=""></option>
<option value="features">PLG_CONTENT_CATEGORYTYPE_FEATURES</option>
<option value="columns">PLG_CONTENT_CATEGORYTYPE_COLUMNS</option>
<option value="spotlights">PLG_CONTENT_CATEGORYTYPE_SPOTLIGHTS</option>
<option value="slices">PLG_CONTENT_CATEGORYTYPE_SLICES</option>
<option value="news">PLG_CONTENT_CATEGORYTYPE_NEWS</option>
</field>
</fieldset>
</fields>
</form>
Any help in what I'm doing wrong would be greatly appreciated! Like I said, it will work on any other type of content, for instance, for it to work on menu's, just have to change the 'name' in the code.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,Joomla 2.5 中存在一个 Bug,导致表单字段未呈现在“编辑类别”页面上。我们最近在我们的网站上添加了一个博客,该博客对此进行了修复。您可以在这里阅读它 http://techjoomla.com/joomla-development/adding-custom-fields-to-joomla-categories-in-joomla-25.html
已为此向 Joomla 提交了一个补丁
Actually there is a Bug in Joomla 2.5 due to which the form fields are not rendered on the Edit Category page. We recently Added a blog on our site which has a fix for this.. You can read it here http://techjoomla.com/joomla-development/adding-custom-fields-to-joomla-categories-in-joomla-25.html
A patch has been submitted for this to Joomla
我建立了一个测试平台并创建了一个类似的插件。
我回显了 $form->getName() 的值,结果显示为“com_categories.categorycom_content”。
由此得出的最佳猜测是,由于类别可以在多个上下文中使用,因此该组件会附加在末尾。
因此,在包含“com_categories.category”的两行中,替换为“com_categories.categorycom_content”即可。
I set up a testbed and created a similar plugin.
I echoed out the value of $form->getName() and it came out as 'com_categories.categorycom_content'
Best guess from this is that as categories can be used in multiple contexts that the component is appended on the end.
So, in the two lines where you have 'com_categories.category', replace with 'com_categories.categorycom_content' and it works.