Valentine's Vardef

bsoremsugar —  February 14, 2008 — 2 Comments

Heart 20080214121354 52954 In honor of Valentine’s Day:

Rose are red,
Violets are blue,
Don’t know about vardefs?
Then you’re probably screwed.

I love the concept of vardefs. Simply put, Vardefs is a multi-dimensional array in PHP for each module that contains the attributes, properties, and metadata about each field/column in the database. Each vardefs file is located in it’s parent module. Jacob and Ken and probably countless others have document this well on the wiki and in the forums.

So, how practical is the information? Well it comes up all of the time – people want to make stock fields required or audited that aren’t already that way. Here’s an example from the Contacts Module. The use case is that I want to make the birth date field in Contacts, required (in the change log). This comes to us from ./modules/Contacts/vardefs.php:

	'birthdate' =>
		array (
			'name' => 'birthdate',
			'vname' => 'LBL_BIRTHDATE',
			'massupdate' => false,
			'type' => 'date',
			'comment' => 'The birthdate of the contact',
			// Added below code to make it required
			'required' => true,
		),

That’s it, just refresh the page and it is now a required field subject to JS client-side validation.

Additionally you can add alter the db in the vardefs file as necessary. A quick “Rebuild Database” in Admin >> Repair >> Rebuild Database and away ya go!

Technorati Tags: , ,

2 responses to Valentine's Vardef

  1. 

    Hi Matt: I attended your Sugar Administration Fundamentals Class last year in Miami. Would you please send me an email so I can ask you a question regarding the upgrade from V4.5 to 5.00b?
    Thanks,
    Jaime Arcila

  2. 

    Hi Matt: I attended your Sugar Administration Fundamentals Class last year in Miami. Would you please send me an email so I can ask you a question regarding the upgrade from V4.5 to 5.00b?
    Thanks,
    Jaime Arcila

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s