With the help of this and this I made a plugin to add a custom fields to the article component. It works fine but I would like to make these custom fields mandatory and only for a specific article category.
The plugin is called "acf"
acf.php :
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentAcf extends JPlugin {
protected $autoloadLanguage = true;
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);
}
return true;
}
return true;
}
}
?>
acf.xml :
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.4" type="plugin" group="content" method="upgrade">
<name>plg_content_acf</name>
<author></author>
<creationDate></creationDate>
<copyright></copyright>
<license></license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>1.0.0</version>
<description>This is the description of the plugin</description>
<files>
<filename plugin="acf">acf.php</filename>
<filename>index.html</filename>
<folder>forms</folder>
</files>
<languages>
<language tag="en-GB">en-GB.plg_content_acf.ini</language>
<language tag="en-GB">en-GB.plg_content_acf.sys.ini</language>
</languages>
</extension>
forms/content.php:
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="attribs" >
<fieldset name="acf" >
<field
type="filelist"
name="path"
label="Document"
directory="images/documents"
filter="\.pdf$"
hide_default="true"
validate="options"
/>
<field
name="anchor"
type="text"
label="Anchor"
description="Description here"
class="required"
/>
</fieldset>
</fields>
</form>