Customize the contact summary screen.
Have you ever wanted to rearrange the contact summary screen? Move the most important information to the top? Remove unnecessary stuff? Create a simplified layout for your volunteers and interns but a more robust layout for your fundraising team? This extension will let you do just that.
This extension provides hook_civicrm_contactSummaryBlocks
to allow other extensions to supply blocks for the layout editor.
It also provides an api (v3 and v4 compatible) to facilitate managing summary layouts.
Hook example:
/**
* Implements hook_civicrm_contactSummaryBlocks().
*
* @link https://github.com/civicrm/org.civicrm.contactlayout
*/
function example_civicrm_contactSummaryBlocks(&$blocks) {
// Register our block with the layout editor.
$blocks['core']['blocks']['example_block'] = [
'title' => ts('Example Block'),
'tpl_file' => 'CRM/Example/ExampleBlock.tpl',
'sample' => [ts('Example field'), ts('Another example field')],
'edit' => FALSE,
'foo' => 'bar', // add any data you want passed to ExampleBlock.tpl
];
}
To display the block your extension needs to provide a smarty template (declare path relative to your extensions' templates
directory per tpl_file
in the example above).
The template will receive {$contactId}
and {$block}
as available variables (in the example above ,{$block.foo == 'bar'}
, which may be sufficient for your block to call the smary api and fetch whatever data you need.
If your block needs additional preprocessing in PHP, you'll need to use hook_civicrm_pageRun to assign more data to the contact summary page (all data assigned to that page is available to every block template).
For a fully editable block you'll also need:
CRM_Example_Form_Inline_Example
and a corresponding smarty template.CRM_Example_Page_Inline_Example
which assigns variables for your tpl when the block reloads the view from ajax.You can optionally use a region hook to inject the template onto the summary screen if you want your block to work even without this extension.
For a working example of how to do all of the above, see the relationship block extension,
which works well on its own; the only addition needed to add its block to the editor palette was implementing hook_civicrm_contactSummaryBlocks
.
This extension licensed under AGPL-3.0.