How to create or customize a content manager
What's a content manager?
A content manager is a PHP class that produces the administrative interface for editing Reason entities. While a Reason type will default to using a basic content manager that builds the form based on MySQL field definitions, a type's editing interface can be altered by assigning it a custom content manager. Technically, content managers are extensions of reason_disco, which is itself an extension of the Disco form management class. Therefore, content managers are Disco classes with some added mojo the that ties them in to Reason.
Where do content managers live?
All Reason content managers live in reason_package/reason_4.0/lib/[core|local]/content_managers/. The ones you create will be in the local directory, so as to keep core and local code separate.
I want to modify the interface for a Reason type. How do I do that using a content manager?
If the Reason type has a custom content manager, you will likely want to extend that class with your customizations. Here's how to do that:
1. On a development instance of Reason, create a new file in reason_package/reason_4.0/lib/local/content_managers/. Name the file with your organization's name and the name of the type that the content manager is intended to be used with -- if you work at XYZ Corp and this is for the Quote type, you might call the file quote_xyz.php. This will keep the filename from conflicting with core content managers.
2. Identify the core content manager used for the type, and... and extend it in this file.
// include its file
reason_include_once( 'content_managers/quote.php' );
// Register your new content manager with Reason -- put the name of your class here
$GLOBALS[ '_content_manager_class_names' ][ basename( __FILE__) ] = 'XYZQuoteManager';
// Define the class
class XYZQuoteManager extends QuoteManager
3. Modify the class to behave in the manner you desire.
You can use any of Disco's functionality here. You can refer to the core content managers if you want to see how they do things, but here is a intro to the basic modification features:
Content managers have an additional method that is intended to be used for extension, called alter_data. So, for example, if you want to change a form element, you might call the parent class's alter_data() method and then procedd to overlay your customizations on top of the existing interface, like so:
You can also add or change validation rules with the run_error_checks() method:
/* Using the line lays your error checks on top of the any others already done. If you want to replace the error checks in the parent class entirely, leave this line out.*/
if(strpos($this->get_value('author'),'Michael ') !== 0)
$this->set_error('Authors may only be named Michael');
Finally, you can have Reason do additional actions upon successful save, using the process() method:
// Anything you want to happen before the changes are saved is put here
//Anything you want to happen after changes are saved is put here
4. Now that you have set up your class, you need to tell Reason to use it. Go into the Master Admin for your development instance and edit the type in question. The "Conent Manager" field should now display the file in its dropdown selector; choose it (in this case it would be listed as "Quote Xyz") and Save & Finish.
5. You should now be able to go into the type and test the changes you have made. You can now continue to edit the content manager until you have achieved the result you want. Once you are happy, move the file to your production instance of Reason and repeat step #4 in production.
What if the type I want to customize doesn't have a content manager?
If you want to create content manager for a type that does not yet have one, just extend the default content manager. The only difference is that you will need to include default.php3 and extend the class "ContentManager".