简体   繁体   English

未为 Joomla 类别自定义组件保存标签

[英]Tags not saving for Joomla category custom component

I am developing a Joomla component and using the categories from the joomla Core.我正在开发 Joomla 组件并使用 joomla Core 中的类别。 The categories are saving properly in the Joomla Administration, but I can't add tags to this categories.. Am I doing something wrong?类别在 Joomla 管理中正确保存,但我无法向此类别添加标签..我做错了什么吗? Or do I need specific code to add tags to the categories for my component?或者我是否需要特定的代码来为我的组件的类别添加标签?

You need to add an entry in the content type table if you want to add tags support in the category.如果要在类别中添加标签支持,则需要在内容类型表中添加一个条目。 More Detail更多细节

Below is the example code that you can check for refrence to add an entry into content type table.下面是示例代码,您可以检查参考以将条目添加到内容类型表中。 Change com_example to your extension.com_example更改为您的扩展名。

<?php
/** @var JTableContentType $table */
$table  = JTable::getInstance('contenttype');

if ($table)
{
    $table->load(array('type_alias' => 'com_example.category'));

    if (!$table->type_id)
    {
        $data   = array(
            'type_title'        => 'Example Category',
            'type_alias'        => 'com_example.category',
            'table'             => '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},'
            . '"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}',
            'rules'             => '',
            'field_mappings'    => '
            {"common":{
            "core_content_item_id":"id",
            "core_title":"title",
            "core_state":"published",
            "core_alias":"alias",
            "core_created_time":"created_time",
            "core_modified_time":"modified_time",
            "core_body":"description",
            "core_hits":"hits",
            "core_publish_up":"null",
            "core_publish_down":"null",
            "core_access":"access",
            "core_params":"params", "core_featured":"null",
            "core_metadata":"metadata", "core_language":"language",
            "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey",
            "core_metadesc":"metadesc", "core_catid":"parent_id",
            "core_xreference":"null", "asset_id":"asset_id"},
            "special": {
            "parent_id":"parent_id",
            "lft":"lft",
            "rgt":"rgt",
            "level":"level",
            "path":"path",
            "extension":"extension",
            "note":"note"
            }
            }',
            'content_history_options' => '{"formFile":"administrator\/components\/com_categories\/models\/forms\/category.xml",
            "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"],

            "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],

            "convertToInt":["publish_up", "publish_down"],
"displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},
            {"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},
            {"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},
            {"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}',
        );

        $table->bind($data);

        if ($table->check())
        {
            $table->store();
        }
    }
}

For anyone facing the same issue I solved it after going through lot of pain.对于任何面临同样问题的人,我在经历了很多痛苦之后解决了它。 There is no documentation on this if you are using Joomla categories in your component.如果您在组件中使用 Joomla 类别,则没有关于此的文档。 @irfan was correct but to make it more easy I feel you can just add a row to the #__content_types during installation itself. @irfan 是正确的,但为了让它更容易,我觉得你可以在安装过程中向#__content_types添加一行。 What I did was I just searched com_newsfeed row in joomla database.我所做的只是在 joomla 数据库中搜索了com_newsfeed行。 I came across a newsfeed categories inside #__content_type .我在#__content_type遇到了一个新闻源类别。 I replaced the type_title column to my title and type_alias column to my_extension.category .我将 type_title 列替换为我的 title 并将 type_alias 列替换为my_extension.category And I was able to save the tags.我能够保存标签。 Also router column names to be changed to your router.还要将路由器列名称更改为您的路由器。 Whole SQL code which you need to put inside your sql file is您需要放入 sql 文件的整个 SQL 代码是

INSERT INTO `#__content_types` (`type_title`, `type_alias`, `table`, `rules`, `field_mappings`, `router`, `content_history_options`) VALUES

('Your Category', 'com_yourcomponent.category', '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}', '', '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}', 'YourComponentHelperRoute::getCategoryRoute', '{"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml", "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"], "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],"convertToInt":["publish_up", "publish_down"], "displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}')

Note : remember to change the component name in the code.注意:记得在代码中更改组件名称。 I have given an example code.我给出了一个示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM