From c3f9759f87d4230ba3865f187a70068f3f7ec15e Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Wed, 30 Oct 2019 06:01:30 +0200 Subject: [PATCH] Updated 074 How to add Joomla Custom Fields (markdown) --- 074-How-to-add-Joomla-Custom-Fields.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/074-How-to-add-Joomla-Custom-Fields.md b/074-How-to-add-Joomla-Custom-Fields.md index b43f01b..8e50d25 100644 --- a/074-How-to-add-Joomla-Custom-Fields.md +++ b/074-How-to-add-Joomla-Custom-Fields.md @@ -41,8 +41,25 @@ Let me first show you the code, how it looks. In the component root folder, I'm [00:09:51](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=75&t=0s&t=00h09m51s) -You could be building a plugin that is targeting Look and not Looking. If you want to change the context of this specific event that has been passed over. To do that we've also added a Context [00:10:12](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m12s) Field in the Site View. Your Site View can change its Context. Let me show you. We'll open the Site Views, in the Site Views we have that view called Looking. We can open that and we have a new Field called Context. We have Looking selected as our Dynamic Get. Here we can set the Context [00:10:38](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m38s) to suit the Dynamic Get and not fall back to the main code. If you don't add this Context, it will fall back to this code name. But you could say I want the Context to be Look and not Looking, then save and close. If we compile this again, it will update the Contexts of that specific event. Any other event related to that [00:11:06](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m06s) Get, that is really what you want. You'll see it's changed it to Look. So it's still pass the component's name, but the correct context in relation to your event. What's going to happen? Why we want this to be Look? It's because the fields are linked to the [00:11:36](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m36s) Look Admin View. It is stored in the database under Look Context and not under the Context of Looking. You are having both here on the front. So you couldn't use the name and Look again. You have to use another name. The way to have that same Context called on your title, is to change it like I've just done. I know that's a lot of explanation. Maybe some of you don't even understand [00:12:10](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m10s) what I've just said but those who do will know, this is nice, you can change the Context through the Site View, that you could have the same Context be triggered multiple times as you would have it. It's a little bit of a tweak at the moment. We might bring more automation in, but I know it is a little liberating. You could [00:12:34](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m34s) really be free how you want to do this. But what is going to happen? These events are being triggered and the values are being stored here(see video). So whatever gets thrown back from the plugins, gets placed into this value here(see video). The only custom code that you need to do after fixing up the events being added to the Dynamic Get, updating the Context to target the corrected [00:13:04](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m04s) view. I'll show you once again. Why do I want this to be Look? If we go to our Admin View, we'll see if you open Looks and click The Name, you will see at the top, [00:13:24](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m24s) it says Demo and the View is Look. The Context of these fields are linked to that 'com_demo' value and that 'look' value. 'com_demo' is always going to be correct. +You could be building a plugin that is targeting Look and not Looking. If you want to change the context of this specific event that has been passed over. To do that we've also added a Context [00:10:12](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m12s) Field in the Site View. Your Site View can change its Context. Let me show you. We'll open the Site Views, in the Site Views we have that view called Looking. We can open that and we have a new Field called Context. We have Looking selected as our Dynamic Get. Here we can set the Context [00:10:38](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m38s) to suit the Dynamic Get and not fall back to the main code. If you don't add this Context, it will fall back to this code name. But you could say I want the Context to be Look and not Looking, then save and close. If we compile this again, it will update the Contexts of that specific event. Any other event related to that [00:11:06](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m06s) Get, that is really what you want. You'll see it's changed it to Look. So it's still pass the component's name, but the correct context in relation to your event. -???? +### What Is Going To Happen? -But this one could be different And so you need to in your site view make sure that your targeting The correct [00:13:47](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m47s) Context of where these fields are So you be passing basically the ID And this context and Joomla will automatically retrieve the values of this fields And place those values For you Inside of this Object here or actually It will create a string as you see you here it implodes the array Into string And places it in here [00:14:13](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m13s) So all you now would need to do Is basically echo out Those values in any way you want them to look So you could Yeah you could add it in some diff tags And I'll show you that in a moment So for now All I wanted to explain is how these events Actually get the Field values on the page [00:14:37](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m37s) So those field values are Loaded into these values respectively of its switches Which I showed you earlier in setting up the field Now the Joomla web site currently is not set up to show the looks So we gonna go to the menu And change that Going to main menu And I'm going to click here on home And I'm gonna select Let's see where is a demo [00:15:09](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m09s) Looks And Yeah that's basically it And gonna save and close out of that So now we have looks On the The page The default page of the website If we click here it should load And there it is the name [00:15:29](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m29s) To see a list of looks and here's the name if you click on that It shows us the name And it shows as there's been one head and if we refresh that it shows two heads So That all works well But our custom values which we have submitted Is not showing up So This value is showing up and even we could add some [00:15:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m55s) Description And This is Also going to show up if we refresh the page here there's the description and we click here there is the description So all that is showing up but the real easy values are not showing up And we want them to also be showing up on the page And That's what we are going to do For them By Simply using those [00:16:28](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m28s) Event Objects So over here we have The Content after display content before display and content after title Now If you forget How to use this or how to place this The component that you can go to his this content [00:16:51](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m51s) Component And you can also open it's Article View And you would see something very similar scroll down down down here You see something well unless they've changed it by the time But at this time The default of Joomla's implementation is very much the same So it's also triggering the content and it's also placing it into these values which means that That if you go to it's template [00:17:19](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m19s) Default PHP You will see Places basically you could search for it so you could take this After title Copy that Come over here And place it in there and here you see Basically The content is generated by the content plugin event on And it basically just Echoes it out [00:17:44](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m44s) So you could use this code just like that copy paste it into your component After the title And the same goes with the other events So with the before display and after display So let me do that quickly I'm gonna just grab these and place them into our component So I've just copied them to a notepad like that I'm gonna move them to my other screen And then I'm gonna go back to to JCB And Go to my component The site view of a component [00:18:23](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m23s) And I'm going to open looking And in the component We have a whole lot of things happening here Basically we have a article Comment here And over here is the title So we want We want that Value [00:18:47](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m47s) To actually echo out After the title So We gonna take That first one Which is the event after the title I'm gonna place it Between the header and this diff Here So [00:19:05](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m05s) Basically There So that the content is generated by there and it's on content after title so this is the title And then when is gonna show over here Then we have another one on content before display Have the content before display I would like to think it needs to go first before anything So I wanna put that there On before anything displays That's way at the top [00:19:39](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m39s) And with content after display I wanna put that obviously at the very end Below everything So that's quite simple We could do more we could wrap it in a diff we could Do all kinds of styles to it But that's the simplest way and I'm just gonna demonstrate that Save and close here And then basically compile it again Install [00:20:08](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m08s) And now let's go refresh that page Oops I got some errors here I realized I'm using slightly different names then The ones I copied from the content You know the article area Content area let me show you that So They are saying up here in the comment on content before display and here it's before display content [00:20:35](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m35s) it's like a little bit Different So I'm using exactly the same So just Heads Up Use the the same as What is here in a comment And that's little me that always trying to Keep everything the same [00:20:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m55s) We save that it should work now So here we go simple Fields input value more fields with more input There are those values displayed on the front So if we go back here We can close this out Go back to the fields and let's say with a more fields You wanna change that to display after the title Save And then go back to the front and refresh this So now the one is up here and the other one is after the title [00:21:28](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m28s) So let's say we want simple field to actually show at the very end of our value go out of more Fields into simple field I will change that to you know After display Save and close So you could move the values Position Simply and everyone will move now you see that simple Field is below everything [00:21:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m55s) And if you realise This whole area here is the block So that's how the custom Fields can come to the front you can also say you know I don't want this Area to show up And you can go to To the field simple field And you could say show label hide label And save And now if you refresh it will only give you the value So [00:22:20](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h22m20s) That's the kind of behavioral integration So that's a quick demonstration Of how to now use Joomla custom fields in your components And how to then Model those values into the front end By Simply making use of the events And Wow have fun I'm sure this will Make things even more interesting Thanks for watching \ No newline at end of file +[00:11:20](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m20s) + +What's going to happen? Why we want this to be Look? It's because the fields are linked to the Look Admin View. It is stored in the database under Look Context and not under the Context of Looking. You are having both here on the front. So you couldn't use the name and Look again. You have to use another name. The way to have that same Context called on your title, is to change it like I've just done. I know that's a lot of explanation. Maybe some of you don't even understand [00:12:10](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m10s) what I've just said but those who do will know, this is nice, you can change the Context through the Site View, that you could have the same Context be triggered multiple times as you would have it. It's a little bit of a tweak at the moment. We might bring more automation in, but I know it is a little liberating. You could [00:12:34](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m34s) really be free how you want to do this. But what is going to happen? These events are being triggered and the values are being stored here(see video). Whatever gets thrown back from the plugins, gets placed into this value here(see video). The only custom code that you need to do after fixing up the events being added to the Dynamic Get, updating the Context to target the corrected [00:13:04](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m04s) view. I'll show you once again. Why do I want this to be Look? If we go to our Admin View, we'll see if you open Looks and click The Name, you will see at the top, [00:13:24](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m24s) it says Demo and the View is Look. The Context of these fields(Simple and More Fields) are linked to that 'com_demo' value and that 'look' value. 'com_demo' is always going to be correct. But 'look' could be different and you will need to in your Site View make sure that you are targeting the correct Context of where these fields are. + +### Passing The ID And Context - Joomla Automatically Retrieve The Values - Place Values Inside The String + +[00:13:50](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m50s) + +You will be passing the ID and the Context and Joomla will automatically retrieve the values of this fields and place those values for you inside of the object or it will create a string as you will see. It implodes the array into the string and places it in here(see video). [00:14:13](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m13s) All you will need to do is echo out those values in any way you want them to look. You could add it in some diff tags. I'll show you that in a moment. All I wanted to explain is how these events get the field values on the page. [00:14:37](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m37s) Those field values are loaded into these values respectively of its switches which I showed you earlier in setting up the field. + +### Joomla Website Not Setup To Show Looks - Change It - Demo - Looks + +[00:14:50](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m50s) + +The Joomla web site currently is not setup to show the Looks. We are going to go to the menu and change that. Go to main menu and I'm going to click on Home. Select Demo, Looks. Save and close. We have Looks on the default page of the website. If we click Joomla Mount it should load and there is The Name. [00:15:29](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m29s) + +??? +To see a list of looks and here's the name if you click on that It shows us the name And it shows as there's been one head and if we refresh that it shows two heads So That all works well But our custom values which we have submitted Is not showing up So This value is showing up and even we could add some [00:15:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m55s) Description And This is Also going to show up if we refresh the page here there's the description and we click here there is the description So all that is showing up but the real easy values are not showing up And we want them to also be showing up on the page And That's what we are going to do For them By Simply using those [00:16:28](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m28s) Event Objects So over here we have The Content after display content before display and content after title Now If you forget How to use this or how to place this The component that you can go to his this content [00:16:51](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m51s) Component And you can also open it's Article View And you would see something very similar scroll down down down here You see something well unless they've changed it by the time But at this time The default of Joomla's implementation is very much the same So it's also triggering the content and it's also placing it into these values which means that That if you go to it's template [00:17:19](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m19s) Default PHP You will see Places basically you could search for it so you could take this After title Copy that Come over here And place it in there and here you see Basically The content is generated by the content plugin event on And it basically just Echoes it out [00:17:44](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m44s) So you could use this code just like that copy paste it into your component After the title And the same goes with the other events So with the before display and after display So let me do that quickly I'm gonna just grab these and place them into our component So I've just copied them to a notepad like that I'm gonna move them to my other screen And then I'm gonna go back to to JCB And Go to my component The site view of a component [00:18:23](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m23s) And I'm going to open looking And in the component We have a whole lot of things happening here Basically we have a article Comment here And over here is the title So we want We want that Value [00:18:47](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m47s) To actually echo out After the title So We gonna take That first one Which is the event after the title I'm gonna place it Between the header and this diff Here So [00:19:05](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m05s) Basically There So that the content is generated by there and it's on content after title so this is the title And then when is gonna show over here Then we have another one on content before display Have the content before display I would like to think it needs to go first before anything So I wanna put that there On before anything displays That's way at the top [00:19:39](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m39s) And with content after display I wanna put that obviously at the very end Below everything So that's quite simple We could do more we could wrap it in a diff we could Do all kinds of styles to it But that's the simplest way and I'm just gonna demonstrate that Save and close here And then basically compile it again Install [00:20:08](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m08s) And now let's go refresh that page Oops I got some errors here I realized I'm using slightly different names then The ones I copied from the content You know the article area Content area let me show you that So They are saying up here in the comment on content before display and here it's before display content [00:20:35](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m35s) it's like a little bit Different So I'm using exactly the same So just Heads Up Use the the same as What is here in a comment And that's little me that always trying to Keep everything the same [00:20:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m55s) We save that it should work now So here we go simple Fields input value more fields with more input There are those values displayed on the front So if we go back here We can close this out Go back to the fields and let's say with a more fields You wanna change that to display after the title Save And then go back to the front and refresh this So now the one is up here and the other one is after the title [00:21:28](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m28s) So let's say we want simple field to actually show at the very end of our value go out of more Fields into simple field I will change that to you know After display Save and close So you could move the values Position Simply and everyone will move now you see that simple Field is below everything [00:21:55](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m55s) And if you realise This whole area here is the block So that's how the custom Fields can come to the front you can also say you know I don't want this Area to show up And you can go to To the field simple field And you could say show label hide label And save And now if you refresh it will only give you the value So [00:22:20](https://www.youtube.com/watch?v=n5RBmP0uNCM&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h22m20s) That's the kind of behavioral integration So that's a quick demonstration Of how to now use Joomla custom fields in your components And how to then Model those values into the front end By Simply making use of the events And Wow have fun I'm sure this will Make things even more interesting Thanks for watching \ No newline at end of file