diff --git a/071-Reuse-Custom-Code.md b/071-Reuse-Custom-Code.md index 693afa7..f0edc9a 100644 --- a/071-Reuse-Custom-Code.md +++ b/071-Reuse-Custom-Code.md @@ -1,4 +1,15 @@ # REUSE CUSTOM CODE +### How To Use Code Across JCB By Taking Advantages Of A Few Features + [00:00:00](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s) -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 may not know is there or maybe they do but they not seen it's advantage And then recently there actually came up a question On the Forum By Alex Tings asking [00:00:33](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m33s) About You know he ask admin views but Generic code that runs in Multiple admin views and then some of it runs only in specific admin views And how I could how I could speed up the maintenance of this kind of thing So his first question is is the helper admin class the best way to put this code and then is there a way Keep the direct admin forms functions I wrote separate from these specific ones Ok I'm sure some of your might even be listening here and I'll understand exactly what we trying to do And I'm not even sure if I'm exactly going to answer this you know [00:01:12](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m12s) So I'm gonna quickly pull up a docker image of Joomla I have a docker file there just quickly gonna pull it up And then we gonna go and use it Ok Ok so I've got it up running I think it's default is user Ok so where in here I'm gonna go to extensions and install And Basically add the web tab The JED [00:01:46](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) JED Then type JCB and here we have Description can look at that And install Sort of getting the JCB install from GitHub Ok we're done Go Joomla component builder we're almost there Then [00:02:22](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) We could Grab a demo component If you don't know how to get access to these components just follow this link and Follow the tutorials So I'm just gonna get the JCB package And then the key that You were send you will add here Maybe force and update is always good sort of get all your Fields updated [00:02:52](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m52s) OK now Continue And 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 So [00:03:12](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m12s) In JCB there we already doing a lot of this multi Inheritance structure kind of relationships And So the best way to sort of demonstrate this is to actually look at JCB itself OK we're almost there OK we got JCB Here Now if we go to custom code We'll see there's a whole lot of custom code And [00:03:40](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m40s) Many of them is this hash Automation Now we wanna look at this JCB manual option For example let's look at the getviewID Which is a custom code Basically that is its name This is how you use it And Here We are having a view [00:04:01](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) Called admin View That is using it So if we click on that Is going to open for us the admin View And when we get here we'll see there is the the code now This actually is the I'm using this specific get view ID All across my components is just It's also being used in JCB But it's it's powerful So I'm using it everywhere [00:04:31](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m31s) So that's one way To use A a specific snippet Which you add here use the JCB manual Give the function and name You could pass values to the function like this And Please read the explanation here To how that is done And the end of the day [00:04:55](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m55s) You can then adapted the value structure for example if If this value here needs to change from instance to instance you can pass it by This value one Which that will be arg0 And then you can just actually replace this here with 3 Then arg0 and 3 again like that And then you just remember to pass At least one value [00:05:27](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m27s) To update This value Where ever you using it That's one way to use the reuse the scripting Now the other way Which is the one that actually gets used in the helper class It's like here I got one called get file path To get file path is also a function Which I am using across my components It is just also being included in JCB [00:05:55](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m55s) But many of my components is using get file path And basically It is a little function That I can pass a few parameters to and can consistently give me back a path of where I want to place or get files from Now in the PHP helper there is a function And the component itself That's me here There is a function called [00:06:20](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m20s) Helper classes for both admin and 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m52s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m20s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m45s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m28s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m57s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m25s) 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. +(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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m33s) 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. + +### Pull Up A Docker Image Of Joomla + +[00:01:12](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m12s) + +???? +I'm quickly going to pull up a docker image of Joomla. I have a docker file there, quickly going to pull it up. We are going to go and use it. I've running. Its default is user. Ok so where in here I'm gonna go to extensions and install And Basically add the web tab The JED [00:01:46](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) JED Then type JCB and here we have Description can look at that And install Sort of getting the JCB install from GitHub Ok we're done Go Joomla component builder we're almost there Then [00:02:22](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) We could Grab a demo component If you don't know how to get access to these components just follow this link and Follow the tutorials So I'm just gonna get the JCB package And then the key that You were send you will add here Maybe force and update is always good sort of get all your Fields updated [00:02:52](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m52s) OK now Continue And 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 So [00:03:12](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m12s) In JCB there we already doing a lot of this multi Inheritance structure kind of relationships And So the best way to sort of demonstrate this is to actually look at JCB itself OK we're almost there OK we got JCB Here Now if we go to custom code We'll see there's a whole lot of custom code And [00:03:40](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m40s) Many of them is this hash Automation Now we wanna look at this JCB manual option For example let's look at the getviewID Which is a custom code Basically that is its name This is how you use it And Here We are having a view [00:04:01](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) Called admin View That is using it So if we click on that Is going to open for us the admin View And when we get here we'll see there is the the code now This actually is the I'm using this specific get view ID All across my components is just It's also being used in JCB But it's it's powerful So I'm using it everywhere [00:04:31](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m31s) So that's one way To use A a specific snippet Which you add here use the JCB manual Give the function and name You could pass values to the function like this And Please read the explanation here To how that is done And the end of the day [00:04:55](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m55s) You can then adapted the value structure for example if If this value here needs to change from instance to instance you can pass it by This value one Which that will be arg0 And then you can just actually replace this here with 3 Then arg0 and 3 again like that And then you just remember to pass At least one value [00:05:27](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m27s) To update This value Where ever you using it That's one way to use the reuse the scripting Now the other way Which is the one that actually gets used in the helper class It's like here I got one called get file path To get file path is also a function Which I am using across my components It is just also being included in JCB [00:05:55](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m55s) But many of my components is using get file path And basically It is a little function That I can pass a few parameters to and can consistently give me back a path of where I want to place or get files from Now in the PHP helper there is a function And the component itself That's me here There is a function called [00:06:20](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m20s) Helper classes for both admin and 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m52s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m20s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m45s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m28s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m57s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m25s) 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.