J4 Issue ?
avatar mbabker
mbabker
16 Jun 2016
  1. 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.

  2. The onContentPrepareData event is not implemented at all.

avatar mbabker mbabker - open - 16 Jun 2016
avatar brianteeman brianteeman - change - 17 Jun 2016
Category Plugins
avatar brianteeman brianteeman - change - 17 Jun 2016
Labels Added: ?
avatar piotr-cz
piotr-cz - comment - 23 Jun 2016

True, ugly workaround is to check GET parameters

$app = JFactory::getApplication();

if ($app->input->get('component') == 'com_content') {
    // Bingo
}

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);
avatar PhilETaylor
PhilETaylor - comment - 12 Jul 2016

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 ;-)

avatar joomla-cms-bot joomla-cms-bot - change - 12 Jul 2016
The description was changed
avatar mbabker
mbabker - comment - 12 Jul 2016

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
    }
avatar joomla-cms-bot joomla-cms-bot - edited - 12 Jul 2016
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Apr 2017
Status New Needs Review
avatar mbabker
mbabker - comment - 25 May 2017

Added to the 4.0 task board. Presumably, addressing the onContentPrepareForm event issue is going to require some form of B/C break.

avatar joomla-cms-bot joomla-cms-bot - change - 25 May 2017
Title
[4.0] Form Event Issues in com_config
Form Event Issues in com_config
avatar joomla-cms-bot joomla-cms-bot - edited - 25 May 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 25 May 2017
Title
Form Event Issues in com_config
[4.0] Form Event Issues in com_config
Status Needs Review Discussion
avatar franz-wohlkoenig franz-wohlkoenig - change - 25 May 2017
Title
Form Event Issues in com_config
[4.0] Form Event Issues in com_config
avatar brianteeman brianteeman - change - 25 Mar 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar mbabker mbabker - change - 13 Sep 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-09-13 01:29:14
Closed_By mbabker
avatar mbabker mbabker - close - 13 Sep 2018

Add a Comment

Login with GitHub to post a comment