2

I would like to use the tagging-function of Joomla! in my component.

To get that working I created a postflight which is being executed after installation:

function postflight($type, $parent)
{
    $table = JTable::getInstance('Contenttype', 'JTable');
    if(!$table->load(array('type_alias' => 'com_bestia.item')))
    {
        $common = new stdClass;
        $common->core_content_item_id = 'id';
        $common->core_title = 'title';
        $common->core_state = 'state';
        $common->core_alias = 'alias';
        $common->core_created_time = 'created';
        $common->core_modified_time = 'modified';
        $common->core_body = 'description';
        $common->core_hits = 'hits';
        $common->core_publish_up = 'publish_up';
        $common->core_publish_down = 'publish_down';
        $common->core_access = 'access';
        $common->core_params = 'params';
        $common->core_featured = 'featured';
        $common->core_metadata   = 'metadata';
        $common->core_language   = 'language';
        $common->core_images = 'images';
        $common->core_urls = 'urls';
        $common->core_version = 'version';
        $common->core_ordering   = 'ordering';
        $common->core_metakey = 'metakey';
        $common->core_metadesc = 'metadesc';
        $common->core_catid = 'catid';
        $common->core_xreference = 'xreference';
        $common->asset_id = null;
        $field_mappings = new stdClass;
        $field_mappings->common[] = $common;
        $field_mappings->special = array();
        $special = new stdClass; $special->dbtable = '#__bestia_items'; $special->key = 'id'; $special->type = 'Item'; $special->prefix = 'BestiaTable'; $special->config = 'array()';
        $table_object = new stdClass;
        $table_object->special = $special;
        $contenttype['type_title'] = 'Item';
        $contenttype['type_alias'] = 'com_bestia.item';
        $contenttype['table'] = json_encode($table_object);
        $contenttype['rules'] = '';
        $contenttype['router'] = 'BestiaHelperRoute::getBestiaRoute';
        $contenttype['field_mappings'] = json_encode($field_mappings);
        $table->save($contenttype);
    }
}

Also I modified my table:

public function __construct(&$db)
{
    parent::__construct('#__bestia_items', 'id', $db);
    JTableObserverTags::createObserver($this, array('typeAlias' => 'com_bestia.item'));
}

And my model:

/**
 * getItem function.
 * 
 * @access public
 * @param mixed $pk (default: null)
 * @return void
 */
public function getItem($pk = null)
{
    if ($item = parent::getItem($pk)) 
    {
        // Convert the metadata field to an array.
        $registry                   =       new JRegistry;

        if(isset($item->metadata))
        {
            $registry->loadString($item->metadata);
            $item->metadata         =       $registry->toArray();
        }

        if (!empty($item->id))
        {
            $item->tags             =       new JHelperTags;
            $item->tags->getTagIds($item->id, 'com_bestia.item');
            $item->metadata['tags'] =       $item->tags;
        }           
    }

    return $item;
}

Now I modified my form.xml:

    <field  name        =       "tags" 
            type        =       "tag"
            label       =       "JTAG" 
            description =       "JTAG_DESC"
            class       =       "inputbox span12 small" 
            multiple    =       "true"
            filter      =       "safehtml" />

Now if I want to save my item with some tags, I'm getting this error:

Speichern fehlgeschlagen! Fehler: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'newTags' in 'field list'

What can I do here?

1 Answer 1

2

Got the error:

Filter does not work here. Removing

filter      =       "safehtml"

solves the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.