Updated 071 Reuse Custom Code (markdown)

Amigo 2019-10-03 11:47:07 +02:00
parent f6cf0e3ced
commit b5726b5bce

@ -5,19 +5,19 @@
[00:00:00](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
(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.
I would like to show you how to use code across JCB in a very inherent kind of way by taking the advantages of few features that JCB has that most people may not know is there, or maybe they do but they have not seen it as an advantage. Recently there came up a question on the forum By Alex Dings, [00:00:33](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m33s), he said that he has 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 had been: Is the Helper Admin class the best way to put this code? Is there a way to keep the generic admin forms functions I wrote separately from these specific ones? Some of you might even be listening and do not understand exactly what we are trying to do.
### 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, 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m52s) Continue, within moments we have JCB installed on JCB.
I am going to pull up a docker image of Joomla. I have a docker file, and quickly going to pull it up. We are going to go and use it. I have it running. Its default is user. I'm going to go to extensions and install. Add the web tab JED [00:01:46](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m52s) Continue, within moments we have JCB installed on JCB. <<<<<<<<<
### Looking At Examples - GetViewID
[00:03:00](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m00s)
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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m40s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m31s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m55s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m27s) to update the [[[[arg0]]] value wherever you are using it. That's one way to use the reuse the scripting.
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 relationship. 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 will see there is a whole lot of custom code. [00:03:40](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m40s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) 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](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m31s) 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 of how that is done. At the end of the day [00:04:55](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m55s) 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 is arg0. You can replace this vdm with [[[[arg0]]]. You must remember to pass, at least value1 [00:05:27](https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m27s) to update the [[[[arg0]]] value wherever you are using it. That's one way to use the reuse of the scripting.
### Another Way To Reuse - getFilePath