-
Notifications
You must be signed in to change notification settings - Fork 22
Updates global #5266
Updates global #5266
Changes from all 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 |
|---|---|---|
|
|
@@ -250,6 +250,9 @@ function dosomething_user_form_alter(&$form, $form_state, $form_id) { | |
| if ($form_id == 'user_register_form' && $_SERVER['REQUEST_URI'] != '/admin/people/create') { | ||
| $form['#action'] = '/user/register'; | ||
| $form['#submit'][] = 'dosomething_user_new_user'; | ||
| if (module_exists('dosomething_global')) { | ||
| $form['#submit'][] = 'dosomething_user_new_user_attributes'; | ||
|
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. new_user_global_attributes?
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. |
||
| } | ||
| // Unsets relevant register form fields based on configuration variables. | ||
| _dosomething_user_register_display_fields($form); | ||
| // Add campaign data, if needed. | ||
|
|
@@ -464,17 +467,6 @@ function dosomething_user_new_user($form, &$form_state) { | |
| global $user; | ||
| $account = $user; | ||
|
|
||
| if (module_exists('dosomething_global')) { | ||
| // Adjust language based on location | ||
| $user_country_code = dosomething_settings_get_geo_country_code(); | ||
| $language = dosomething_global_convert_country_to_language($user_country_code); | ||
| $system_languages = language_list(); | ||
| if (!in_array($langauge, $system_languages)) { | ||
| $language = 'en-global'; | ||
| } | ||
| user_save($account, ['language' => $language]); | ||
| } | ||
|
|
||
| // Should we sign this kid up for messages? | ||
| if (dosomething_user_is_under_thirteen()) { | ||
| return; | ||
|
|
@@ -523,6 +515,56 @@ function dosomething_user_new_user($form, &$form_state) { | |
| dosomething_mbp_request('user_register', $params); | ||
| } | ||
|
|
||
| function dosomething_user_new_user_attributes($form, &$form_state) { | ||
| dosomething_user_set_global_attributes(); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the user global attributes and sends them to Northstar. | ||
| * | ||
| * @param object $account | ||
| * The account to return value for. If NULL, uses global $user. | ||
| * @param string $country_code | ||
| * The country code where the user currently resides. If NULL, uses | ||
| * the headers in current request. | ||
| * @param string $language | ||
| * The new language to set on the user. If NULL, gets the matching | ||
| * language or defaults. | ||
| */ | ||
| function dosomething_user_set_global_attributes($user = NULL, $country_code = NULL, $language = NULL) { | ||
| if ($user == NULL) { | ||
| global $user; | ||
| $account = $user; | ||
| } | ||
| if ($country_code == NULL) { | ||
| $country_code = dosomething_settings_get_geo_country_code(); | ||
| // If no Fastly headers set, use US EN | ||
| if ($country_code == NULL) { | ||
| $language = 'en'; | ||
|
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.
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. Yes they are two different languages. en is just for US, en global is for all countries outside of the US we don't explicitly support |
||
| } | ||
| } | ||
| // If the language wasn't specified in the function call, determine the user language | ||
| if ($language == NULL) { | ||
|
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. can you add a comment block above explaining the logic that happens below? |
||
| $converted_language = dosomething_global_convert_country_to_language($country_code); | ||
| $language = 'en-global'; | ||
|
|
||
| // If the country in the headers matched to a language in our strongarm | ||
| if ($converted_language != NULL) { | ||
|
|
||
| // Verify the language is installed on the system, | ||
| $system_languages = language_list(); | ||
| foreach ($system_languages as $lang_key => $system_lang) { | ||
| if ($converted_language == $lang_key) { | ||
| $language = $converted_language; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| user_save($account, ['language' => $language]); | ||
| //TODO: (#5263) Send $language and $country_code to NorthStar | ||
|
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. we will also want to save user country to the user
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. I don't see this field anywhere, has it been created yet?
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. it's a part of field_address
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. ohh gotcha
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. see #5266 (comment) |
||
| } | ||
|
|
||
| /** | ||
| * Checks that user is over 13. | ||
| * | ||
|
|
||
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.
can you add comments for why we are returning null here?
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.
yep- just to add it here first,
this function shouldn't be deciding what the correct default value should be, as the name implies its only purpose is to find the matching language for that country. In some cases, that country doesn't have a matching language and it's useful to have it return a default lang, in others, it might be more preferable to have it return NULL.