I'm trying to make my own field type and it works fine so far, but the values are not saved to the DB, where do I do that? I know there is a similar question but I'm not content with the answer.
#__items
#__tags
#__item_tags
I query just the tags to get the options and then the intersection table to get the selected ones, the item id is known already. My class inherits from JFormFieldList to get the getInput functionality. I use this field inside a form xml to define it for the view.
<?php
defined('_JEXEC') or die;
JFormHelper::loadFieldClass('list');
class JFormFieldMyTag extends JFormFieldList
{
protected $type = 'MyTags';
protected function getOptions()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('all tags')->from('tags');
$db->setQuery($query);
$rows = $db->loadObjectList();
$this->value = $this->getSelected(); // The input function takes this as an array of the selected values
return $rows;
}
protected function getSelected()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query ->select('only the selected ones')->from('intersection')->where('id' = $this->getAttribute('id');
$db->setQuery($query);
$rows = $db->loadObjectList();
return $rows;
}
}
What I need is a way to remove and add entries to the intersection table, joomla seems not to do it automatically and I cant find anything in the docs.