Loading i18n_panels.module +108 −31 Changes for i18n_panels.module: 108 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -161,10 +161,14 @@ function i18n_panels_panels_delete_display($did) { ->condition('did', $did) ->execute() ->fetchColumn(); // Build a dummy display. $display = (object) array('uuid' => $uuid); i18n_string_object_remove('display_configuration', $display); // Remove related pane translations. // Check if this display was just saved in the db. if (!_18n_panels_is_exported_panels_display($display)) { // If the display was just saved in the db remove all translations. i18n_string_object_remove('display_configuration', $display); // Remove related pane translations too. $pids = db_select('panels_pane') ->fields('panels_pane', array('pid')) ->condition('did', $did) Loading @@ -172,6 +176,19 @@ function i18n_panels_panels_delete_display($did) { ->fetchCol(); i18n_panels_panels_pane_delete($pids); } else { // If the display is exported leave the translated strings but give the user // a hint how to clean up. drupal_set_message( t( 'The reverted panels display(s) were exported, please run a <a href="!link">string refresh</a> to update the translatable strings.', array('!link' => url('admin/config/regional/translate/i18n_string')) ), 'warning', FALSE ); } } /** * Implements hook_panels_pre_render(). Loading Loading @@ -249,6 +266,81 @@ function i18n_panels_i18n_string_list($group) { $strings = array(); if ($group == 'panels') { // Fetch all available displays. $displays = _18n_panels_fetch_all_panel_displays(); foreach ($displays as $display) { if (empty($display->uuid)) { drupal_set_message(t('The display %display has no uuid, please resave or re-export it.', array('%display' => $display->did)), 'warning'); continue; } // Avoid duplicated runs _18n_panels_fetch_all_panel_displays() probably // returns the same display twice, one for the db based and one for the // exported one. if (isset($strings['panels']['display_configuration'][$display->uuid])) { continue; } $strings['panels']['display_configuration'][$display->uuid]['title']['string'] = $display->title; foreach ($display->content as $pane) { if (empty($pane->uuid)) { // Fetch exported uuid and validate it. $uuid = str_replace('new-', '', $pane->pid); if (!panels_uuid_is_valid($uuid)) { drupal_set_message(t('The pane %pane has no uuid, please resave or re-export it.', array('%pane' => $pane->pid)), 'warning'); continue; } $pane->uuid = $uuid; } if ($translation_object = i18n_panels_get_i18n_translation_object($pane)) { // Split up all strings and add them to the list. $pane_strings = (array) $translation_object; unset($pane_strings['panels_i18n_settings']); foreach ($pane_strings as $key => $pane_string) { $strings['panels']['pane_configuration'][$pane->uuid][$key] = $pane_string; } } } } } return $strings; } /** * Checks if the give display is exported or only stored in the db. * * @return boolean * TRUE if the display is available from code. */ function _18n_panels_is_exported_panels_display($display) { if (isset($display->uuid)) { $displays = _18n_panels_fetch_all_panel_displays(); return isset($displays['exported-' . $display->uuid]); } return FALSE; } /** * Returns a list of really all available panel displays. * * The list is statically cached. Use the parameter $reset to refresh the list * during the same request. * Probably returns the same display twice - once with the db based and once * the exported one. * * @todo I bet there are better ways to solve this mess. * * @param boolean $reset * Reset the static cache. * * @return array * List of all panel displays. */ function _18n_panels_fetch_all_panel_displays($reset = FALSE) { $displays = &drupal_static(__FUNCTION__, array()); if (!empty($displays) && !$reset) { return $displays; } // Fetch db based displays. $dids = db_select('panels_display')->fields('panels_display', array('did'))->execute()->fetchCol(); $displays = panels_load_displays($dids); Loading @@ -257,7 +349,7 @@ function i18n_panels_i18n_string_list($group) { ctools_include('export'); foreach (ctools_export_crud_load_all('panels_display') as $panels_display) { if (!empty($panels_display->uuid)) { $displays['new-' . $panels_display->uuid] = $panels_display; $displays['exported-' . $panels_display->uuid] = $panels_display; } } Loading @@ -270,42 +362,27 @@ function i18n_panels_i18n_string_list($group) { foreach ($pages['tasks'] as $task) { $page = page_manager_cache_load($task); $task_info = page_manager_get_task_subtasks($page->task); foreach ($page->handler_info as $id => $info) { $page_manager_handler = $page->handlers[$id]; if ($page_manager_handler->handler == 'panel_context' && !empty($page_manager_handler->conf['display'])) { $panels_display = $page_manager_handler->conf['display']; $displays['page-manager-handler-' . $panels_display->uuid] = $panels_display; } } } } if ($page_manager_handler->handler == 'panel_context') { foreach ($displays as $display) { if (empty($display->uuid)) { drupal_set_message(t('The display %display has no uuid, please resave or re-export it.', array('%display' => $display->did)), 'warning'); continue; } $strings['panels']['display_configuration'][$display->uuid]['title']['string'] = $display->title; foreach ($display->content as $pane) { if (empty($pane->uuid)) { // Fetch exported uuid and validate it. $uuid = str_replace('new-', '', $pane->pid); if (!panels_uuid_is_valid($uuid)) { drupal_set_message(t('The pane %pane has no uuid, please resave or re-export it.', array('%pane' => $pane->pid)), 'warning'); continue; // @todo Is there really no better way to check this? $is_exported = ($page_manager_handler->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE) || (isset($page->subtask['storage']) && $page->subtask['storage'] == t('Overridden'))); if (!empty($page_manager_handler->conf['display'])) { $panels_display = $page_manager_handler->conf['display']; $displays['exported-' . $panels_display->uuid] = $panels_display; } $pane->uuid = $uuid; elseif ($is_exported && isset($page_manager_handler->conf['did'])) { $panels_display = panels_load_display($page_manager_handler->conf['did']); if (isset($panels_display->uuid)) { $displays['exported-' . $panels_display->uuid] = $panels_display; } if ($translation_object = i18n_panels_get_i18n_translation_object($pane)) { // Split up all strings and add them to the list. $pane_strings = (array) $translation_object; unset($pane_strings['panels_i18n_settings']); foreach ($pane_strings as $key => $pane_string) { $strings['panels']['pane_configuration'][$pane->uuid][$key] = $pane_string; } } } } } return $strings; return $displays; } Loading
i18n_panels.module +108 −31 Changes for i18n_panels.module: 108 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -161,10 +161,14 @@ function i18n_panels_panels_delete_display($did) { ->condition('did', $did) ->execute() ->fetchColumn(); // Build a dummy display. $display = (object) array('uuid' => $uuid); i18n_string_object_remove('display_configuration', $display); // Remove related pane translations. // Check if this display was just saved in the db. if (!_18n_panels_is_exported_panels_display($display)) { // If the display was just saved in the db remove all translations. i18n_string_object_remove('display_configuration', $display); // Remove related pane translations too. $pids = db_select('panels_pane') ->fields('panels_pane', array('pid')) ->condition('did', $did) Loading @@ -172,6 +176,19 @@ function i18n_panels_panels_delete_display($did) { ->fetchCol(); i18n_panels_panels_pane_delete($pids); } else { // If the display is exported leave the translated strings but give the user // a hint how to clean up. drupal_set_message( t( 'The reverted panels display(s) were exported, please run a <a href="!link">string refresh</a> to update the translatable strings.', array('!link' => url('admin/config/regional/translate/i18n_string')) ), 'warning', FALSE ); } } /** * Implements hook_panels_pre_render(). Loading Loading @@ -249,6 +266,81 @@ function i18n_panels_i18n_string_list($group) { $strings = array(); if ($group == 'panels') { // Fetch all available displays. $displays = _18n_panels_fetch_all_panel_displays(); foreach ($displays as $display) { if (empty($display->uuid)) { drupal_set_message(t('The display %display has no uuid, please resave or re-export it.', array('%display' => $display->did)), 'warning'); continue; } // Avoid duplicated runs _18n_panels_fetch_all_panel_displays() probably // returns the same display twice, one for the db based and one for the // exported one. if (isset($strings['panels']['display_configuration'][$display->uuid])) { continue; } $strings['panels']['display_configuration'][$display->uuid]['title']['string'] = $display->title; foreach ($display->content as $pane) { if (empty($pane->uuid)) { // Fetch exported uuid and validate it. $uuid = str_replace('new-', '', $pane->pid); if (!panels_uuid_is_valid($uuid)) { drupal_set_message(t('The pane %pane has no uuid, please resave or re-export it.', array('%pane' => $pane->pid)), 'warning'); continue; } $pane->uuid = $uuid; } if ($translation_object = i18n_panels_get_i18n_translation_object($pane)) { // Split up all strings and add them to the list. $pane_strings = (array) $translation_object; unset($pane_strings['panels_i18n_settings']); foreach ($pane_strings as $key => $pane_string) { $strings['panels']['pane_configuration'][$pane->uuid][$key] = $pane_string; } } } } } return $strings; } /** * Checks if the give display is exported or only stored in the db. * * @return boolean * TRUE if the display is available from code. */ function _18n_panels_is_exported_panels_display($display) { if (isset($display->uuid)) { $displays = _18n_panels_fetch_all_panel_displays(); return isset($displays['exported-' . $display->uuid]); } return FALSE; } /** * Returns a list of really all available panel displays. * * The list is statically cached. Use the parameter $reset to refresh the list * during the same request. * Probably returns the same display twice - once with the db based and once * the exported one. * * @todo I bet there are better ways to solve this mess. * * @param boolean $reset * Reset the static cache. * * @return array * List of all panel displays. */ function _18n_panels_fetch_all_panel_displays($reset = FALSE) { $displays = &drupal_static(__FUNCTION__, array()); if (!empty($displays) && !$reset) { return $displays; } // Fetch db based displays. $dids = db_select('panels_display')->fields('panels_display', array('did'))->execute()->fetchCol(); $displays = panels_load_displays($dids); Loading @@ -257,7 +349,7 @@ function i18n_panels_i18n_string_list($group) { ctools_include('export'); foreach (ctools_export_crud_load_all('panels_display') as $panels_display) { if (!empty($panels_display->uuid)) { $displays['new-' . $panels_display->uuid] = $panels_display; $displays['exported-' . $panels_display->uuid] = $panels_display; } } Loading @@ -270,42 +362,27 @@ function i18n_panels_i18n_string_list($group) { foreach ($pages['tasks'] as $task) { $page = page_manager_cache_load($task); $task_info = page_manager_get_task_subtasks($page->task); foreach ($page->handler_info as $id => $info) { $page_manager_handler = $page->handlers[$id]; if ($page_manager_handler->handler == 'panel_context' && !empty($page_manager_handler->conf['display'])) { $panels_display = $page_manager_handler->conf['display']; $displays['page-manager-handler-' . $panels_display->uuid] = $panels_display; } } } } if ($page_manager_handler->handler == 'panel_context') { foreach ($displays as $display) { if (empty($display->uuid)) { drupal_set_message(t('The display %display has no uuid, please resave or re-export it.', array('%display' => $display->did)), 'warning'); continue; } $strings['panels']['display_configuration'][$display->uuid]['title']['string'] = $display->title; foreach ($display->content as $pane) { if (empty($pane->uuid)) { // Fetch exported uuid and validate it. $uuid = str_replace('new-', '', $pane->pid); if (!panels_uuid_is_valid($uuid)) { drupal_set_message(t('The pane %pane has no uuid, please resave or re-export it.', array('%pane' => $pane->pid)), 'warning'); continue; // @todo Is there really no better way to check this? $is_exported = ($page_manager_handler->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE) || (isset($page->subtask['storage']) && $page->subtask['storage'] == t('Overridden'))); if (!empty($page_manager_handler->conf['display'])) { $panels_display = $page_manager_handler->conf['display']; $displays['exported-' . $panels_display->uuid] = $panels_display; } $pane->uuid = $uuid; elseif ($is_exported && isset($page_manager_handler->conf['did'])) { $panels_display = panels_load_display($page_manager_handler->conf['did']); if (isset($panels_display->uuid)) { $displays['exported-' . $panels_display->uuid] = $panels_display; } if ($translation_object = i18n_panels_get_i18n_translation_object($pane)) { // Split up all strings and add them to the list. $pane_strings = (array) $translation_object; unset($pane_strings['panels_i18n_settings']); foreach ($pane_strings as $key => $pane_string) { $strings['panels']['pane_configuration'][$pane->uuid][$key] = $pane_string; } } } } } return $strings; return $displays; }