Learning Joomla! 3 Extension Development(Third Edition)
上QQ阅读APP看书,第一时间看更新

Zip it up and install your plugin

Now that you have created all the code for the Click to Call plugin, you need to test it in your Joomla! site to see if it works correctly. We will start out with a way that you might get this running on your development site, then, we will zip it all up into an installable file that you could distribute to other people.

Before we do that, you will need to add some phone numbers in your articles that we are going to turn into Click to Call links, so that we know the plugin works. Add some phone numbers in 1234-5678 or 1234 5768 format.

In your Joomla! 3 development website, find the /plugins/content/ folder and create a new folder clicktocall.

Copy into this folder the files you have created, clicktocall.xml, clicktocall.php, and index.html.

Now in your Joomla! Administrator, navigate to Extensions | Extension Manager, and select the Discover view at the left side. Click on the Discover button and you should see the Content - Click To Call plugin appearing. Select it and click on the Install button.

Now you will need to enable this plugin through Extensions | Plug-in Manager. Just click on the red cross in the status column and it should turn into a green tick.

You will also notice that your plugin is listed by navigating to Extensions | Extension Manager | Manage. You can also see the information such as Date, Author, and Version that you set in your installation XML file are shown here.

Note

Plugins are executed in the order in which they appear when you click on the ordering column. When you have more than one plugin triggering for an event, the results of one plugin can affect the next, so keep that in mind.

Take a look at your frontend and you should now see all the phone numbers you inserted earlier have turned into Click to Call links.

If you view this on a mobile device, you will see how the Click to Call link works.

Now that we know the plugin works, you will want to be able to package this up into a file that you can give to other people to install on their Joomla! websites. Well, the good news is that you have already done all the hard work, all you need to do is chuck these files you created into the same folder and zip it up. You can use whatever zip program you like, for example 7-zip. Joomla! supports both .zip and .tar.gz formats, so you can choose which one to use. Generally the .tar.gz files are smaller; however some web hosts don't support .tar.gz files, in which case you could send those users a .zip file instead. The .zip file format is most commonly used by extension developers.

You should call your plugin file plg_content_clicktocall_v1.0.0.zip, so just by looking at the filename, someone could tell that this is a content plugin called Click to Call and it's Version 1.0.0. This ZIP file can now be installed via the normal extension manager installer.

When testing your extensions in Joomla!, you should make sure that you set error_reporting to maximum in your global configuration. When error reporting is set lower such as the default setting, a lot of warning messages, notices, and error messages are hidden from the browser. It is best to see these messages so you can address the problem and improve your code before your users start complaining.

You may also need to adjust the error_reporting setting in your php.ini file on your development site.

error_reporting = E_ALL