public static function Utility::sanitizeMachineName in Menu Item Extras 8.2
Sanitize string.
Parameters
string $string: Input string.
Return value
string Sanitized string.
2 calls to Utility::sanitizeMachineName()
- UtilityTest::testSanitizedSuggestion in tests/
src/ Unit/ UtilityTest.php - Check sanitizing of suggestions.
- UtilityTest::testSanitizeMachineName in tests/
src/ Unit/ UtilityTest.php - Test string sanitizing.
File
- src/
Utility/ Utility.php, line 42
Class
- Utility
- Utility functions specific to menu_item_extras.
Namespace
Drupal\menu_item_extras\UtilityCode
public static function sanitizeMachineName($string) {
$to_replace = [
' ',
'-',
'.',
];
$string = str_replace($to_replace, array_fill(0, count($to_replace), '_'), mb_strtolower($string));
$string = preg_replace('/[^A-Za-z0-9\\_]/', '', $string);
return self::limitUnderscores($string);
}