public function UltimenuTool::truncateRegionKey in Ultimenu 8.2
Simplify menu names or menu item titles for region key.
If region key is to use menu item title: Region key: ultimenu_LOOOOOOOOOOOONGMENUNAME_LOOOOOOOOOOOOOOOOOONGMENUITEM. If region key is to use unfriendly key UUID, we'll only care for menu name. Region key: ultimenu_LOOOOOOOOOOOOOONGMENUNAME_1c2d3e4.
Parameters
string $string: The Menu name or menu item title.
int $max_length: The amount of characters to truncate.
Return value
string The truncated menu properties ready to use for region key.
Overrides UltimenuToolInterface::truncateRegionKey
1 call to UltimenuTool::truncateRegionKey()
- UltimenuTool::getRegionKey in src/
UltimenuTool.php - Gets the region key.
File
- src/
UltimenuTool.php, line 128
Class
- UltimenuTool
- Provides Ultimenu utility methods.
Namespace
Drupal\ultimenuCode
public function truncateRegionKey($string, $max_length = self::MAX_LENGTH) {
// Transliterate the string.
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$transformed = $this->transliteration
->transliterate($string, $langcode);
// Decode it.
$transformed = Html::decodeEntities($transformed);
$transformed = mb_strtolower(str_replace([
'menu-',
'-menu',
], '', $transformed));
$transformed = preg_replace('/[\\W\\s]+/', '_', $transformed);
// Trim trailing underscores.
$transformed = trim($transformed, '_');
$transformed = Unicode::truncate($transformed, $max_length, TRUE, FALSE);
return $transformed;
}