Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Utility/Html.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
69 * The cleaned class name. | 69 * The cleaned class name. |
70 */ | 70 */ |
71 public static function getClass($class) { | 71 public static function getClass($class) { |
72 $class = (string) $class; | 72 $class = (string) $class; |
73 if (!isset(static::$classes[$class])) { | 73 if (!isset(static::$classes[$class])) { |
74 static::$classes[$class] = static::cleanCssIdentifier(Unicode::strtolower($class)); | 74 static::$classes[$class] = static::cleanCssIdentifier(mb_strtolower($class)); |
75 } | 75 } |
76 return static::$classes[$class]; | 76 return static::$classes[$class]; |
77 } | 77 } |
78 | 78 |
79 /** | 79 /** |
80 * Prepares a string for use as a CSS identifier (element, class, or ID name). | 80 * Prepares a string for use as a CSS identifier (element, class, or ID name). |
81 * | 81 * |
82 * http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for | 82 * Link below shows the syntax for valid CSS identifiers (including element |
83 * valid CSS identifiers (including element names, classes, and IDs in | 83 * names, classes, and IDs in selectors). |
84 * selectors.) | 84 * |
85 * @see http://www.w3.org/TR/CSS21/syndata.html#characters | |
85 * | 86 * |
86 * @param string $identifier | 87 * @param string $identifier |
87 * The identifier to clean. | 88 * The identifier to clean. |
88 * @param array $filter | 89 * @param array $filter |
89 * An array of string replacements to use on the identifier. | 90 * An array of string replacements to use on the identifier. |
122 // We strip out any character not in the above list. | 123 // We strip out any character not in the above list. |
123 $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier); | 124 $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier); |
124 // Identifiers cannot start with a digit, two hyphens, or a hyphen followed by a digit. | 125 // Identifiers cannot start with a digit, two hyphens, or a hyphen followed by a digit. |
125 $identifier = preg_replace([ | 126 $identifier = preg_replace([ |
126 '/^[0-9]/', | 127 '/^[0-9]/', |
127 '/^(-[0-9])|^(--)/' | 128 '/^(-[0-9])|^(--)/', |
128 ], ['_', '__'], $identifier); | 129 ], ['_', '__'], $identifier); |
129 return $identifier; | 130 return $identifier; |
130 } | 131 } |
131 | 132 |
132 /** | 133 /** |
213 * The cleaned ID. | 214 * The cleaned ID. |
214 * | 215 * |
215 * @see self::getUniqueId() | 216 * @see self::getUniqueId() |
216 */ | 217 */ |
217 public static function getId($id) { | 218 public static function getId($id) { |
218 $id = str_replace([' ', '_', '[', ']'], ['-', '-', '-', ''], Unicode::strtolower($id)); | 219 $id = str_replace([' ', '_', '[', ']'], ['-', '-', '-', ''], mb_strtolower($id)); |
219 | 220 |
220 // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can | 221 // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can |
221 // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"), | 222 // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"), |
222 // colons (":"), and periods ("."). We strip out any character not in that | 223 // colons (":"), and periods ("."). We strip out any character not in that |
223 // list. Note that the CSS spec doesn't allow colons or periods in identifiers | 224 // list. Note that the CSS spec doesn't allow colons or periods in identifiers |