Untitled
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
use Drupal\Core\Database\Database; use Drupal\Core\Form\FormStateInterface; /** * Implements hook_form_alter(). */ function yourmodule_form_alter(&$form, FormStateInterface $form_state, $form_id) { // Check if the form is the one you want to alter. if ($form_id == 'your_form_id') { // Get the email ID from the form submission. $email = $form_state->getValue('email_field_name'); // Replace with the actual field name. // Perform a database query to retrieve groups associated with the email. $query = Database::getConnection()->select('group_content__invitee_mail', 'invitee') ->fields('invitee', ['entity_id']) ->condition('invitee.invitee_mail_value', $email); $entity_ids = $query->execute()->fetchCol(); if (!empty($entity_ids)) { // Query for group information based on entity IDs. $group_query = Database::getConnection()->select('group_content_field_data', 'group_data') ->fields('group_data', ['gid']) ->condition('group_data.id', $entity_ids, 'IN'); $group_ids = $group_query->execute()->fetchCol(); if (!empty($group_ids)) { // Do something with the group IDs, for example, print them. foreach ($group_ids as $group_id) { drupal_set_message('Group ID: ' . $group_id); } } else { drupal_set_message('No groups found for the provided email.'); } } else { drupal_set_message('Email not found in invitee mail table.'); } } }