SugarCRM 7 — Custom subpanels
This tutorial should hopefully help you to create a new subpanel under the Contacts module in Sugar using a custom link class and driven by SugarCRM 7’s new SugarQuery API. 1. Create a new link class This should go into custom/modules//YourNewLink.php and this class will act as the custom functionality that will build your link between the two records. /** * Custom filtered link */ class YourNewLink extends Link2 { /** * DB * * @var DBManager */ protected $db; public function __construct($linkName, $bean, $linkDef = false) { $this->focus = $bean; $this->name = $linkName; $this->db = DBManagerFactory::getInstance(); if (empty($linkDef)) { $this->def = $bean->field_defs[$linkName]; } else { $this->def = $linkDef; } } /** * Returns false if no relationship was found for this link * * @return bool */ public function loadedSuccesfully() { // this link always loads successfully return true; } /** * @see Link2::getRelatedModuleName() */ public function getRelatedModuleName() { return ''; } /** * * @see Link2::buildJoinSugarQuery() */ public function buildJoinSugarQuery($sugar_query, $options = array()) { $joinParams = array('joinType' => isset($options['joinType']) ? $options['joinType'] : 'INNER'); $jta = 'active_other_invites'; if (!empty($options['joinTableAlias'])) { $jta = $joinParams['alias'] = $options['joinTableAlias']; } $sugar_query->joinRaw($this->getCustomJoin($options), $joinParams); return $sugar_query->join[$jta]; } /** * Builds main join subpanel * @param string $params * @return string JOIN clause */ protected function getCustomJoin($params = array()) { $bean_id = $this->db->quoted($this->focus->id); $sql = " INNER JOIN("; $sql .= "SELECT id FROM accounts WHERE id={$bean_id}"; // This is essentially a select statement that will return a set of ids that you can match with the existing sugar_query $sql .= ") accounts_result ON accounts_result.id = sugar_query_table.id"; return $sql; } } The argument $sugar_query is a new SugarQuery object, the details of which are documented here. What you essentially need to do is extend this query with whatever join/filters you wish to add. This is done in the inner join I’ve specified. ...