Monday, 22 September 2014

Add field in subpanel through Manifest in SugarCRM7.

Today I came across the requirement in which I have to add the field in subpanel using manifest.

I have "Student" module which is related with the "Subject" module. Subject subpanel is displayed under the "Student" module. I have requirement to add field in "Subject" subpanel through Manifest.

(1) Write the following code into post_install.php.
  function post_install()
  {
    require_once('modules/ModuleBuilder/parsers/ParserFactory.php');

    //Define all the fields for subpanel
    $addFieldsToSubpanel = array(
         'subject_short_code' => array(
            'name' => 'subject_short_code',
            'label' => 'LBL_SUBJECT_SHORT_CODE',
            'enabled' => true,
            'default' => true,
            ),
    );

    $subpanelLayoutFields = array();
    //Loop through all the fields we want to add in subpanel
    foreach ($addFieldsToSubpanel as $key => $field) {
        $subpanelLayoutFields[$key] = $field;
    }
    addField2Subpanel('UT_Student','ut_student_ut_subject',$subpanelLayoutFields);
  }

  /**
   * This function add field into subpanel.
   * @param string $parentModule. Name of the module in which subpanel exist.
   * @param string $subpanelName. Name of the relationship field.
   * @param array $layoutFields. Array of the field(s) defination to include in subpanel.
   * @param string $view. Name of the view, by default it is "listview".
   * @save field in subpanel.
  */
  function addField2Subpanel($parentModule,$subpanelName,$layoutFields,$view='listview')
  {
       echo "Updating subpanel $subpanelName under the $parentModule module.";
       $parser = ParserFactory::getParser($view, $parentModule, null, $subpanelName);

       if (!$parser) {
          $GLOBALS['log']->fatal("No parser found for $module | $view");
       }

       foreach ($layoutFields as $field => $field_def) {
          $parser->_viewdefs['panels'][0]['fields'][] = $field_def;
          echo ("$field field added to $subpanelName subpanel under the $parentModule module.");
       }

       $parser->handleSave(false);
  }


(2) Do "Quick Repair & Rebuild" from admin.
Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My Photo
SugarCRM Consultants Contact us at contact@urdhva-tech.com Skype : urdhvatech

Search This Blog

Loading...

Stay connected Socially

     

Total Pageviews

Popular Posts