You are here

function ultimenu_truncate_menu_property in Ultimenu 7

Simplify menu names or menu item titles for region key.

If region key is to use menu item title: Region key: ultimenu_LOOOOOOOOOOOOOONGMENUNAME_LOOOOOOOOOOOOOOOOOONGMENUITEM. If region key is to use unfriendly key MLID, we'll only care for menu name. Region key: ultimenu_LOOOOOOOOOOOOOONGMENUNAME_1234

Parameters

string $property: 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.

See also

_drupal_bootstrap_full()

decode_entities()

5 calls to ultimenu_truncate_menu_property()
ultimenu_get_config in includes/ultimenu.utilities.inc
The configuration for the requested block delta.
ultimenu_regions in includes/ultimenu.utilities.inc
The array of available Ultimenu regions based on enabled menu items.
ultimenu_tree_output in ./ultimenu.module
We use tree for future integration with regular dropdown so far.
_ultimenu_block_configure in includes/ultimenu.admin.inc
Implements hook_block_configure().
_ultimenu_block_save in includes/ultimenu.admin.inc
Implements hook_block_save().

File

includes/ultimenu.utilities.inc, line 215
Misc functions that hardly change.

Code

function ultimenu_truncate_menu_property($property, $max_length = 60) {

  // If multilingual site and transliteration enabled, support transliteration.
  $default_language = language_default();
  if (function_exists('locale') && function_exists('transliteration_clean_filename')) {
    $property = transliteration_clean_filename($property, $default_language->language);
  }
  $property = decode_entities($property);
  $property = drupal_strtolower(str_replace(array(
    'menu-',
    '-menu',
  ), '', $property));
  $property = preg_replace('/[\\W\\s]+/', '_', $property);

  // Trim trailing underscores.
  $property = trim($property, '_');
  $property = truncate_utf8($property, $max_length, TRUE, FALSE);
  return $property;
}