Table of Contents Previous Next

Sugar Developer Guide

Version 5.1


Chapter 4 Customizing Sugar : User Interface Customizations : Creating a Custom SugarField

Creating a Custom SugarField
Let's try to create a new type of field for rendering a YouTube video. In this example, we will use a custom text field in the Contacts module and then override the DetailView of the custom field in the metadata file to link to our YouTube video. Here are the steps:
1)
2)
3)
4)
Create a directory include/SugarFields/Fields/YouTube. The name of the directory (YouTube) corresponds to the name of the field type you are creating.
5)
In include/SugarFields/Fields/YouTube directory, create the file DetailView.tpl. For the DetailView we will use the "embed" tag to display the video. In order to do this we need to add in the template file:
{if !empty({{sugarvar key='value' string=true}})}
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/{{sugarvar key='value'}}></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/{{sugarvar key='value'}}" type="application/x-shockwave-flash"
wmode="transparent" width="425" height="350">
</embed>
</object>
{/if}

You will notice that we use the "{{" and “}}” double brackets around our variables. This implies that that section should be evaluated when we are creating the cache file. Remember that Smarty is used to generate the cached templates so we need the double brackets to distinguish between the stage for generating the template file and the stage for processing the runtime view.
Also note that will use the default EditView implementation that is provided by the base sugar field. This will give us a text field where people can input the YouTube video id so you do not need to create EditView.tpl. Also, we do not need to provide a PHP file to handle the SugarField processing since the defaults will suffice.
6)
 
array (
'name' => 'youtube_c',
'type' => 'YouTube',
'label' => 'LBL_YOUTUBE',
),
 
Your custom field is now ready to be displayed. You can now find an id value of a YouTube video to insert into the EditView and render the video content in the DetailView! Remember to set your system to Developer Mode or delete the EditView.tpl or DetailView.tpl files in the cache/modules/Contacts directory.

Table of Contents Previous Next

Copyright 2004-2008 SugarCRM Inc.
Product License