0

I have created a custom search based on relationships. Each row shows a contact and a related organisation in separate columns as well as other info. Each contact is automatically linked to the view page in the search results but I would like the organisation to also be linked. I return a column aliased to "org_id" in the all function select piece.

, tempTable.org_id
, tempTable.organization_name

I have not added org_id to my columns array in the constructor because I do not want it to display. If I do then the template file works but I have an extra column.

I have sucessfully overridden the template file as follows:

{if $fName eq 'sort_name'}
   <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`&context=custom"}">{$row.sort_name}</a></td>
{elseif $fName eq 'organization_name'}
   <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.org_id`&key=`$qfKey`&context=custom"}">{$row.organization_name}</a></td>
{else}
   <td>{$row.$fName}</td>
{/if}

It does display a link on the organisation name cell. However the template is not seeing the org_id value and the link stops at cid= EG. civicrm/contact/view?reset=1&cid=&key=fb7ffdb351588d7d7d9df84f3b3e03f5_1119&context=custom

Edit: I have also tried this without the template override and used alterRow. This also only works if the org_id result column is added to the columns list of the custom search.

  function alterRow( &$row ) {
    $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$row['org_id']}");
    $row['organization_name'] = "<a href=\"{$url}\">{$row['organization_name']}</a>";
  }
2

OK. I figured it out eventually. This is how I got it to work. It seems a little wonky but it functions

  1. Add the column to the list of columns
  2. Override the template
  3. Alter the rows to add the link
  4. AND unset the column in Alter rows

The constructor columns must contain

  ts('Org id') => 'org_id',

The override

  public function templateFile() {
    return "CRM/Contact/Form/Search/Custom/mySearch.tpl";
  }

The template

Add snippets in each of the column headers section and the rows section skipping an item in the loop. Eg. {if $header.sort neq 'org_id'}

For the headers:

 {foreach from=$columnHeaders item=header}
    {if $header.sort neq 'org_id'}
      <th scope="col">
      {if $header.sort}
        {assign var='key' value=$header.sort}
        {$sort->_response.$key.link}
      {else}
          {$header.name}
      {/if}
     </th>
   {/if}
{/foreach}

For the rows:

{foreach from=$columnHeaders item=header}
   {assign var=fName value=$header.sort}
   {if $header.sort neq 'org_id'}
     {if $fName eq 'sort_name'}
       <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`&context=custom"}">{$row.sort_name}</a></td>
      {else}
        <td>{$row.$fName}</td>
      {/if}
   {/if}
{/foreach}

The alter rows

Note the added unset line.

function alterRow( &$row ) {
  $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$row['org_id']}");
  $row['organization_name'] = "<a href=\"{$url}\">{$row['organization_name']}</a>";
  unset($row['org_id']);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.