- Issue created by @somebodysysop
- πͺπΈSpain manuel.adan π
Sure, it is explained in the module's main page
launch an email confirmation in just 1 line
\Drupal::service('email_confirmer')->confirm('somemail@example.com'); - Status changed to Fixed
3 days ago 11:13am 1 March 2025 - πΊπΈUnited States somebodysysop
I don't believe the question I asked is explained in the module's main page.
What wanted to build was a mechanism by which a user could confirm his email address by replying to the confirmation email sent by email-confirmer. I was looking for a hook that would allow me to do that.
I guess I wasn't clear enough in my question. Anyway, I came up with this process:
- extract_confirmation_url_from_email($email_body)
- extract_uuid_from_url($url)
- confirm_email_by_uuid($uuid)
Here is the code I created to confirm the email address (using the code from the home page) using the uuid extracted from the reply email:
/** * Confirms an email confirmation entity by UUID. * * This method loads the email confirmation entity based on the UUID provided. * If the entity is still pending, it marks the confirmation as confirmed, saves it, * and returns 1 for a successful confirmation. If the entity is not found or * is not in a pending state, it returns 0. * * @param string $uuid * The UUID of the email confirmation entity. * * @return int * Returns 1 if the confirmation is successful, or 0 if the confirmation fails. */ function confirm_email_by_uuid($uuid) { // Load the confirmation entity by UUID. $confirmations = \Drupal::entityTypeManager() ->getStorage('email_confirmer_confirmation') ->loadByProperties(['uuid' => $uuid]); // Get the first confirmation entity. $confirmation = reset($confirmations); if ($confirmation && $confirmation->isPending()) { // Bypass hash and directly mark as confirmed. $confirmation->set('confirmed', EmailConfirmationInterface::CONFIRMED); $confirmation->save(); // Optionally invoke hooks or additional logic. \Drupal::moduleHandler()->invokeAll('email_confirmer', ['confirm', $confirmation]); // Return 1 for successful confirmation. return 1; } else { // Return 0 for invalid, expired, or not pending confirmation. return 0; } }
It's working.
I am aware that using this mechanism, all someone has to do is forward the email sent by email_confirmer to anyone they wish. But, in my situation, the onus for the results is on the user.
Anyway, thanks for the response. Better late than never.