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!