DPCalendar lets 3rd party Joomla extensions interact with DPCalendar easily through plugin events. How a Joomla plugin can be developed is described in this article.
Want to integrate your own DPCalendar calendar plugin with data from an external system? Please have a look at the Create a DPCalendar plugin article.
DPCalendar fires the Joomla content events when an event, location, booking or ticket is saved or displayed. This allows other plugins to interfere into the processes. The Joomla custom fields are integrated like that into the forms and when displaying these items.
Beside the default Joomla events, DPCalendar fires some specific events where plugins can hook in.
Description
Before DPCalendar is executed in the back end. This allows plugins to perform certain tasks or redirect to different pages.
Parameters
Return value
Nothing.
Description
Is triggered before a mail is sent in DPCalendar. This event allows to to customize the sent out mail, with attachments a new subject, body or addresses.
Actually the following contexts are supported:
Parameters
Return value
Nothing.
Description
Is triggered after a mail is sent in DPCalendar. This event allows to to cleanup some stuff.
Parameters
Return value
Nothing.
Description
Is triggered when the toolbar is filled with actions. Does allow the plugin to add custom actions.
Parameters
Return value
Nothing.
Description
Is triggered when the whole booking is saved and mails were sent out.
Parameters
Return value
Nothing.
plg_dpcalendar_helloworld --- helloworld.xml --- helloworld.php --- index.html --- language --- ---- en-GB --- ---- ---- en-GB.plg_dpcalendar_helloworld.ini --- ---- ---- en-GB.plg_dpcalendar_helloworld.sys.ini
Manifest (dpcalendar_helloworld.xml) The manifest file describes the plugin and delivers Joomla the necessary information during installation. An example is shown below.
<?xml version="1.0" encoding="utf-8"?> <extension version="3.9" type="plugin" group="dpcalendar" method="upgrade"> <name>plg_dpcalendar_helloworld</name> <author>Digital Peak</author> <creationDate>Aug 2018</creationDate> <copyright>(C) 2018 Digital Peak GmbH. <https://www.digital-peak.com> </copyright> <license>https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license> <authorEmail>info@digital-peak.com</authorEmail> <authorUrl>joomla.digital-peak.com</authorUrl> <version>7.0.0</version> <description>PLG_DPCALENDAR_HELLOWORLD_XML_DESCRIPTION</description> <files> <filename plugin="helloworld">helloworld.php</filename> <folder>language</folder> </files> <config> <fields name="params" addfieldpath="/administrator/components/com_dpcalendar/models/fields"> <fieldset name="basic"> <field name="ext" type="extcalendar" plugin="helloworld" label="" description=""/> </fieldset> <fieldset name="advanced"> <fieldset name="advanced"> <field name="cache" type="list" default="1" label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_DESC"> <option value="1">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_JOOMLA</option> <option value="2">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_DB</option> <option value="0">PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_NEVER</option> </field> <field name="cache_time" type="text" default="900" showon="cache:1" label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_TIME_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_TIME_DESC"/> <field name="sync_start" type="text" default="-3 year" showon="cache:2" label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_START_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_START_DESC"/> <field name="sync_end" type="text" default="+3 year" showon="cache:2" label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_END_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_END_DESC"/> <field name="sync_steps" type="text" default="1 year" showon="cache:2" label="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_STEPS_LABEL" description="PLG_DPCALENDAR_HELLOWORLD_FIELD_CACHING_SYNC_STEPS_DESC"/> </fieldset> </fieldset> </fields> </config> </extension>
The file /administrator/components/com_dpcalendar/libraries/dpcalendar/DPCalendar/Plugin/DPCalendarPlugin.php can be used as base class to create the PHP file. Here is an example how it is recommended to implement a DPCalendar plugin.
<?php /** * @package DPCalendar * @copyright Copyright (C) 2018 Digital Peak GmbH. <https://www.digital-peak.com> * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL */defined('_JEXEC') or die();use Joomla\CMS\Date\Date; use Joomla\Registry\Registry;class PlgDPCalendarHelloworld extends \DPCalendar\Plugin\DPCalendarPlugin { protected $identifier = 'hw'; protected function getContent ($calendarId, Date $startDate = null, Date $endDate = null, Registry $options) { $start = DPCalendarHelper::getDate(); $start->modify('+1 day'); $end = clone $start; $end->modify('+2 hour'); $buffer = "BEGIN:VCALENDAR VERSION:2.0 PRODID:-//DPCalendar BEGIN:VEVENT UID:sdfsf8erhklf89zrjklh890hoih89 DTSTAMP:20140714T170000Z ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com DTSTART:" . $start->format('Ymd\THis\Z') . " DTEND:" . $end->format('Ymd\THis\Z') . " SUMMARY:Demo Hello world event DESCRIPTION:This is a demo event in the hello world DPCalendar plugin. LOCATION:New York END:VEVENT END:VCALENDAR"; return $buffer; } }
Comments (0)