-
-
Notifications
You must be signed in to change notification settings - Fork 178
071 Reuse Custom Code
00:00:00 (Click on these time links to see Youtube video)
I would like to show you how to use code across JCB in a very inherent kind of way by taking the advantages of a few features that JCB has. Features that most people may not know is there, or maybe they do but they haven't seen it as an advantage. Recently there came up a question on the forum By Alex Dings, asking 00:00:33 about, he ask admin views but generic code that runs in multiple admin views and then some of it runs only in specific admin views. How I could speed up the maintenance of this kind of thing. His first question is, is the helper admin class the best way to put this code? Is there a way to keep the direct admin forms functions I wrote separate from these specific ones? I'm sure some of you might even be listening and don't understand exactly what we trying to do. I'm not even sure if I'm exactly going to answer this.
I'm quickly going to pull up a docker image of Joomla. I have a docker file, quickly going to pull it up. We are going to go and use it. I've it running. Its default is user. I'm going to go to extensions and install. Add the web tab JED 00:01:46 JED Then type jcb and underneath we have a description, you can look at that and install. Getting JCB install from GitHub. We're done. Go Joomla Component Builder, we're almost there. Then 00:02:22 you could grab a demo component. If you don't know how to get access to these components, follow this 'free keys' link and follow the tutorials. I'm going to get the JCB Get Package. The key that you have received, you can add it here. Maybe Force Local Update. It is always good to have all your fields updated. 00:02:52 Continue, within moments we have JCB installed on JCB.
Now we can start looking at the examples. That's really what I wanted to get to. Because the question is being answered by the demo data already. In JCB there we are already doing a lot of this multi inheritance structure kind of relationships. The best way to demonstrate this is to look at JCB itself. We're almost there. We have JCB. If we go to custom code, we'll see there's a whole lot of custom code. 00:03:40 Many of them is this Hash (automation). We want to look at this JCB( manual) option. For example let's look at the getViewID which is a custom code, that is its name. This is how you use it. We are having a view 00:04:01 called Admin View that is using it. If you click on that it is going to open it for us the Admin View. When we get here, we'll see there is the code. I'm using this specific getViewID all across my components. It's also being used in JCB. It's powerful. 00:04:31 That is one way to use a specific snippet which you add by using the JCB manual. Give the function and name. You could pass values to the function(see video). Please read the explanation how that is done. At the end of the day 00:04:55 you can adapt the value structure, for example if this value(vdm) needs to be changed from instance to instance, you can pass it by value1, that are arg0. You can replace this vdm with [[arg0]. You must remember to pass, at least value1 00:05:27 to update the [[arg0] value wherever you are using it. That's one way to use the reuse the scripting.
The other way is the one that actually gets used in the helper class. I have one called getFilePath. The getFilePath is also a function I am using across my components. It is being included in JCB. Many of my components are using getFilePath and it is a little function I can pass a few parameters to and can consistently give me back a path of where I want to place or have files from. Now in the PHP helper there is a function and in the component itself, there is a function called 00:06:20 helper classes - Both admin & site.
???? So anything you put in here will be not only added to the admin helper class but also to the site Helper class sort of a way to Avoid doing it twice And As you can see There is one to just put it in the admin So you could just take care and just target the admin helper Or you could just target the site class helper But in this case most of this code I wanted to be everywhere 00:06:52 And if we were to Go down to the very bottom suppose here Is the Get file Path So it is forming part of a whole bunch of code that I'm adding to the helper class of this component And which I'm also using another components so I don't need to redo this code anytime soon unless in in sorry I don't need to come and open the 00:07:20 Component when I want to change this code I can just change the code Right there In the Place that it's in the custom area So that means if we close out here And we go back to the custom code You can see that the function is being used in component builder and in what field there PHP helper both It's where it's added And 00:07:45 If you'll need improving the code you can always at the bottom see in which areas is being used So that is the option for multiple reuse of custom scripting So you could put it anywhere you like in JCB either in the component helper class or in the component View You know PHP areas And by doing so it gets reused it gets placed into that code on compilation And that's really the answer I suppose To the power of the customer code area I realize it could be confusing because we are mixing it with the IDE custom code which These are 00:08:28 This hash Automation Is basically where you Edited your code in the IDE like I did here And the JCB is keeping track of it And it's saying ok this is for the admin views template default body php file And on the on this starting hash Value We are doing an insert of this code and you cannot maintain the code here But it's only for one file one location one place 00:08:57 Then there's the JCB manual and the JCB manual Is the implementation or the mutated implementation Of using custom code snippets this snippet All across in custom code areas So that means I'm using the same word custom code For different implementation And That might have been a mistake because You could miss it's possible differences 00:09:25 But there is most certainly a difference this doesn't target a file but a actual area Somewhere in that JCB compilation So Yeah I hope that helps Let me know.
- 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