Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Documentation

Thomas Hunziker edited this page Aug 17, 2017 · 1 revision

This plugin will install testing data for various core components. Once the plugin is installed, it will show itself in the administrator "Sample Data" module and can be activated from there.

How it works

  • During pageload the "Sample Data" module will import the "sampledata" pluging group and trigger the onSampledataGetOverview event. The plugins listening to that event will return their name and some metadata for the module to display. It will show the various sample data sets as list.
  • If an entry in that list is activated, the module will fire multiple AJAX requests using com_ajax which then will trigger the onAjaxSampledataApplyStepX events in the plugin. Those are the methods actually generating the sample data content.

Methods

onSampledataGetOverview

Returns an object with the following properties

  • name - The name of the sample data set. The name isn't shown to the user.
  • title - The title of the sample data set that is shown in the module.
  • description - The description of the sample data set that is shown in the module.
  • icon - The icon class. This will be prepended by icon- and should be a valid Icomoon class.
  • steps - The amount of steps the plugin has. This tells the module how many AJAX calls it should fire.

onAjaxSampledataApplyStepX

Generates the sample data content. Either returns void or an "response" array which will be converted into a message to the user. What is done within each step is completely up the plugin. The amount of onAjaxSampledataApplyStepX methods has to match the steps defined in the onSampledataGetOverview method. In the case of this testing sample data, each step is responsible for one component:

  • Step 1 - Tags
  • Step 2 - Banners
  • Step 3 - Articles
  • Step 4 - Contacts
  • Step 5 - Newsfeed
  • Step 6 - Menus
  • Step 7 - Modules

Data

Editing

The title and description of the items are coming from language strings. The item settings (options, nesting, ...) are "hardcoded" in the plugin code. Thus changing the title and description is rather simple, just find the right language string and adjust it. Changing settings can be a bit more tricky as you need to find the correct item in the code and adjust the value there.

Adding

To add a new item to an already existing step, you first need to create the new language strings and then add the code to the respective step. Depending on the step this differs but most of the time there is an array of items somewhere which gets looped over to save it. So you can just add another item to that array. If you want to add a new step (eg support a new extension) you need to add a new onAjaxSampledataApplyStepX method together with the needed language strings and adjust the steps property in the onSampledataGetOverview method.

Plugin Interaction

While usually a sample data set is taken care by a single plugin, this doesn't need to be always the case. Since the module uses a regular plugin event, there could be multiple plugins listening to the same onAjaxSampledataApplyStepX call, meaning you could add your own plugin which will add some own data when the "Testing" Sample Data is installed. That would allow for 3rd parties to "hook" into that sample data set and install testing data for its own extension as well.