- Issue created by @vlad.dancer
- 🇺🇦Ukraine vlad.dancer Kyiv
vlad.dancer → changed the visibility of the branch 3.x to hidden.
- Merge request !54Issue #3447905: Wrong subscriber's prefered language for anonymous user when interface language is not default → (Merged) created by vlad.dancer
- 🇺🇦Ukraine vlad.dancer Kyiv
Results for the test case:
// Switch to non default language. $this->drupalGet('/es'); // Subscibe. $this->submitForm($edit, 'Subscribe'); $subscriber = $this->getLatestSubscriber(); // Expect to get non default language $this->assertEquals('es', $subscriber->getLangcode(), 'Subscriber prefered language is set to user interface language');
- Status changed to Needs review
6 months ago 6:48pm 17 May 2024 - 🇺🇦Ukraine vlad.dancer Kyiv
For the moment developers can set language in the next way:
/** * Implements hook_form_FORM_ID_alter(). * * Set anonymous subscriber's preferred language based on current user interface. * Fix Issue # 3447905. */ function mymodule_form_simplenews_subscriptions_block_[NEWSLETTER_ID]_alter(array &$form, FormStateInterface &$form_state): void { if (\Drupal::currentUser()->isAnonymous()) { array_unshift($form['actions']['submit']['#submit'], 'mymodule_alter_preferred_language'); } } function mymodule_alter_preferred_language(array &$form, FormStateInterface $form_state): void { $form_state->setValue(['langcode', 0, 'value'], \Drupal::languageManager()->getCurrentLanguage()->getId()); }
Or even add language dropdown:
function mymodule_form_simplenews_subscriptions_block_[NEWSLETTER_ID]_alter(array &$form, FormStateInterface &$form_state): void { if (\Drupal::currentUser()->isAnonymous()) { array_unshift($form['actions']['submit']['#submit'], 'mymodule_alter_prefered_language'); $form['lang'] = [ '#type' => 'language_select', '#title' => t('Preferred language'), '#default_value' => \Drupal::languageManager()->getCurrentLanguage()->getId(), '#languages' => LanguageInterface::STATE_CONFIGURABLE, ]; } } function mymodule_alter_prefered_language(array &$form, FormStateInterface $form_state): void { $selectedLang = $form_state->getValue('lang'); $form_state->setValue(['langcode', 0, 'value'], $selectedLang ?? \Drupal::languageManager()->getCurrentLanguage()->getId()); }
- Issue was unassigned.
- First commit to issue fork.
- 🇮🇳India Aditiup
Hello sir,
For the issue #3447905 I recommend the following alterations to be madeWrong subscriber's prefered language for anonymous user when interface language is not default
Changes to be made:
1) Changes in SubscriptionsBlockForm.php
form Method Modification:Inside the form method, check if the current user is anonymous using \Drupal::currentUser()->isAnonymous().
If the user is anonymous, set the default value of the langcode field to the current interface language using \Drupal::languageManager()->getCurrentLanguage()->getId().2) Changes in simplenews.module
-simplenews_form_alter Hook Implementation:
This function alters forms based on their ID. It checks the form ID and calls specific functions to modify the forms.
Newly Added: simplenews_form_alter function is added to handle different form alterations in a centralized manner.-simplenews_form_user_register_form_alter:
Adds subscription options to the user registration form.
Previously Provided: This function was given earlier and is now included in the simplenews.module.-simplenews_user_profile_form_submit:
Handles the submission of the user registration form, processing newsletter subscriptions.
Previously Provided: This function was given earlier and is now included in the simplenews.module.-simplenews_form_simplenews_subscriptions_block_alter:
Ensures anonymous subscribers get the correct language based on the current user interface language.
Newly Added: This function was added to fix the issue with the wrong preferred language for anonymous users. - 🇺🇦Ukraine vlad.dancer Kyiv
@Aditiup 16.92MB patch with over 234053 lines changed, is it purposely?
Regarding last commit in MR54 with +117/-168 changes in simplenews.module. These changes will never be reviewed/accepted at once.
- 🇹🇳Tunisia Ahmed Aziz ABBASSI
@vlad.dancer As her mentor for GSoC (Google Summer of Code) 2024, I would like to dedicate time this weekend to review and test her work. If you have any other suggestions or ideas, I would be happy to hear them.
- 🇹🇳Tunisia Ahmed Aziz ABBASSI
I was busy last weekend by work and family plans. I will dedicate this weekend for testing @Aditiup work.
- Status changed to Needs work
about 2 months ago 5:24pm 19 September 2024 - 🇬🇧United Kingdom adamps
Unfortunately I can't understand the last commit added in #9. It makes many changes that don't seem related to this issue.
I suggest we go back to the previous commit which basically looks good but there were some test failures.
- First commit to issue fork.
MR's branch reset to last stable commits and rebased on to 4.x. Ready to review.
-
adamps →
committed 4dce8b84 on 4.x authored by
vlad.dancer →
Issue #3447905 by vlad.dancer, davps, adamps: Wrong subscriber's...
-
adamps →
committed 4dce8b84 on 4.x authored by
vlad.dancer →
Automatically closed - issue fixed for 2 weeks with no activity.