Knows someone a good guide on how to implement the TAGS feature into a Custom J4/5 Component? I have this information from Astrid's Book on how to develop J4 Components but it looks not fully correct to me (uses old syntax at least for the table).
What I've tried (multiple times)
script.php
...
private function saveContentTypes()
{
// $app = Factory::getApplication();
// $table = $app->bootComponent('com_tags')
// ->getMVCFactory()
// ->createTable('Contenttype');
$table = Table::getInstance('Contenttype', 'JTable'); // << Old way should be replaced by above or not?
$table->load(['type_alias' => 'com_component.question']); // will fail on new way (commented above)
$tableStringContentObj = new stdClass();
$tableStringContentObj->special = new stdClass();
$tableStringContentObj->special->dbtable = '#__com_component_questions';
$tableStringContentObj->special->key = 'id';
$tableStringContentObj->special->type = '[COMPONENTNAME]QuestionTable';
$tableStringContentObj->special->prefix = 'NXD\\Component\\[COMPONENTNAME]\\Administrator\\Table\\';
$tableStringContentObj->special->config = 'array()';
$tableStringContentObj->common = new stdClass();
$tableStringContentObj->common->dbtable = '#__ucm_content';
$tableStringContentObj->common->key = 'ucm_id';
$tableStringContentObj->common->type = 'Corecontent';
$tableStringContentObj->common->prefix = 'Joomla\\CMS\\Table'; // was JTable
$tableStringContentObj->common->config = 'array()';
$tableString = json_encode($tableStringContentObj);
$fieldMappingObj = new stdClass();
$fieldMappingObj->common = new stdClass();
$fieldMappingObj->common->core_content_item_id = 'id';
$fieldMappingObj->common->core_title = 'title';
$fieldMappingObj->common->core_state = 'published';
$fieldMappingObj->common->core_alias = 'alias';
$fieldMappingObj->common->core_publish_up = 'publish_up';
$fieldMappingObj->common->core_publish_down = 'publish_down';
$fieldMappingObj->common->core_access = 'access';
$fieldMappingObj->common->core_params = 'params';
$fieldMappingObj->common->core_featured = 'featured';
$fieldMappingObj->common->core_language = 'language';
$fieldMappingObj->common->core_ordering = 'ordering';
$fieldMappingObj->common->core_catid = 'catid';
$fieldMappingObj->common->asset_id = 'null';
$fieldMappingObj->special = new stdClass();
$fieldMapping = json_encode($fieldMappingObj);
$contentType = [];
$contentType['type_id'] = ($table->type_id) ?: 0;
$contentType['type_title'] = 'Questions';
$contentType['type_alias'] = 'com_component.question';
$contentType['table'] = $tableString;
$contentType['rules'] = '';
$contentType['router'] = 'RouteHelper::getQuestionRoute'; // not yet defined but shouldn't be an issue?
$contentType['field_mappings'] = $fieldMapping;
$contentType['content_history_options'] = '';
$table->save($contentType);
return;
}
...
The row gets added on install and looks good to me (a lot more information then the others but type_alias looks fine) - Note: I'm adding the information by using an object (xyObj) because when typing it as string it writes the format (newlines) also into the table.
In the XML Form for Edit Question
<field name="tag" type="tag" custom="true" ... />
The field gets rendered and shows me all Tags of COM_CONTENT.Article that has been setted up already (that shouldn't be the case right?). When trying to add a new tag (type and enter) it does not store the new tag and the field is empty after save.
For me it feels like i'm trying to use outdated information on how to implement the Tags functionality...