diff --git a/i18n_menu/i18n_menu.inc b/i18n_menu/i18n_menu.inc index c40cf5e..570bf9e 100644 --- a/i18n_menu/i18n_menu.inc +++ b/i18n_menu/i18n_menu.inc @@ -79,7 +79,8 @@ class i18n_menu_link extends i18n_string_object_wrapper { /** * Get translatable properties. * - * Check whether title or description are to be translated by default menu system. + * Check whether title or description are to be translated by default menu + * system. */ protected function build_properties() { $properties = parent::build_properties(); diff --git a/i18n_menu/i18n_menu.install b/i18n_menu/i18n_menu.install index d4e53e0..0f49e1e 100644 --- a/i18n_menu/i18n_menu.install +++ b/i18n_menu/i18n_menu.install @@ -48,24 +48,24 @@ function i18n_menu_update_7000() { } /** - * Set alter property for menu items with language + * Set alter property for menu items with language. */ function i18n_menu_update_7001() { // Compile a list of menus with i18n options. - $i18n_menus = array_filter('i18n_menu_mode', menu_get_names()); + $i18n_menus = array_filter(menu_get_names(), 'i18n_menu_mode'); if ($i18n_menus) { $query = db_select('menu_links', 'm') - ->fields('m', array('mlid', 'options')) + ->fields('m') ->condition('menu_name', $i18n_menus); - foreach ($query->execute()->fetchAllAssoc() as $item) { + foreach ($query->execute()->fetchAllAssoc('mlid', PDO::FETCH_ASSOC) as $mlid => $item) { $options = unserialize($item['options']); - if (_i18n_menu_link_check_alter($link) && empty($options['alter'])) { + if (_i18n_menu_link_check_alter($item) && empty($options['alter'])) { $options['alter'] = TRUE; db_update('menu_links') - ->condition('mlid', $item->mlid) + ->condition('mlid', $mlid) ->fields(array('options' => serialize($options))) ->execute(); } } } -} \ No newline at end of file +} diff --git a/i18n_menu/i18n_menu.module b/i18n_menu/i18n_menu.module index 46cc2c0..6ae2601 100644 --- a/i18n_menu/i18n_menu.module +++ b/i18n_menu/i18n_menu.module @@ -56,14 +56,17 @@ function i18n_menu_menu_alter(&$items) { } /** - * Implements hook_block_view() + * Implements hook_block_view(). */ function i18n_menu_block_view_alter(&$data, $block) { if (($block->module == 'menu' || $block->module == 'system') && (i18n_menu_mode($block->delta) & I18N_MODE_MULTIPLE)) { $menus = menu_get_menus(); if (isset($menus[$block->delta])) { if (empty($block->title)) { - $data['subject'] = i18n_string_plain(array('menu', 'menu', $block->delta, 'title'), $menus[$block->delta]); + $data['subject'] = i18n_string_plain( + array('menu', 'menu', $block->delta, 'title'), + $menus[$block->delta] + ); } // Add contextual links for this block. if (!empty($data['content'])) { @@ -190,7 +193,7 @@ function i18n_menu_menu_link_insert($link) { } /** - * Implements hook_menu_update() + * Implements hook_menu_update(). */ function i18n_menu_menu_link_update($link) { // Stores the fields to update. @@ -198,10 +201,12 @@ function i18n_menu_menu_link_update($link) { $menu_mode = i18n_menu_mode($link['menu_name']); if ($menu_mode & I18N_MODE_TRANSLATE && isset($link['language'])) { - // Multilingual menu links, translatable, it may be part of a translation set. + // Multilingual menu links, translatable, it may be part of a + // translation set. if (i18n_object_langcode($link)) { if (!empty($link['translation_set'])) { - // Translation set comes as parameter, we may be creating a translation, add link to the set + // Translation set comes as parameter, we may be creating a translation, + // add link to the set. $translation_set = $link['translation_set']; $translation_set ->add_item($link) @@ -218,8 +223,9 @@ function i18n_menu_menu_link_update($link) { $fields['i18n_tsid'] = 0; } } - // For multilingual menu items, always set a language and mark them for 'alter' - // so they can be processed later by hook_translated_link_menu_alter() + // For multilingual menu items, always set a language and mark them for + // 'alter' so they can be processed later by + // hook_translated_link_menu_alter(). if ($menu_mode) { if (!isset($link['language'])) { $link['language'] = LANGUAGE_NONE; @@ -228,7 +234,8 @@ function i18n_menu_menu_link_update($link) { $fields['options'] = $link['options']; $fields['options']['alter'] = TRUE; } - // We cannot unmark links for altering because we don't know what other modules use it for. + // We cannot unmark links for altering because we don't know what other + // modules use it for. } // Update language field if the link has a language value. if (isset($link['language'])) { @@ -245,7 +252,8 @@ function i18n_menu_menu_link_update($link) { ->condition('mlid', $link['mlid']) ->execute(); } - // Update translatable strings if any for customized links that belong to a localizable menu. + // Update translatable strings if any for customized links that belong to a + // localizable menu. if (_i18n_menu_link_is_localizable($link)) { i18n_string_object_update('menu_link', $link); @@ -343,13 +351,13 @@ function i18n_menu_variable_info_alter(&$variables, $options) { /** * Get localized menu tree. - * @param $menu_name + * + * @param string $menu_name * The menu the translated tree has to be fetched from. - * @param $langcode - * Optional language code to get the menu in, defaults to request language. - * @param $reset + * @param string $langcode + * Optional language code to get the menu in, defaults to request language. + * @param bool $reset * Whether to reset the internal i18n_menu_translated_tree cache. - * */ function i18n_menu_translated_tree($menu_name, $langcode = NULL, $reset = FALSE) { $menu_output = &drupal_static(__FUNCTION__); @@ -510,8 +518,8 @@ function _i18n_menu_link_description($link, $langcode = NULL) { * Check whether this link is to be processed by i18n_menu and start processing. */ function _i18n_menu_link_process(&$link) { - // Only visible links that have a language property and haven't been processed before. - // We also check that they belong to a menu with language options. + // Only visible links that have a language property and haven't been processed + // before. We also check that they belong to a menu with language options. if (empty($link['i18n_menu']) && !empty($link['language']) && !empty($link['access']) && empty($link['hidden']) && i18n_menu_mode($link['menu_name'])) { // Mark so it won't be processed twice. $link['i18n_menu'] = TRUE; @@ -528,7 +536,7 @@ function _i18n_menu_link_process(&$link) { * Menu items that have a language or that have any localizable strings * will be marked to be run through hook_translated_menu_link_alter(). * - * @see i18n_menu_translated_menu_link_alter(). + * @see i18n_menu_translated_menu_link_alter() */ function _i18n_menu_link_check_alter($link) { return i18n_menu_mode($link['menu_name']) && (i18n_object_langcode($link) || _i18n_menu_link_is_localizable($link, TRUE)); @@ -537,11 +545,15 @@ function _i18n_menu_link_check_alter($link) { /** * Check whether this link should be localized by i18n_menu. * - * @param $link - * Menu link array - * @param $check_strings - * Whether to check if the link has actually localizable strings. Since this is a more - * expensive operation, it will be just checked when editing menu items. + * @param array $link + * Menu link array. + * @param bool $check_strings + * Whether to check if the link has actually localizable strings. Since this + * is a more expensive operation, it will be just checked when editing menu + * items. + * + * @return boolean + * Returns TRUE if link is localizable. */ function _i18n_menu_link_is_localizable($link, $check_strings = FALSE) { return !empty($link['customized']) && !i18n_object_langcode($link) && i18n_menu_mode($link['menu_name'], I18N_MODE_LOCALIZE) && @@ -567,13 +579,14 @@ function _i18n_menu_link_localizable_properties($link) { // it will be localized by core, not by i18n_menu. if (!$router || (empty($router['title_callback']) || $router['title_callback'] != 't') || - (empty($router['title']) || $router['title'] != $link['link_title'])) - { + (empty($router['title']) || $router['title'] != $link['link_title']) + ) { $props[] = 'title'; } } if (!empty($link['options']['attributes']['title'])) { - // If the description matches the router description, it will be localized by core. + // If the description matches the router description, it will be localized + // by core. if (!$router || empty($router['description']) || $router['description'] != $link['options']['attributes']['title']) { $props[] = 'description'; } @@ -587,11 +600,11 @@ function _i18n_menu_link_localizable_properties($link) { * We need the untranslated title to compare, and this will be fast. * There's no api function to do this? * - * @param $path + * @param string $path * The path to fetch from the router. */ function _i18n_menu_get_router($path) { - $cache = &drupal_static(__FUNCTION__ , array()); + $cache = &drupal_static(__FUNCTION__, array()); if (!array_key_exists($path, $cache)) { $cache[$path] = db_select('menu_router', 'mr') ->fields('mr', array('title', 'title_callback', 'description'))