Skip to content

Instantly share code, notes, and snippets.

@strsar
Created January 30, 2017 17:32
Show Gist options
  • Save strsar/c8de8ed2cb3b2936159aab5874bdbd35 to your computer and use it in GitHub Desktop.
Save strsar/c8de8ed2cb3b2936159aab5874bdbd35 to your computer and use it in GitHub Desktop.
[Joomla!] - Extend core component xml fields via System Plugin
<?php defined('_JEXEC') or die;
class plgSystemPlugin extends JPlugin {
public function __construct(&$subject, $config = array()) {
parent::__construct($subject, $config);
}
/**
* @event onContentPrepareForm
*/
function onContentPrepareForm($form, $data) {
$doc = JFactory::getDocument();
$app = JFactory::getApplication();
$option = $app->input->get('option');
$xml = $this->params->get('xml');
/**
* Additional core fields
*/
if($xml && $app->isAdmin()){
$template = $app->getTemplate();
// Cases for component types
switch($option) {
case 'com_content':
// Load current article
$article = JTable::getInstance('content');
$article->load(JRequest::getInt('id'));
// Get article params
$_params = new JRegistry();
$_params->loadString($article->attribs);
// Load form based on layout
JForm::addFormPath(__DIR__.'/forms/com_content');
// If layout frontpage
if($_params->get('article_layout') == 'website:frontpage') {
$form->loadFile('frontpage', false);
}else{
$form->removeField('image_fulltext', 'images');
$form->removeField('image_fulltext_alt', 'images');
$form->removeField('float_fulltext', 'images');
$form->removeField('image_fulltext_caption', 'images');
$form->removeField('image_intro_caption', 'images');
$form->loadFile('extend', true);
}
break;
case 'com_categories':
JForm::addFormPath(__DIR__.'/forms/com_categories');
$form->loadFile('extend', false);
break;
case 'com_modules':
JForm::addFormPath(__DIR__.'/forms/com_modules');
$form->loadFile('extend', false);
break;
case 'com_menus':
JForm::addFormPath(__DIR__.'/forms/com_menus');
$form->removeField('page_heading', 'params');
$form->removeField('show_page_heading', 'params');
$form->loadFile('item_component', true);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment