Merge pull request #14928 from lcdservices/dev-core-1158
[civicrm-core.git] / CRM / Core / Smarty / plugins / function.crmCrudLink.php
CommitLineData
5f292f80
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
5f292f80 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
5f292f80 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
5f292f80
TO
11
12/**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC
16 * $Id$
17 *
18 */
19
20/**
21 * Dynamically construct a link based on an entity-type and entity-id.
22 *
16b10e64
CW
23 * @param array $params
24 * Array with keys:
25 * - table: string
26 * - id: int
27 * - action: string, 'VIEW' or 'UPDATE' [default: VIEW]
28 * - title: string [optionally override default title]
29 * @param CRM_Core_Smarty $smarty
5f292f80
TO
30 *
31 * @return string
32 */
33function smarty_function_crmCrudLink($params, &$smarty) {
34 if (empty($params['action'])) {
35 $params['action'] = 'VIEW';
36 }
37
be2fb01f 38 $link = CRM_Utils_System::createDefaultCrudLink([
5f292f80
TO
39 'action' => constant('CRM_Core_Action::' . $params['action']),
40 'entity_table' => $params['table'],
41 'entity_id' => $params['id'],
be2fb01f 42 ]);
5f292f80
TO
43
44 if ($link) {
45 return sprintf('<a href="%s">%s</a>',
46 htmlspecialchars($link['url']),
47 htmlspecialchars(CRM_Utils_Array::value('title', $params, $link['title']))
48 );
49 }
50 else {
51 return sprintf('[%s, %s]', $params['table'], $params['id']);
52 }
53}