Table of Contents
How to Add More Helper Methods to your Components Helper Class
Ok let's quickly look at adding and methods to your components helper class you obviously go to the component And Then you go to this Libs and helpers tab 00:00:14 There is a few areas here to Target the helper class And There's one that's called site helper Then there's one that is called Admin So you could Add this This is the admin area This is the site area then there is one called both So if you want to add and helper method to your 00:00:44 Site area You basically added here like I've done with this Fancy date Added it to the site area of the component Just to demonstrate the other one The admin area I'm just gonna Say This Is admin And then I'm also gonna do the one that says both admin and site 00:01:08 And just say This is both So basically If you want to add a method that it must be accessible from both front and Backend site and admin area Then you use that one If you want a method just available in the admin area then you use this one And if you want a method available in the site area than you use this one And so Let's let's run this and see how it looks 00:01:43 Ok I'm gonna compile it Ok let's see Let me just quickly go and remove that I don't want that in there Ok I'm gonna just install this Then go let's go look at the code Ok so we have I have our Joomla Mount Project here and there is the admin area And there is the front end 00:02:10 components area So let's first go to the admin area components Then to demo and then we go to the Helper area And then we go to demo again we open that up and if we scroll down it says here this This is admin this is both see so it added those values in here And we don't see the date Function here Because it was set to for the site area So if we 00:02:44 Close the admin go to the component Then again demo Helper Again demo We'll see That it has this Fancy date Set here And then it has this as both So 00:03:01 Whatever is placed in both gets placed in both the front and back or site and admin Helper class And then you could target specific areas by either just admin or just site And that's really how you get methods into the helper class quite easily Now if you want to Actually add your own file your own helper class Then you'll have to do a lot more to get this to work Because the helper method Is being called in the components Main file 00:03:40 so you see there is a register The helper Method See it's getting registered here And so this is the helper classes name And whatever Method you wanna call So if you wanna call for example we are in the site Area Say we wanna call the fancy date 00:04:02 We'll basically Have to call it like this Which I suppose this Easy to understand So that's how we would call it with the date value Ok so That's how you call it and then you obviously put it into Whatever other variable you want 00:04:28 And you use it as you like If you add your own helper class Meaning your own file literally Then you'll have to go about this a little different There is a way to do that let me quickly show you It's a little bit of a workaround because I've had to do that Sometimes First of all you obviously use the File and folder inclusion I did the advance one or the basic 00:05:06 Depending on where your file's located And then you would grab that specific File Let's say this one And you will placed the path In corresponding to the Zip file where you wanted and whether it should be updated and all that Same goes with this I'm not gonna explain how you add the file that much because there is tutorial how to do this and just go watch it on on YouTube 00:05:35 If you have questions But this would be the first step Second step is to obviously add that Specific file Now We have in the component helper We have what is called a global event So the global event Is an event you want to trigger as often as the helper class gets added So it's a little bit of a 00:06:01 Little in-house tweak Because we want to sometimes have a Event take place every time the helper class gets loaded So this is the admin Event Add a global admin event so every time the global Admin is going to be added We want a method to be triggered so What is that method First wait to see all that is I'm just gonna add here 00:06:33 The event So if you can see so I'll just add that little snippet there that's just for the admin area and gonna save and close And then compile it again and install to see it in the code Ok let's go to the code Say yes Now we'll see This is the site the helper method Let's go to the admin helper method 00:06:59 We'll see now there is a global event That says The event In the Admin This is the admin if we look at that path It is the administrator component Com demo helpers helper class so this is the admin event And it now has the string of the event in it If we go to the admin area 00:07:22 And we open The demo Main file which is what Joomla grabs he's start with this one We'll see that there is a little bit of a snippet been added And that snippet Triggers The global event With The document Object being passed 00:07:45 So going back here here comes the document we can actually affect the document With a global event Every time A view of this component loads because the helper method Always Gets Triggered every time this backend admin File gets loaded So You have a event now if you want to add your custom Helper class to be available 00:08:11 The way to do that Would be just to Add it here To this event Because then you can add your own helper class so we'll call this own Just just an idea and Let's call this file also Own Ok So 00:08:38 And then save that And from now on every time in the backend This helper method will be available To you to use Without ever Sorry helper class will be available to use with whatever A method is in it So going back to the UI You obviously have to load this file in manually like I've showed when We started looking at this 00:09:07 But now going back We'll just I like this thing Copy Go to The component And Then To the event And basically add that in there 00:09:26 And update our little comment saying The Custom Helper class Now what's important is you could do the same For the front end That is the site event you can add the same here you'll just again Have to move that file to the front ends helper Folder With the helper 00:09:57 Sorry the file including method there is tutorials on how to do the file including You know and moving it to the helper class and all that there is tutorials and how to do that I'm not gonna demonstrate again please just go look at the tutorials on YouTube There is tutorials about this I'm sure you can find that's not that hard Ok save again Should have been save and close So just to demonstrate I'm gonna compile and installed this demo component once again Now let's look at the code 00:10:32 And we'll see now It's being triggered Here As well as in the site Component is being triggered And here it is being triggered In the main document and also here in the main document site and admin both alike So that's just too quick work around which isn't that much of a workaround it's Just basically using a global event To handle file inclusion 00:11:02 If you wanted to only be done per a specific View Then once again there is a different way to do that And there is away actually to do that But This is how to do it globally for all the views and have that helper file already there I usually just use the components own helper file mostly I really hardly ever use this event for Inclusion of files Simply because Why 00:11:33 Put it another place just put it here But there is other purposes you see me passing the document object there And that could be because I wanna add some things to the document before any paid loads And that's what I I have it there it's quite useful for that kind of use anyway hope This helps thanks for watching until next time take care
m
- Home
- Beta Testing
- Custom Code
- PHP Settings
- Demo Component
- Tutorials
- Hello World JCB
- Intro JCB Guide
- JCB Installation Steps
- Planning Components
- Field Type Overview
- Basic Fields Creation
- Admin View Management
- Advanced Field Usage
- Admin Component Integration
- Component Setting Customization
- Scripting Components
- Component FTP Options
- Dynamic Get Method
- Site View DynamicGet
- Site View Templates
- Template Setup Guide
- Layout Configuration Steps
- Custom Admin Management
- Adding Site Views
- Custom Admin Integration
- MySQL Demo Tweaking
- Global JCB Settings
- Custom Time Field
- User Helper Integration
- Email Helper Usage
- Message Store Email
- List View Unescape
- Export Import Customization
- Overwrite Custom Fields
- List Field Filtering
- Automatic Code Import
- Manual Code Implementation
- Component Export Import
- Custom Admin Buttons
- Translation Management
- Site View Permissions
- Component SQL Updates
- Site Edit Configuration
- JCB Backup System
- Helper Structure Integration
- JCB v2.5 Upgrade
- Tab Setup Guide
- JCB v2.6 Release
- Extended HelloWorld
- Field Rule Validation
- Community Snippets Intro
- Snippet Forking Tutorial
- Pull Request Snippets
- Library Manager Area
- Excel-based Translation
- Dynamic Router Details
- Database Auto Updates
- Subform Quick Demo
- VDM Package Import
- Dynamic File Inclusion
- File Field Upload
- Drag-n-Drop Upload
- Quick HelloWorld JCB
- Non-database Fields
- Dashboard Customization
- Menu Prefix Toggle
- Community JCB Packages
- Collaborative JCB Workflow
- JCB Package Install
- JCB JAB18 Event
- Convenient New Fields
- Component Language Strings
- Library Functionality Anticipation
- Join Field Relations
- License Template Change
- Code Reusability
- Local Dev Environment
- Extended Field Types
- Joomla Custom Fields
- Custom Field Expansion
- Site View Listing
- Run Expansion Method
- Form Site View
- Field URL Update
- Additional Helper Methods
- Field Validation Rules
- New Placeholder Feature
- Component Config Params
- Per-field Default Values