*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
*/
class CRM_Core_Action {
* @param null $op
* @param null $objectName
* @param int $objectId
+ * @param string $iconMode
+ * - `text`: even if `icon` is set for a link, display the `name`
+ * - `icon`: display only the `icon` for each link if it's available, and
+ * don't tuck anything under "more >"
+ * - `both`: if `icon` is available, display it next to the `name` for each
+ * link
*
* @return string
* the html string
$enclosedAllInSingleUL = FALSE,
$op = NULL,
$objectName = NULL,
- $objectId = NULL
+ $objectId = NULL,
+ $iconMode = 'text'
) {
if (empty($links)) {
return NULL;
if (!$mask || !array_key_exists('bit', $link) || ($mask & $link['bit'])) {
$extra = isset($link['extra']) ? self::replace($link['extra'], $values) : NULL;
- $frontend = (isset($link['fe'])) ? TRUE : FALSE;
+ $frontend = isset($link['fe']);
if (isset($link['qs']) && !CRM_Utils_System::isNull($link['qs'])) {
$urlPath = CRM_Utils_System::url(self::replace($link['url'], $values),
if (strpos($urlPath, '/delete') || strpos($urlPath, 'action=delete')) {
$classes .= " small-popup";
}
+
+ $linkContent = $link['name'];
+ if (!empty($link['icon'])) {
+ if ($iconMode == 'icon') {
+ $linkContent = CRM_Core_Page::crmIcon($link['icon'], $link['name'], TRUE, ['title' => '']);
+ }
+ elseif ($iconMode == 'both') {
+ $linkContent = CRM_Core_Page::crmIcon($link['icon']) . ' ' . $linkContent;
+ }
+ }
+
$url[] = sprintf('<a href="%s" class="%s" %s' . $extra . '>%s</a>',
$urlPath,
$classes,
!empty($link['title']) ? "title='{$link['title']}' " : '',
- $link['name']
+ $linkContent
);
}
}
}
else {
$extra = '';
- $extraLinks = array_splice($url, 2);
- if (count($extraLinks) > 1) {
- $mainLinks = array_slice($url, 0, 2);
- CRM_Utils_String::append($extra, '</li><li>', $extraLinks);
- $extra = "{$extraULName}<ul class='panel'><li>{$extra}</li></ul>";
+ if ($iconMode != 'icon') {
+ $extraLinks = array_splice($url, 2);
+ if (count($extraLinks) > 1) {
+ $mainLinks = array_slice($url, 0, 2);
+ CRM_Utils_String::append($extra, '</li><li>', $extraLinks);
+ $extra = "{$extraULName}<ul class='panel'><li>{$extra}</li></ul>";
+ }
}
$resultLinks = '';
CRM_Utils_String::append($resultLinks, '', $mainLinks);
// make links indexed sequentially instead of by bitmask
// otherwise it's next to impossible to reliably add new ones
- $seqLinks = array();
+ $seqLinks = [];
foreach ($links as $bit => $link) {
$link['bit'] = $bit;
$seqLinks[] = $link;