Joomla Plugin Development

Select your language

/**
     * Returns an array of events this subscriber will listen to.
     *
     * @return  array
     *
     * @since   5.0.0
     */
    public static function getSubscribedEvents(): array
    {
        return ['onContentPrepare' => 'onContentPrepare',
			   'onAfterRender' => 'onAfterRender'];
    }

Above mentioned function is used in plugin when we implements SubscriberInterface interface, using following code:

final class Vdocipher extends CMSPlugin implements SubscriberInterface

This method is important, think of registering an task inside constructor of an controller class of a component. This function is going to register an event that is not part of specific plugin group, but can be executed using this code. For example I did a content plugin, with following xml:

<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="content" method="upgrade">
	<name>plg_content_vdocipher</name>
	<creationDate>Jan 2024</creationDate>
	<author>Abdul waheed</author>
	<authorEmail>This email address is being protected from spambots. You need JavaScript enabled to view it.</authorEmail>
	<authorUrl>www.abdulwaheed.pk</authorUrl>
	<copyright>Copyright (C) 2024, All rights reserved.</copyright>
	<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
	<!--  The version string is recorded in the components table -->
	<version>1.0.0</version>
	<!-- The description is optional and defaults to the name -->
	<description>PLG_VDOCIPHER_DESCRIPTION</description>
	<namespace path="src">Joomla\Plugin\Content\Vdocipher</namespace>
	<files>
		<folder plugin="vdocipher">services</folder>
		<folder>src</folder>
	</files>
	<languages>
		<language tag="en-GB">language/en-GB/plg_content_vdocipher.ini</language>
		<language tag="en-GB">language/en-GB/plg_content_vdocipher.sys.ini</language>
	</languages>
	<config>
		<fields name="params">
			<fieldset name="basic">
				
				<field
					name="apikey"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_API_KEY"
					showon=""
				/>
				
				<field
					name="width"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_WIDTH"
					showon=""
				/>
				<field
					name="height"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_HEIGHT"
					showon=""
				/>
				<field
					name="playbackspeed"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_PLAYBACKSPEED"
					showon=""
				/>
				<field
					name="playerid"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_PLAYERID"
					showon=""
				/>
				<field
					name="annotation"
					type="textarea"
					label="PLG_CONTENT_VDOCIPHER_ANNOTATION"
					filter="raw"
				/>
				<field name="type" type="list" default="" label="PLG_CONTENT_VDOCIPHER_TYPE" description="">
				  <option value="rtext">Animated</option>
				  <option value="text">Static</option>
				</field>
				<field name="showname" type="list" default="" label="PLG_CONTENT_VDOCIPHER_NAME" description="">
				  <option value="1">Yes</option>
				  <option value="0">No</option>
				</field>
				<field name="showemail" type="list" default="" label="PLG_CONTENT_VDOCIPHER_EMAIL" description="">
				  <option value="1">Yes</option>
				  <option value="0">No</option>
				</field>
				<field name="showip" type="list" default="" label="PLG_CONTENT_VDOCIPHER_IP" description="">
				  <option value="1">Yes</option>
				  <option value="0">No</option>
				</field>
				<field
					name="alpha"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_ALPHA"
					showon=""
					   default="0.60"
				/>
				<field
					name="color"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_COLOR"
					showon=""
					   default="0xFF0000"
				/>
				<field
					name="size"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_SIZE"
					showon=""
					   default="15"
				/>
				<field
					name="interval"
					type="text"
					label="PLG_CONTENT_VDOCIPHER_INTERVAL"
					showon=""
					   default="5000"
				/>

				
			</fieldset>
		</fields>
	</config>
</extension>

We need to execute a system plugin event onAfterRender into our content plugin, so inside this method, getSubscribedEvents we registered our event along method to be execute like that: return ['onAfterRender' => 'onAfterRender']; , in return to this code. onAfterRender event will be execute.

 Hope this helped.


Still need help! no problem, feel free to contact us Today


 Abdul Waheed : (Hire Joomla & PHP Pakistani Freelancer)