Updated 073 JCB Fields Type Extended (markdown)

Amigo 2019-10-31 09:49:15 +02:00
parent b671dee016
commit fa12eebb28
1 changed files with 8 additions and 8 deletions

@ -3,39 +3,39 @@
[00:00:00](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
(Click on these time links to see Youtube video)
I would like to give a demonstration and maybe some explanation about the functionality of a Custom field. Some tutorials about this had been given in the past but JCB has improved and there is a little bit of a different look [00:00:25](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m25s) to that area. Let me do this again and show in the Compiler what it is actually doing. Here are a few views. [00:00:46](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m46s) I've imported Sermon Distributor which is the most common demo component that I have used and it has a few Custom Fields so I could actually change this. This one is changed to Custom and we see that we've got a few Custom Fields here. The idea was that you would [00:01:15](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m15s) use the demo components and then figure out how their Custom Fields work.
I would like to give a demonstration and maybe some explanation about the functionality of a Custom field. Some tutorials about this had been given in the past but JCB has improved and there the area has bit of a different look. Let me do this again and show in the Compiler how it actually functions. Here are a few views. [00:00:46](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m46s) I've imported Sermon Distributor which is the most common demo component that I have used which has a few Custom Fields. I could actually change this(Follow on video). This one is changed to Custom and here is a few Custom Fields . The idea was that you would [00:01:15](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m15s) use the demo components and then figure out how their Custom Fields work.
### Custom Fields Connect A Table From One View To Another
[00:01:31](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m31s)
First of all Custom Fields is a way to connect a table from another view of course into another view. Then you can have more than one Custom Field in a table and you can do that to build relationships. You could even take different tables and create a different combined list of values. You can really do anything with Custom Fields it is maybe one of the most powerful Field types in JCB.
First of all Custom Fields is a way to connect a table from another view of course into another view. Then you can have more than one Custom Field in a table and you can do that to build relationships. You could even take different tables and create a different combined list of values. You can really do anything with Custom Fields, it is maybe one of the most powerful Field types in JCB.
### Custom Fields A Joomla Concept
[00:02:24](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m24s)
In the Editor, I would like to show you that Custom Fields are basically a Joomla implementation or concept. So in your Models folder, you have a folder called 'fields'. In Joomla 4 this is changing the folder structure but in for now, you will know it is here and so here is our Custom Fields. It is a field that you create by creating a file in this folder and then [00:03:17](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m17s) using the field name in your XML.
In the Editor, I would like to show you that Custom Fields are basically a Joomla implementation or concept. So in your Models folder, you have a folder called 'fields'. In Joomla 4 this is changing the folder structure but for now, you will know it is here and so here is our Custom Fields. It is a field that you create by creating a file in this folder and then [00:03:17](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m17s) using the field name in your XML.
If you look at the form and let's say we use Sermon, you will see that in the XML at the top we have `addfieldpath` and it can be seen that it ends in the model because of how we do it expects it to be here. [00:03:44](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) That's why it knows to go look for the field here. Now if you scroll down you will see that we have a 'normal' and wherever it says `Joomla`, it means it's a normal field. At the moment it says `custom`, it means that this is not a 'normal' field this field was custom made for this component. Now this (`<--....-->`) is just a note. [00:04:11](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m11s) It's like the comment it doesn't do anything. So you can come here in the fields area and there are `preachers`. This is the file that makes this work. That's basically what JCB builds, it puts this in place and then builds this file and that's it. [00:04:36](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m36s) In these files depending on what type of file we are extending; so now we are extending here the list option(`JFormfieldlist`).
If you look at the form and let's say we use Sermon, you will see that in the XML at the top we have `addfieldpath` and it can be seen that it ends in the model because of how we do it, it expects it to be here. [00:03:44](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) That's why it knows to go and search for the field here. Now if you scroll down you will see that we have a 'normal' and wherever it says `Joomla`, it means it's a normal field. At the moment it says `custom`. It means that this is not a 'normal' field. This field was custom made for this component. Now this (`<--....-->`) is just a note. [00:04:11](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m11s) It's like the comment it does not do anything. So you can come here in the Fields area and there is `preachers`. This is the file that makes this work. That's basically what JCB builds, it puts this in place and then builds this file. [00:04:36](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m36s) Here we are extending the list option(`JFormfieldlist`).
### Where To Find The Available Extension Options
[00:04:45](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m45s)
To know what is all the available extending options we go to Joomla Component Builder's file and go to the Compiler and to Joomla 3, then scroll down and there is the 'checkboxes' option and there is the 'Field list', the 'Field radio' [00:05:08](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m08s) and the 'Field user' but the field user we actually made a whole custom field to just target the field user but the 'checkboxes' and the 'radio'. If you go back to JCB and create new and select 'Custom' you would see that it at some point asks; what would you like to extend? [00:05:41](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m41s) And here are these three options you can extend that like a **List**, as a **Radio button** or **Checkboxes**. That is what this **'Extend'** is for. So that is currently the only 3 that is ready to go in JCB. There are of course others but then we will have to expand JCB. It doesn't reach those yet. If you are using a form list which is the most common one because you wanted to have a list of things in another table then you to populate the `getoptions` function.
To know what is all the available extending options we go to Joomla Component Builder's file and go to the Compiler and to Joomla 3, then scroll down and there is the 'checkboxes' option and there is the 'Field list', the 'Field radio' [00:05:08](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m08s) and the 'Field user' but the Field user we have made a whole Custom field to just target the Field user. Concerning the 'checkboxes' and the 'radio': If you go back to JCB and create new and select 'Custom' you would see that at some point it asks what you would like to extend. [00:05:41](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m41s) And here are these three options you can extend as a **List**, as a **Radio button** or as **Checkboxes**. That is what this **'Extend'** is for. So that is currently the only 3 that is ready to go into JCB. There are of course others but then we will have to expand JCB. If you are using a form list which is the most common one because you want to have a list of things in another table then you have to populate the `getoptions` function.
### Code Required For Get Option Function
### A Portion of Code Required For Get Option Function
[00:06:27](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m27s)
The `getoptions` function or method is requiring this chunk of code. Now instead of making it that you need to write out this whole thing. [00:06:45](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMREs&t=00h06m45s) In JCB you are just adding this part for the 'List'. For the 'radio' it is also just the `getoptions`. For the 'Checkboxes' again also just `getoptions`. So it is basically the only code we need to have it's only with the user one [00:07:08](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m08s) which we have a `getgroups` and `getexclude`. And if you select 'Custom user', that is exactly what you get, you get 'getexclude' area and you get 'getgroup' area and these two chunks of code is what is going to be placed [00:07:36](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m36s) in this area here. That is what is going to happen. So you could at any time come in here and fiddle around with this, I mean in the PHP when the file is created. Like over here, I've got this 'Preacher' open. You can come in here and fiddle with us and then take your changes just back to the view to JCB and just place it in a Custom. That means that the type is movable because it is new but it must be something that doesn't already exist in Joomla.
The `getoptions` function or method is requiring this chunk of code. Now instead of making it that you need to write out this whole thing. [00:06:45](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMREs&t=00h06m45s) In JCB you are just adding this part for the 'List'. For the 'radio' it is also just the `getoptions`. For the 'Checkboxes' again also just `getoptions`. So it is basically the only code we need to have. It is only with the user one [00:07:08](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m08s) that we have a `getgroups` and `getexclude`. And if you select 'Custom user', that is exactly what you get, you get 'getexclude' area and you get 'getgroup' area and these two chunks of code is what is going to be placed [00:07:36](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m36s) in this area. That is what is going to happen. So you could at any time come in here and fiddle around with this, I mean in the PHP when the file is created. Like over here, I've got this 'Preacher' open. You can come in here and fiddle with it and then take your changes back to the view in JCB and just place it in Custom. That means that the type is movable because it is new but it must be something that doesn't already exist in Joomla.
### Where To Find A List Of All Joomla's Field Types
[00:08:19](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m19s)
If you don't know what all the field types are that exist in Joomla then a good place to start is to go to Field Types and check out all these and if that is still not clear you can go to this URL. This has a list of all Joomla's field types so you could [00:08:43](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m43s) open that, scroll down and here is a list of all the field type names that you can't use again. It will be conflicting because it will break that name in that form. Do not use names that are not used by Joomla.
If you don't know what all the field types are that exist in Joomla then a good place to start is to go to Field Types and check out all these and if that is still not clear you can go to this URL. This has a list of all Joomla's field types so you could [00:08:43](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m43s) open that, scroll down and here is a list of all the field type names that you can not use again. It will be conflicting because it will break that name in that form. Do not use names that are not used by Joomla.>>>>>>>>
**Going back to create a Custom Field.** [00:09:12](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m12s) We could start with Sermon Preacher which is the one we are looking at. So again the name up here is just for the interface for you, it's just that you can see what is the field. You can call this anything. It only falls back to this name if there isn't a label set here, then it will fall back to this name. [00:09:39](https://www.youtube.com/watch?v=91iIAuHZj38&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m39s) But the ideal is just set the label.