Adding some events to trigger plugins in the Rentalot component
Add event 'onRentalotSubmitEnquiry' in controller Enquiry at the end of the ajax_submit to add tasks when a request is sent.
* Event after submiting a Enquiry request form
*
* @param string $context define the context of the event execution.
* @param object $bookingModel object contains input form data.
* @param array $emailInfoClient info from the sent mail.
* @param boolean $isMailSent the mail has been sent (1) or not (0).
*/
public function onRentalotSubmitEnquiry($context, $bookingModel, $emailInfoClient, $isMailSent)
Add event 'onRentalotSubmitBooking' in controller Booking at the end of the ajax_submit to add tasks when a booking is sent.
* Event after submiting a booking form
*
* @param string $context define the context of the event execution.
* @param array $postData the content of the form.
* @param object $bookingModel object contains input form data.
* @param boolean $check the mail has been sent (1) or not (0).
*/
public function onRentalotSubmitBooking($context, $postData, $bookingModel, $check)
To make it possible to trigger these events, we need to connect Rentalot with these events. the '$app->triggerEvent' is the solution in Joomla to request the associated plugins. It contains 2 params :
- the name of the events to call
- an array containing params to send to the plugin : context, BookingModel ...
the controllers/enquirycontroller.php has been modified with the following lines of code :
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
...
$isSentOk = LARP_email::sendEmail($email_info_client, $message);
if($isSentOk) ...
...
$email_info_client = array();
$email_info_client['email_to'] = $post_data->email; // Client
$email_info_client['reply_to'] = $config_model->getData('email_to'); // Admin
...
PluginHelper::importPlugin('rentalot');
// permits to do something after sending the enquiry mail to visitor
$app = Factory::getApplication();
$result = (array) $app->triggerEvent('onRentalotSubmitEnquiry',
array('com_rentalot.enquiry', $booking_model, $email_info_client, $isSentOk)
);
See history updates on the PHP file to check codes updates.
the controllers/bookngcontroller.php has been modified with the following lines of code :
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
...
PluginHelper::importPlugin('rentalot');
// permits to do something after sending the booking mail to visitor
$app = Factory::getApplication();
$result = (array) $app->triggerEvent('onRentalotSubmitBooking',
array('com_rentalot.booking', $post_data, $this->backend_booking_model, $check)
);
See history updates on the PHP file to check codes updates.
The folder 'plugins' contains plugins in the joomla group/type 'rentalot' to explain how to developp them and to test them on Rentalot component Enquiries or Booking with the previous modification of the code in the controller!
- group = "rentalot"
- name = "plg_rentalot_(plugin name)"
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.8" type="plugin" group="rentalot" method="upgrade">
<name>plg_rentalot_myplugin</name>
...
see the manifest of the example plugin.
- class name = "PlgRentalot(Plugin name)"
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
class PlgRentalotMyplugin extends CMSPlugin
...
And add events you want: onRentalotSubmitEnquiry, onRentalotSubmitBooking ...
see the script of the example plugin.