Custom code to pre-generated code #30

Closed
opened 2016-12-29 19:41:31 +00:00 by mwweb · 1 comment
mwweb commented 2016-12-29 19:41:31 +00:00 (Migrated from github.com)

Component Builder creates a lot of the code automatically. But, what would you need to do if you wanted to extend some of the code that is generated by component builder? For example, a piece of code that I need to get into the code in a particular area, in the site model:

$item->slug = (isset($item->alias)) ? $item->id.':'.$item->alias : $item->id;
This below needs to be a part of that array:

                        //get category image
                        $item->image = json_decode($item->params)->image;
                        $item->image_alt = json_decode($item->params)->image_alt;

Once generated, the array would need to look like:

			$item->slug = (isset($item->alias)) ? $item->id.':'.$item->alias : $item->id;
                        //get category image
                        $item->image = json_decode($item->params)->image;
                        $item->image_alt = json_decode($item->params)->image_alt;
Component Builder creates a lot of the code automatically. But, what would you need to do if you wanted to extend some of the code that is generated by component builder? For example, a piece of code that I need to get into the code in a particular area, in the site model: ` $item->slug = (isset($item->alias)) ? $item->id.':'.$item->alias : $item->id; ` This below needs to be a part of that array: ``` //get category image $item->image = json_decode($item->params)->image; $item->image_alt = json_decode($item->params)->image_alt; ``` Once generated, the array would need to look like: ``` $item->slug = (isset($item->alias)) ? $item->id.':'.$item->alias : $item->id; //get category image $item->image = json_decode($item->params)->image; $item->image_alt = json_decode($item->params)->image_alt; ```

The best way to do that in the admin-view, is in the tab called PHP there is a list of switches, look for Add PHP (getItem Method)

You will see it has a hint, that says:
// PHP Here that should run in the getItem Method (object) $item is where all values are

So you can do the following there:

if ([[[Component]]]Helper::checkObject($item) && isset($item->params) && [[[Component]]]Helper::checkJson($item->params))
{
	//get category image
        $item->image = json_decode($item->params)->image;
        $item->image_alt = json_decode($item->params)->image_alt;
}

Or in a site-view you will add the code to the dynamic get area (of the main-get) , so you open the dynamic get and look for the tab called Custom Script now depending if it is a list query or a get item the switch will be different.

list query => Add PHP (after getting the Items)
get item => Add PHP (after getting the Item)

You will see that the note shows the targeting variable name. Let me know if you still having trouble.

The best way to do that in the admin-view, is in the tab called `PHP` there is a list of switches, look for `Add PHP (getItem Method)` You will see it has a hint, that says: `// PHP Here that should run in the getItem Method (object) $item is where all values are` So you can do the following there: ``` if ([[[Component]]]Helper::checkObject($item) && isset($item->params) && [[[Component]]]Helper::checkJson($item->params)) { //get category image $item->image = json_decode($item->params)->image; $item->image_alt = json_decode($item->params)->image_alt; } ``` Or in a site-view you will add the code to the dynamic get area (of the main-get) , so you open the dynamic get and look for the tab called `Custom Script` now depending if it is a list query or a get item the switch will be different. `list query => Add PHP (after getting the Items)` `get item => Add PHP (after getting the Item)` You will see that the note shows the targeting variable name. Let me know if you still having trouble.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#30
No description provided.