I created a plugin to add custom fields to the joomla com_content core. I add the fields to the backend and frontend. Now the new tab is shown on every post but i want to show the tab and the fields just for one specific category (id=43).
This is how i add the new form to the backend and frontend:
<?php
// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentComputerverzeichnis extends JPlugin {
function onContentPrepareForm($form, $data) {
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option) {
case 'com_content':
if ($app->isAdmin()) {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('content', false);
}
case 'com_content':
if ($app->isSite()) {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('content', false);
}
return true;
}
return true;
}
}
?>
And this is my form:
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="attribs" >
<fieldset name="custom" label="Lizenzinformationen">
<field name="typ" type="list" label="Typ">
<option value="-">Wähle einen Typ aus!</option>
<option value="1">Mac</option>
<option value="2">PC</option>
<option value="3">Server</option>
</field>
<field
name="arbeitsplatz"
type="sql"
label="Arbeitsplatz"
query="SELECT id, name FROM #__users"
key_field="id"
value_field="name"
header="Wähle einen Arbeitsplatz aus"
showon="typ:1[OR]typ:2"
>
</field>
<field name="computerversion"
type="text"
label="Computerversion"
showon="typ:1[OR]typ:2[OR]typ:3"
/>
<field name="notizen" type="editor" label="Notizen" description="" width="300" filter="safehtml" showon="typ:1[OR]typ:2[OR]typ:3" />
</fieldset>
</fields>
</form>