不保存Joomla类别自定义组件的标签

时间:2018-01-25 14:06:09

标签: php joomla joomla-extensions

我正在开发Joomla组件并使用joomla Core中的类别。这些类别在Joomla Administration中正确保存,但我无法在此类别中添加标签。我做错了什么?或者我是否需要特定代码才能将标签添加到我的组件的类别中?

2 个答案:

答案 0 :(得分:0)

如果要在类别中添加标记支持,则需要在内容类型表中添加条目。 More Detail

下面是您可以检查引用以将条目添加到内容类型表中的示例代码。将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();
        }
    }
}

答案 1 :(得分:0)

对于遇到相同问题的任何人,我在经历了很多痛苦之后都解决了它。如果您在组件中使用Joomla类别,则没有任何文档。 @irfan是正确的,但是要使其变得更容易,我觉得您可以在安装本身期间仅向#__content_types添加一行。我所做的只是在joomla数据库中搜索了com_newsfeed行。我在#__content_type中遇到了一个新闻源类别。我将type_title列替换为标题,并将type_alias列替换为my_extension.category。而且我能够保存标签。还要将路由器列名称更改为您的路由器。 您需要放入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"}]}')

注意:请记住在代码中更改组件名称。我给出了示例代码。