HelloWorld - part 6 addons

From EPESI framework documentation
Jump to: navigation, search


Addons are used to view relations between records in certain modules. For instance if you want to add a HelloWorld addon to companies you must first create a new addon in HelloWorldInstall.php. Addons by default are sorted in alphabetical order. This can be changed via admin GUI (Record Browser). Page split (or splits) are always first as they are part of the main record.

Install

Utils_RecordBrowserCommon::new_addon('company', $this->get_type(), 'company_addon',
array($this->get_type() . 'Common', 'company_addon_label'));

Do so By using the code above in the install() function. The first parameter, company in this case is the record in the recordset we want to create the addon for (i.e. for Contacts it will be contact). $this->get_type() is an instance of this module (it holds HelloWorld string). company_addon is the name of the addons main fuction used in HelloWorld_0.php. We will get to that later. The last parameter is the label of the addons tab that will be viewed in company module. Remember to reinstall your module afterwards.

label

So now that the addon is created we want to be able to see it. To do so go into HelloWorldCommon_0.php and add this function.

 public static function company_addon_label() {
     return array('label' => __('HelloWorldaddon'), 'show' => true);
 }

Where HelloWorldaddon is the name of your tab.

functionality

Set the functionality of your module addon in the modules main file HelloWorld_0.php.

  public function company_addon($record) {
    print $record['company_name'];
        
    }

The $record argument is an array of all the fields in the certain recordset it is added to. Now navigate to Menu->CRM->Companies and view any company. Click the HelloWorldaddon tab. The output of this addon will be the companies name.

Addon.png

Now to show only helloworld recorsets that have the same value in text field as the string containing the companies name you must set the criticals. Swap the code below with the current code in company_addon funciton.

 public function company_addon($record) {

        $rs = new Custom_HelloWorld_Recordset();
        $this->rb = $rs->create_rb_module($this);

        $crits = array('text' => $record['company_name']); //set relations between fields 
        $cols = array('text' => true); // set false if you do not want the field to be visible in header
        $show_data_params = array($crits, $cols);

        $this->display_module($this->rb, $show_data_params, 'show_data');
 }

It's best practice to create a function that creates a Recordset.

 public function company_addon($record) {
        $this->init_default_rb();

        $crits = array('text' => $record['company_name']); 
        $cols = array('text' => true); /
        $show_data_params = array($crits, $cols);

        $this->display_module($this->rb, $show_data_params, 'show_data');
 }
 private function init_default_rb() {
        $rs = new Custom_HelloWorld_Recordset();
        $this->rb = $rs->create_rb_module($this);
 }


To test if this works create a new record in HelloWorld and set the Text field to a companies name that you have listed in Menu->CRM->Comapnies (if you do not have any create a test company) . After you have done so check if the record is listed in the HelloWorldaddon tab in the companies view if so, you have done everything correctly.

Addon2.png


Download: Get full tutorial here


NEXT >