1

I am developing a component extension to create different forms for insurance.

When I create a form in backend and save it by clicking the Save or Save & Close button, I am going to create a table in database. The suitable event could be onExtensionAfterSave event in a plugin belonging to group Extension.

Now the question is this: I saw two different samples of this method:

  1. onExtensionAfterSave($data, $isNew)
  2. onExtensionAfterSave($context, &$table, $isNew)

Which is the right one?

Also to obtain paremeters, Can I use JPlugin::params (params to my extension in the backend that are already created and saved to database)?

  • 1
    Is the component your component? If so why would you listen for your own events in a plugin rather than creating the tables within your component's controller? – jamesgarrett Dec 11 '17 at 7:38
  • The component is for creating forms with different fields and input, a form might be only one page or another one multi-pages, after creation of each form, a separate table will be created according to the fields of created form. So I need to learn about the created forms field and input after it is created, the forms are quite different from each other and those forms will be used in site part, the created tables save the data to those forms after user input in the site part, created forms are not constant, they are dynamic, Events are necessary to learn about forms. – Kian William Nowrouzian Dec 16 '17 at 4:37
0

onExtensionAfterSave isn't a common Joomla event - It only fires when the component/module/plugin configuration is saved. Example, editing Joomla global configuration, editing the options of a component, editing the options of a module, editing the options of a plugin. I've been writing extensions for years and I've never used that event - because it just isn't useful.

I think you picked the wrong event.

It won't fire on creating a form within your component unless you've written your component to fire that event. And if you did, I'd suggest picking a different event - like onContentAfterSave, which is designed to do what you're asking for.

If it's your own component (that you're writing) - you might consider creating your own set of events to monitor. Joomla is designed to do this. I did this in one of my own components to monitor a dozen different events related to CBT training.

When you're working with your own events, you can define whatever you want to send to the plugin. In my events, most take only one variable - an ID. The plugin retrieves the data based on that ID and does whatever it's designed to do.

Step 1, choose a unique type to name your plugin folder: /plugins/YOURNEWTYPE/

Step 2, make a test plugin to define and test your events.

Step 3, load the plugins and create a dispatcher in your component to fire your custom event whenever you need it.

It's super easy.

  • I considered custom event as an alternative as long as I can use joomla events to get rid of dispatching of events separately in component, eg. plugin under group of content has no need to be dispatched separately in custom component. When the user saves component in back end, I got to create a table based on that form in which its inputs are not the same, the created form is dynamic , so both onExtensionAfterSave and onContentAfterSave are able to handle it, I will also develop a custom event plugin as you advised and I shall test all of them and may I ask what CBT training is? – Kian William Nowrouzian Dec 16 '17 at 5:06
  • About the example I said above in regard with joomla events plugin, I meant a plugin under group of search, I mentioned content mistakenly in the second line above. – Kian William Nowrouzian Dec 16 '17 at 5:29
  • I tried a test plugin, onExtensionAfterSave event did not work without being dispatched in controller, After I dispatched the event, it did and I have the id to be able to access the database to create my form. I used to create a plugin under search group, it worked without being dispatched, I expected the same here. – Kian William Nowrouzian Dec 16 '17 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.