public static function login($membershipID, $campaignID) {
    $campaignIDs = [];
    $membershipIDs = [];
    $fullNames = [];
    $memberIDs = [];

    $request = \Drupal::request();
    $session = $request->getSession();

    if (!empty($session->get('openy_campaign'))) {
      $openyCampaignSession = $session->get('openy_campaign');
      $campaignIDs = $openyCampaignSession['campaign_ids'];
      $membershipIDs = $openyCampaignSession['membership_ids'];
      $fullNames = $openyCampaignSession['full_names'];
      $memberIDs = $openyCampaignSession['member_ids'];
    }

    // Add new Campaign ID, MembershipID and Full name to SESSION.
    if (!in_array($campaignID, $campaignIDs) || !in_array($membershipID, $membershipIDs)) {
      // Load Member by unique Membership ID.
      $query = \Drupal::entityQuery('openy_campaign_member')
        ->condition('membership_id', $membershipID);
      $result = $query->execute();
      if (!empty($result)) {
        $memberID = reset($result);
        $member = Member::load($memberID);
      }

      $campaignIDs[] = $campaignID;
      $membershipIDs[$campaignID] = $membershipID;
      $fullName = (!empty($member) && !empty($member->getFullName())) ? $member->getFullName() : t('Team member');
      $fullNames[$campaignID] = $fullName;
      $memberId = !empty($member) ? $member->id() : '';
      $memberIDs[$campaignID] = $memberId;

      Cache::invalidateTags(['member:' . $memberId]);

      $session->set('openy_campaign', [
        'member_ids' => $memberIDs,
        'campaign_ids' => $campaignIDs,
        'membership_ids' => $membershipIDs,
        'full_names' => $fullNames,
      ]);
    }
  }
public static function login($membershipID, $campaignID) {
    $campaignIDs = [];
    $membershipIDs = [];
    $fullNames = [];
    $memberIDs = [];

    $request = \Drupal::request();
    $session = $request->getSession();

    if (!empty($session->get('openy_campaign'))) {
      $openyCampaignSession = $session->get('openy_campaign');
      $campaignIDs = $openyCampaignSession['campaign_ids'];
      $membershipIDs = $openyCampaignSession['membership_ids'];
      $fullNames = $openyCampaignSession['full_names'];
      $memberIDs = $openyCampaignSession['member_ids'];
    }

    // Add new Campaign ID, MembershipID and Full name to SESSION.
    if (!in_array($campaignID, $campaignIDs) || !in_array($membershipID, $membershipIDs)) {
      // Load Member by unique Membership ID.
      $query = \Drupal::entityQuery('openy_campaign_member')
        ->condition('membership_id', $membershipID);
      $result = $query->execute();
      if (!empty($result)) {
        $memberID = reset($result);
        $member = Member::load($memberID);
      }

      $campaignIDs[] = $campaignID;
      $membershipIDs[$campaignID] = $membershipID;
      $fullName = (!empty($member) && !empty($member->getFullName())) ? $member->getFullName() : t('Team member');
      $fullNames[$campaignID] = $fullName;
      $memberId = !empty($member) ? $member->id() : '';
      $memberIDs[$campaignID] = $memberId;

      Cache::invalidateTags(['member:' . $memberId]);

      $session->set('openy_campaign', [
        'member_ids' => $memberIDs,
        'campaign_ids' => $campaignIDs,
        'membership_ids' => $membershipIDs,
        'full_names' => $fullNames,
      ]);
    }
  }
public static function login ( $ membershipID , $ campaignID ) { $ campaignIDs = [ ] ; $ membershipIDs = [ ] ; $ fullNames = [ ] ; $ memberIDs = [ ] ; $ request = \ Drupal :: request ( ) ; $ session = $ request -> getSession ( ) ; if ( ! empty ( $ session -> get ( 'openy_campaign' ) ) ) { $ openyCampaignSession = $ session -> get ( 'openy_campaign' ) ; $ campaignIDs = $ openyCampaignSession [ 'campaign_ids' ] ; $ membershipIDs = $ openyCampaignSession [ 'membership_ids' ] ; $ fullNames = $ openyCampaignSession [ 'full_names' ] ; $ memberIDs = $ openyCampaignSession [ 'member_ids' ] ; } // Add new Campaign ID, MembershipID and Full name to SESSION. if ( ! in_array ( $ campaignID , $ campaignIDs ) || ! in_array ( $ membershipID , $ membershipIDs ) ) { // Load Member by unique Membership ID. $ query = \ Drupal :: entityQuery ( 'openy_campaign_member' ) -> condition ( 'membership_id' , $ membershipID ) ; $ result = $ query -> execute ( ) ; if ( ! empty ( $ result ) ) { $ memberID = reset ( $ result ) ; $ member = Member :: load ( $ memberID ) ; } $ campaignIDs [ ] = $ campaignID ; $ membershipIDs [ $ campaignID ] = $ membershipID ; $ fullName = ( ! empty ( $ member ) && ! empty ( $ member -> getFullName ( ) ) ) ? $ member -> getFullName ( ) : t ( 'Team member' ) ; $ fullNames [ $ campaignID ] = $ fullName ; $ memberId = ! empty ( $ member ) ? $ member -> id ( ) : '' ; $ memberIDs [ $ campaignID ] = $ memberId ; Cache :: invalidateTags ( [ 'member:' . $ memberId ] ) ; $ session -> set ( 'openy_campaign' , [ 'member_ids' => $ memberIDs , 'campaign_ids' => $ campaignIDs , 'membership_ids' => $ membershipIDs , 'full_names' => $ fullNames , ] ) ; } }
Login member by Campaign ID. Save it to SESSION.

@param $membershipID
int Membership card number.
@param $campaignID
int Campaign node ID.
Login member by Campaign ID . Save it to SESSION .