Here I propose a modified version of the issue solution
Add setting to disable per-user rendering(issue #3081703)
Changes that are proposed to be made:
1) Custom Mail Cache (MailCacheJust.php):
-Implementation of a custom mail cache class (MailCacheJust) that ensures caching of only necessary data and build information.
-This helps in maintaining consistency across newsletter deliveries, irrespective of whether subscribers have associated user accounts or not.
2)Custom Mail Entity (CustomMailEntity.php):
-Extention of the MailEntity class to disable account switching during entity rendering.
-This prevents issues related to recursive rendering errors, especially critical when rendering entities with references.
3)Custom Service Provider (CustomNewsletterServiceProvider.php):
-Creation of a service provider to replace Simplenews services with your custom implementations (MailCacheJust and CustomMailEntity).
-This ensures that Drupal uses your custom classes throughout the Simplenews module, improving performance and consistency.
4)Service Definitions (simplenews.services.yml):
-Definition of the services (MailCacheJust, CustomMailEntity, and CustomNewsletterServiceProvider) correctly in the service definitions.
-This registration ensures that Drupalโs dependency injection container correctly manages and uses your custom services.
Aditiup โ made their first commit to this issueโs fork.
Hello sir,
For the issue #3447905 I recommend the following alterations to be made
Wrong 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.
Aditiup โ made their first commit to this issueโs fork.
Hello Sir,
For the issue #3031919 I propose the following solution, I guess this might solve the problem
Changes to be made in the initial code in SubscriberForm.php
1)Added Email Field for Anonymous Users:For anonymous users, an email field is added to the form to capture their email address.
2)Handled Users Without Email Addresses:For logged-in users without an email address, a message is displayed indicating that their subscription will remain inactive until an email address is set.
3)Adjusted Subscription Logic:In the submitForm method, the subscription logic now checks if the email is provided. If not, it creates the subscription with an inactive status.
Changes to be made in the initial code in entity Subscriber.php
1)Email Field Requirements and Unique Constraint:
-Changes: The email field is defined as required (setRequired(TRUE)) and includes a uniqueness constraint (addConstraint('UniqueField', [])).
-Solution: Ensures that every subscriber entity must have a valid and unique email address. This prevents the creation of entities with empty or null email values, which could cause query conditions to fail when querying by email.
2)User and Subscription Synchronization:
-Changes: Implemented fillFromAccount() and copyToAccount() methods to synchronize data between the subscriber entity and user accounts.
-Solution: When a user subscribes with a blank email, these methods ensure that relevant user information (such as email address, preferred language, and status) is correctly synchronized between the user account and the subscriber entity. This synchronization prevents discrepancies that could lead to errors in subscription management.
3)Entity Load and Creation:
-Changes: Added loadByMail() and loadByUid() methods to facilitate loading of subscriber entities based on email or user ID.
-Solution: These methods ensure proper entity creation and retrieval, even in cases where users have blank email addresses. They provide flexibility to create new entities if none exist, ensuring robust entity management regardless of initial user data.
Changes to be made in the initial code in entity ConfirmationController.php
1)Subscriber Email Check: Added checks using $subscriber->getEmail() to ensure the subscriber has a valid email address before performing subscription actions (subscribe or unsubscribe).
2)Immediate Action Handling: Adjusted logic within the else block to include checks before calling $this->subscriptionManager->subscribe() or $this->subscriptionManager->unsubscribe() to ensure operations are only performed if the subscriber's email address exists.
Changes to be made in query condition.php
condition() Method Adjustment:
1)Within the condition() method, added a check specific to simplenews_subscriber.mail field where if the value is empty (NULL or ''), the condition is skipped to prevent the `
2)The check ensures that conditions involving simplenews_subscriber.mail are handled gracefully when the value is empty, aligning with the proposed resolution to allow subscriptions without an email but defer activation until an email is set.