Creating tags programmatically with com_content

184 views
Skip to first unread message

Matt Thomas

unread,
Jul 12, 2013, 4:48:21 PM7/12/13
to joomla-...@googlegroups.com
Hi folks,

I've been wrapping my head around how core tags work, and trying to implement automatic tag creation in com_overload for testing purposes. 

Since com_overload uses core com_content, my understanding was that adding the tags array to metadata would do it, but it seems that this only adds the json encoded tags to the metadata field and gets the article into #__ucm_content. No tags are created or associated with the content item.

On a side note, this works fine in Joomla 3.1.1, but triggers a fatal error in the latest from Github:

Fatal error: Cannot use object of type JHelperTags as array in /administrator/components/com_categories/models/category.php on line 430

Do I somehow need to call JHelperTags::preStoreProcess and JHelperTags::postStoreProcess. Is that correct?

I would have thought that doing something like the following in the article save method would work:

$table = JTable::getInstance($type = 'Content', $prefix = 'JTable', $config = array());
JHelperTags::preStoreProcess($table);
JHelperTags::postStoreProcess($table);

Any insight is greatly appreciated!

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain

Richard McDaniel

unread,
Jul 12, 2013, 4:54:13 PM7/12/13
to joomla-...@googlegroups.com
Thank you for making this tool. It seems that Joomla is/was tested with only small amounts of data and therefore code that scales poorly isn't noticed right away.

Mark Dexter

unread,
Jul 12, 2013, 4:54:52 PM7/12/13
to joomla-...@googlegroups.com
@Matt: If you look at weblinks, for example, you'll see this code in the store() method of WeblinksTableWeblink:

$this->tagsHelper->preStoreProcess($this);
$result = parent::store($updateNulls);

$this->newTags = isset($this->newTags) ? $this->newTags : array();
return $result && $this->tagsHelper->postStoreProcess($this, $this->newTags);

Now, I hasten to add that there is a proposed patch to improve this and move this processing to the parent class and add a property to that class to indicate whether or not you are using tags for this table. But at this moment, this is how it works.


Hope that helps. Mark

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send an email to joomla-...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matt Thomas

unread,
Jul 12, 2013, 5:00:10 PM7/12/13
to joomla-...@googlegroups.com
Richard,

The thanks goes to Nicholas from Akeeba Backup for making it. I'm just trying to add a wee bit to it. I do agree that we need large scale data testing.

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



--

Matt Thomas

unread,
Jul 12, 2013, 5:22:11 PM7/12/13
to joomla-...@googlegroups.com
Mark,

Thanks. I was in fact looking at both Weblinks and that article. Where this is a bit of a unique case is that com_overload is just automating the creation of articles with com_content. I would imagine that what I'm trying to do should/could be possible with a plugin (i.e. automatic tags creation) as well.

That said, I don't see a store() method in com_content, or even a class that extends JTable other than ContentTableFeatured. I'm not really sure where this could be done.

Any ideas?

 

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



Mark Dexter

unread,
Jul 12, 2013, 5:25:15 PM7/12/13
to joomla-...@googlegroups.com
JTableContent has a store() method with the same code as used in weblinks. https://github.com/joomla/joomla-cms/blob/master/libraries/legacy/table/content.php#l269

It's in the libraries/legacy folder.

Mark

Matt Thomas

unread,
Jul 12, 2013, 5:32:58 PM7/12/13
to joomla-...@googlegroups.com
Ah, interesting. I never thought to look there as weblinks has a table directory.  One step closer it seems.

Thanks!

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



Mark Dexter

unread,
Jul 12, 2013, 5:37:49 PM7/12/13
to joomla-...@googlegroups.com
It's confusing. I'm not sure why content is in the libraries folder. Perhaps historical accident. At this point, we have some tables in the legacy folder, the cms folder, and the joomla folder. I think Michael is working on trying to organize some of these folders. Might be we could merge the cms and legacy folders at least.

If you use an IDE, you can get a nice list of all the classes in the project and find the files by class name.

Mark
Reply all
Reply to author
Forward
0 new messages