-
Notifications
You must be signed in to change notification settings - Fork 22
Redirects users on homepage to proper path prefix #5458
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,35 @@ define('DOSOMETHING_GLOBAL_DEFAULT_LANG_CODE', 'en-global'); | |
| function dosomething_global_init() { | ||
| global $user; | ||
|
|
||
| // Redirect people hitting the homepage to there local version | ||
| if (drupal_is_front_page() && is_numeric(arg(1))) { | ||
|
|
||
| // Cannot use arg() as it doesn't return path prefixes | ||
| $path = request_path(); | ||
| $args = explode('/', $path); | ||
|
|
||
| // Only apply logic to Global homepage. | ||
| if (!empty($path) && $args[0] != 'node') { | ||
| return; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like some wild code to determine the home page, whyyyy? what's going on?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately it had to be wild... all of these are supporting edge cases / weird things I found. (eg: even if the URL is just / the arg 0 and 1 params still return the homepage node). The homepage is a weird thing, the comments point out which part handles what. |
||
|
|
||
| $country_code = dosomething_settings_get_geo_country_code(); | ||
| $language = dosomething_global_convert_country_to_language($country_code); | ||
| // No matching language, serve the global page | ||
| if ($language == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| // Get users local path prefix and verify we support it | ||
| $path_prefix = dosomething_global_get_prefix_for_language($language); | ||
| if ($path_prefix == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| // Redirect user | ||
| drupal_goto($path_prefix . '/' . current_path()); | ||
| } | ||
|
|
||
| // Verify we're dealing with a node edit with no translation specification in the URL | ||
| if (arg(0) == "node" && is_numeric(arg(1)) && arg(2) == "edit" && null == arg(3)) { | ||
| // Load the page node and user | ||
|
|
@@ -268,6 +297,20 @@ function dosomething_global_convert_country_to_language($country) { | |
| return NULL; | ||
| } | ||
|
|
||
| /** | ||
| * Converts the given language into its assigned URL prefix. | ||
| * | ||
| * @param string language | ||
| * The language to get the prefix for (eg: 'en', 'mx') | ||
| * | ||
| * @return | ||
| * The URL prefix mapped to this language | ||
| */ | ||
| function dosomething_global_get_prefix_for_language($language) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drupal has a function language_list() that returns all of the languages with their information. This query works, but I'm thinking that using the built-in function is more drupally, and it's a little less code for us to maintain. This is what language_list() returns by default, but it can return a list keyed by the field you pass in.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh thats better, for some reason i thought language list only returned a list of the languages, not all of the details. Ill switch this out! |
||
| $languages = language_list(); | ||
| return $languages[$language]->prefix; | ||
| } | ||
|
|
||
| /** | ||
| * Get the appropriate language for the application. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their* local version (sp)