From 49eb49efdb6c812855fe30eb6fd05375bdee1300 Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Tue, 4 Jun 2019 17:02:35 +0200 Subject: [PATCH] Updated 008 Advanced Fields (markdown) --- 008-Advanced-Fields.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/008-Advanced-Fields.md b/008-Advanced-Fields.md index 305f4f5..2951a1e 100644 --- a/008-Advanced-Fields.md +++ b/008-Advanced-Fields.md @@ -26,27 +26,32 @@ Getting back to extending a list field: you simply add list. There are a few con To explain what the system is doing, go to components, open 'Sermon Distributor,' take the name in code, like that 'sermondistributor', copy, and you'll see that it is a lowercase 'c.' If it had been an uppercase l it would mean that you'd have to place the component's name with an uppercase as well. [00:11:12](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m12s) The system is replacing these place holders with the actual component name on the fly. Using the placeholders saves you time in the long run from making changes everywhere if you make a change to a component's name. Which is quite normal to do. Often you start with the component and think of calling it something and later realize that the name is been used in the Joomla repository, and you need to choose another name. To do that is going to affect the whole component, so we added this placeholder structure which should make the data easier. +In all the custom coding that you're adding where you need to use the components name, you can use the tag format of replacement. [00:12:16](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m16s) In some areas you would need to use brackets. Most of the time it works either way. The best way to ensure that it works is to try it with a hashtag first; if it didn't replace it in the code, the angle brackets need to be used. In this case we are using these ### characters. Again, the view is the single variable of the view. If we close and go to the view which would be preacher, all lowercase is what you would be adding here. Make sure that it's always lowercase. [00:13:20](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m20s) - - -Anywhere in all the custom coding that you're adding and you need to use the components name, [00:12:16](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m16s) you can simply use this ### tag format of replacement. In some areas you would need to use brackets like that [[[. But most of the time it will work either way. The best measure to ensure is to try it with a # first and if you go into the code and you see it didn't replace it, then you know it's the angle brackets[[[ that needs to be used anyway. In this case we are using these ### sign characters. The view again, that is this single variable of the view. If we were to close, and go to the view(admin) which would be then preacher, all lowercase, is what you would be adding here. Make sure that it's always lowercase. [00:13:20](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m20s) - -Then the list view or the views plural, would be the add value there. All lowercase as well and then the value field is the field that the user will see. That is what is visible in the UI user interface. The key field is the value that will be stored in the database. This field relate to this table(#-###component###-preacher). Inside this table, what field do you want the user to see? That would be the name of the preacher. And inside this table, what field would you want to store in the other database? Because we are looking into preacher but we are going to store it wherever this field is being used. That would be the ID and the column name in that data base of that view where this field will be used, will be called [00:14:24](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m24s) preacher. To show that to you in the database itself. You can open it there,(See video) scroll down to sermon distributor, open sermons, click on structure, and here in the back end. Go to sermons, click 'new' and you will see that there is a place for preacher. If I was to look with firebug at it, we'll see that it is the name is preacher and remember we spoke about this Jform_ as the ID. But it's actually simply the preacher field which is being stored directly in the database in the preacher [00:15:28](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m28s) column of the table. It's stored as INT 11 and we say that it is a key. We can target it. At the bottom if we look at indexes, we'll see that it has actually added it as a key. +The list view (or the views plural) would be the add value there. All lowercase too. The value field is the field that the user will see. It is visible in the UI user interface. The key field is the value that will be stored in the database. This field relate to this table (#-###component###-preacher). Inside this table, which field do you want the user to see? The name of the preacher. Inside this table, which field would you want to store in the other database? We are going to store it wherever the field is being used. That would be the ID and the column name in that data base of that view where this field will be used. [00:14:24](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m24s) It will be called preacher. To show that in the database itself. Open it. (See video.) Go to sermons, click 'new,' and you will see a place for preacher. If you were to look with firebug at it, you'd see that it is the name is preacher. (Remember we spoke about this Jform_ as the ID.) It's simply the preacher field which is being stored directly in the database in the preacher column of the table. [00:15:28](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m28s) It's stored as INT 11 and we say that it is a key. We can target it. If we look at indexes, we'll see that it had added it as a key. **Custom PHP layout in Field Definition** -That all is done in the database structure and then in this area here(See video). Again in this part you can add your own custom PHP. The fact that I'm using 19, 18, 17, it's just creating line breaks and spacing and tabs for me dynamically. I could have placed them all under PHP one, without this quotation marks. [00:16:32](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m32s) Wrapping around them all like we just did with the file folder list view example we did previously. Just a note inside of this code, you cannot use quotation marks, you need to use single quotes. Unfortunately at this stage it is not able to accommodate you even if you try to do an escape. It will not behave as you might expect. So my apologies for that. At this stage you can only do single quotes between these two quotations, double quotes. -That is adding a custom field which is a little bit more advanced. If you know PHP you will know exactly what's happening here. +All of that is done in the database structure and in this area. (See video.) Here you can add your own custom PHP. I'm using 19, 18, 17, etc so that it's creating line breaks and spacing and tabs for me dynamically. I could have placed them all under PHP one, without these quotation marks. [00:16:32](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m32s) We wrap around them like we did with the file folder list view example we did previously. + +(Just a note: inside of this code, you can't use quotation marks; you need to use single quotes, even if you try to do an escape. It will not behave as you might expect.) **Build Code for Sermon Preacher** -These place holders reflect back to these 'key_field_id' values here. So basically 'a.###ID###' will be written there [00:17:36](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m36s) and the text value which is the field value is going to be called 'a.###name###' and then '###ID###' and '###code_text###'. This code is build-up by the view that we are in, and the text, so this would read sermon preacher in the code. I can go show you how it looks when it builds it. Let's quickly look at that. To show you where it starts, let's open jformfieldlist. That is what it starts with, it replaces this place holder with your code. It replaces all these features up here as well and updates that(see video) and [00:18:30](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m30s) every where you see '###component###', it's going to be updated through component builder. Everything up here(selected area) will be replaced with your licensing tags. Let's look at the finished product. Sermon is placed on the module field and there is 'preachers'. Open it, [00:18:57](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m57s) you would see that it added preacher there, and in the input add it and it also shows you where, if you had trip that switch like we have explained to show the line numbers in your component. It shows you in what file. These files are found, if [00:19:15](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m15s) you go to component builder, under helpers compiler. These are the files that is being used to compile your component. When we go to the advanced section, we will go much more in-depth in regards to these files. +These place holders reflect back to these 'key_field_id' values. (See video.) Basically, 'a.###ID###' will be written here and the text value which is the field value is going to be called 'a.###name###' and then '###ID###' and '###code_text###'. [00:17:36](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m36s) This code is built up by the view that we are in, as well as by the text, so it would read sermon preacher in the code. + +* **Example (See Video)** + +To show you how it looks when it is being built. Open jformfieldlist. That is what it starts with, replacing this place holder with your code. It replaces all these features up here as well. [00:18:30](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m30s) Everywhere you see '###component###', it will be updated through component builder. Everything here will be replaced with your licensing tags. Let's look at the finished product. Sermon is placed on the module field and there is 'preachers'. [00:18:57](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m57s) If you open it you'd see that it added preacher there, and the input added. If you trip that switch, like we have explained, to show the line numbers in your component. It shows you in what file. [00:19:15](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m15s) These files are found if you go to component builder, helpers compiler. These are the files that are being used to compile your component. **Generate a New Button** -Now we just trying to get across how to build a component. [00:19:40](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m40s) Not to extend component builder itself as yet. At least here you can see where in the code it is building this and compiling this and putting it together. Remember we talked about getting the structure, let's [00:19:59](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m59s) go down. This(see video) is used for the button. This is to generate a new button. When you click on new, that(selected area) is the button. This area from there to there is generating the button. This is what controls whether the button should show up or whether it shouldn't. [00:20:21](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m21s) Even if it is to be set at all this is what generates the button. This area here, the 'get options', you will see, we said that it will show the name, and it will show 'ID'. Go back to our structure here, we dynamically replaces these(###ID###,###name###) with those 'view preachers'. The reason for it , is that it's actually done a few times. [00:20:48](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m48s) I felt like let's make it that you only need to update these values and then it gets updated all over in the bottom of the code. It makes it just much more easy to change your custom fields. It build a field called preacher name. Which again it uses here 'preacher_name' as a object value. Because it [00:21:17](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m17s) retrieves the object from the database and it looks as if that object exists, it actually reiterates and builds up option list which is returned to use in the drop down. It dynamically generates your list. So component builder through that infrastructure what I have [00:21:37](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m37s) Just explained here, compiles all of that code for you and puts it in the right file in the right place. +We are trying to build a component, not as yet to extend component builder itself. [00:19:40](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m40s) Here you can see where in the code it is building, compiling, and putting this together. [00:19:59](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m59s) This is used for the button. (See video.) This is to generate a new button. When you click on new, this is the button. This area is generating the button. This controls whether the button should show up or not. [00:20:21](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m21s) If it is to be set at all, this is what generates the button. We said that the 'get options' will show the name and 'ID'. Going back to our structure here, we dynamically replace these (###ID###,###name###) with 'view preachers'. The reason for this is that it's done a few times. [00:20:48](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m48s) We'll say that you only need to update these values and it would get updated all over in the bottom of the code. It makes it easier to change your custom fields. A field called preacher name was built. Which again used 'preacher_name' as an object value. [00:21:17](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m17s) Because it retrieves the object from the database and it seems as if the object exists, it reiterates and builds up option list which is returned to use in the drop down. It dynamically generates your list. So component builder through this infrastructure compiles all of the code for you and puts it in the right file in the right place.[00:21:37](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m37s) + +Once you have built a component and know where you have made those changes in component builder you can look at the files if you know how to build a Joomla website. I used the same conventions as decor in regards to implementation of the files. [00:22:07](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h22m07s) + + - Once you build a component and you know where you have made those changes in component builder, you can go look at those files if you know how to build a Joomla website. I used the same conventions as decor in regards to implementation of the files. [00:22:07](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h22m07s) **Dropbox Custom List Example**