Updated 008 Advanced Fields (markdown)

Amigo 2019-05-31 08:22:12 +02:00
parent 7abcedf606
commit 93eccf736b

@ -1,14 +1,21 @@
# ADVANCED FIELDS
Hi we've just finished with admin views and we would like to start looking at advanced field types. There are a few advanced field types and the one that is most advanced, is the one called custom field type. I'm going to sort this here by custom fields. It's that one(custom). And you will see in a moment we have quite a few custom fields in place. [00:00:32](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m32s)
There are a few advanced field types and the one that is most advanced, is the one called custom field type. Sorting it by custom fields, you will see that we have quite a few custom fields in place. [00:00:32](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m32s)
**Local File List Example**
Now let's look at two of those. One is the local(file list), the other one is the sermon one. But let's first look at the local(file list). You'd see that from there(XML field definition). All the way down to there is simply PHP. So I'm creating a view which is most basically. Taking information if you know PHP, from the global settings of your component so there need to be a field with a name 'localfolder' in your global settings. We will still look at how to set up global settings when we get to component. If it hasn't got a setting it falls back onto the image which is in the 'JPATH ROOT'. For your component this will be replaced with your component name. And it puts it into local folder. [00:01:36](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m36s)
Let us look at two of these. One is the local(file list), the other one is 'sermon'. But let us first look at the local(file list). You will see that the whole 'XML field definition' column is simply PHP. So I'm creating a view which is most basically taking information (if you know PHP), from the global settings of your component so there need to be a field with a name 'localfolder' in your global settings. We will look at how to set up global settings when we get to component. If it hasn't got a setting it falls back onto the image which is in the 'JPATH ROOT'. For your component this will be replaced with your component name. And it puts it into local folder. [00:01:36](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m36s)
Then I just start the options array, which you going to return. The first thing I add to it is select 'Please add files'. If there isn't files it will say 'Please add files' to, and it will give the local folder name. If there is files we going to update those then over here(JFolder). So first we bring in the file system classes from Joomla then we basically check whether that folder exists. If it doesn't exist we create it just in the field type. Now once it's created and if it exists it obviously skips this(see video) doesn't go in there and it just starts by grabbing all the files and from that folder and place it into files. And then starts up an array [00:02:40](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m40s) where it loops the files and put it into options. By doing that we are basically, let me just check here and make sure. We're adding the file name and the file name to our options array. Then returning the options array. So you can add your own custom PHP scripting when you extend a list field. We are extending list field. So it's just going to be a drop down list of all the files in that specific folder. Either images or the folder that it was set globally in local folder. OK so that is just setting up a folder.
Then I just start the options array, which you going to return. The first thing I add to it is select 'Please add files'. If there isn't files it will say 'Please add files' to, and it will give the local folder name. If there is files we are going to update those at 'JFolder'. So first we bring in the file system classes from Joomla, then we check whether that folder exists. If it doesn't exist we create it just in the field type. Now once it's created and if it exists it obviously skips this(see video)it doesn't go in there and it just starts by grabbing all the files from that folder and place it into files and then starts up an array [00:02:40](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m40s) where it loops the files and put it into options. By doing that we are adding the file name($file) and the file name($file) to our options array. Then returning the options array. So you can add your own custom PHP scripting when you extend a list field. We are extending list field. So it is just going to be a drop down list of all the files in that specific folder. Either images or the folder that it was set globally in local folder. So this is just setting up a folder.
Now there is a field type called file list. The reason why I didn't use file list is because file list has a static directory to where [00:03:44](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) you need to add the files, so that you can view them. We wanted to have it be able to rename the folder for the files, for the media, to anything and then have it update itself automatically. That is why we then created a custom field where we extended the list type, and let me just refreshed this to get that detail back. So we chose a custom field and then we just extend the list type, and we don't want it to have add new button because it won't work, it will just break. We are allowing them to select multiple. Now since we are using multiple we need to go back and make sure that we are storing it as a 'JSON'. So the 'JSON' is when have multiple or arrays, any kind of arrays in a value you need to store it as a 'JSON'. [00:04:48](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m48s) The component builder itself will check if the multiple selection is true, it will automatically store it in a 'JSON' object. Even if you forgot to select 'JSON'. We have got some things in place to ensure that the system behaves as expected. Just a quick view on doing a local file custom field as a local file. Now which I'm sure you all have been waiting for is.
Now there is a field type called 'file list'. The reason why I didn't use file list is because file list has a static directory to where [00:03:44](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m44s) you need to add the files, so that you can view them. We want it to be able to rename the folder for the files, for the media, to anything and then have it update itself automatically. That is why we then created a custom field where we extended the list type, and let me just refreshed this to get that detail back. So we chose a custom field and then we just extend the list type, and we don't want it to add 'new button' because it won't work, it will just break. We are allowing them to select multiple. Now since we are using multiple we need to go back and make sure that we are storing it as a 'JSON'. So the 'JSON' is when you have 'multiple' or 'arrays', or any kind of arrays in a value, that needs to be stored as a 'JSON'. [00:04:48](https://www.youtube.com/watch?v=VpzYbifqv0M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m48s) The component builder itself will check if the multiple selection is true, it will automatically store it in a 'JSON' object even if you forget to select 'JSON'. There are things in place to ensure that the system behaves as expected.
**Sermon Preacher Custom Field**