Merge pull request #15818 from colemanw/fields
[civicrm-core.git] / CRM / Core / Smarty / plugins / modifier.crmAddClass.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * Add a class to an html element
22 *
23 * @param string $string
24 * The html to be tweaked.
25 * @param string $class
26 * The new class or classes to add (separate with a space).
27 *
28 * @return string
29 * the new modified html string
30 */
31 function smarty_modifier_crmAddClass($string, $class) {
32 // Standardize white space
33 $string = str_replace(['class ="', 'class= "', 'class = "'], 'class="', $string);
34 if (strpos($string, 'class="') !== FALSE) {
35 $string = str_replace('class="', 'class="' . "$class ", $string);
36 }
37 else {
38 $string = str_replace('>', ' class="' . $class . '">', $string);
39 }
40 return $string;
41 }