The onContentPrepareForm
event lacks a way to identify component configuration forms. The JForm
instance is instantiated with a form name of com_config.component
and neither the form nor the dispatched event include any type of context identifying the component.
The onContentPrepareData
event is not implemented at all.
Category | ⇒ | Plugins |
Labels |
Added:
?
|
yup we came upon this when implementing the new logging features for myJoomla.com - we went down the route of obtaining $app->input->get('component') as well as there was no other pretty way of doing it.
To add more misery there is also com_config.application (only used by com_config) and com_config.component ... used by all other ...er... extensions ;-)
My workaround wasn't much better but at least made use of the injected data (and actually worked a bit better off because I ended up needing to hook into plugin save events too):
/**
* Listener for the `onExtensionBeforeSave` event.
*
* @param string $context The context of the content passed to the plugin.
* @param JTable $table The record being saved.
* @param boolean $isNew If the content is just about to be created.
*
* @return void
*/
public function onExtensionBeforeSave($context, JTable $table, $isNew)
{
switch ($context)
{
case 'com_config.component':
$this->processComponent($table, $isNew);
break;
case 'com_plugins.plugin':
$this->processPlugin($table, $isNew);
break;
}
}
/**
* Handles updates for a component's configuration.
*
* @param JTable $table The record being saved.
* @param boolean $isNew If the content is just about to be created.
*
* @return void
*/
private function processComponent(JTable $table, $isNew)
{
// Only act when the com_content component config is saved
if (!($table instanceof JTableExtension) || $table->name != 'com_content')
{
return;
}
// Do stuff
}
/**
* Handles updates for a plugin's configuration.
*
* @param JTable $table The record being saved.
* @param boolean $isNew If the content is just about to be created.
*
* @return void
*/
private function processPlugin(JTable $table, $isNew)
{
// Only act when this plugin is saved
if (!($table instanceof JTableExtension) || $table->name != $this->pluginName)
{
return;
}
// Do stuff
}
Status | New | ⇒ | Needs Review |
Added to the 4.0 task board. Presumably, addressing the onContentPrepareForm
event issue is going to require some form of B/C break.
Title |
|
Title |
|
||||||
Status | Needs Review | ⇒ | Discussion |
Title |
|
Labels |
Added:
J4 Issue
|
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-09-13 01:29:14 |
Closed_By | ⇒ | mbabker |
True, ugly workaround is to check GET parameters
I think the consistent way would be to add a context argument to event dispatcher, rather to form instance.
In frontend this could be in the
ConfigModelForm::preprocessForm
:$results = $dispatcher->trigger('onContentPrepareForm', array($form, $data, $group));
So event listener interface would look like:
abstract public function onContentPrepareForm(JForm $form, $data, $context = null);