public function getRedirectUrl($location_id, $membership_id) {
    $storage = $this->entityTypeManager->getStorage('node');
    $membership = $storage->load($membership_id);
    $info = $membership->field_mbrshp_info->referencedEntities();
    $defaultUrl = Url::fromRoute('<front>');
    foreach ($info as $value) {
      if (!empty($value->field_mbrshp_location->first()) && $value->field_mbrshp_location->first()->get('target_id')->getValue() == $location_id) {
        return !empty($value->field_mbrshp_link->first()) ? $value->field_mbrshp_link->first()->getUrl() : $defaultUrl;
      }
    }
    return NULL;
  }
public function getRedirectUrl($location_id, $membership_id) {
    $storage = $this->entityTypeManager->getStorage('node');
    $membership = $storage->load($membership_id);
    $info = $membership->field_mbrshp_info->referencedEntities();
    $defaultUrl = Url::fromRoute('<front>');
    foreach ($info as $value) {
      if (!empty($value->field_mbrshp_location->first()) && $value->field_mbrshp_location->first()->get('target_id')->getValue() == $location_id) {
        return !empty($value->field_mbrshp_link->first()) ? $value->field_mbrshp_link->first()->getUrl() : $defaultUrl;
      }
    }
    return NULL;
  }
public function getRedirectUrl ( $ location_id , $ membership_id ) { $ storage = $ this -> entityTypeManager -> getStorage ( 'node' ) ; $ membership = $ storage -> load ( $ membership_id ) ; $ info = $ membership -> field_mbrshp_info -> referencedEntities ( ) ; $ defaultUrl = Url :: fromRoute ( '<front>' ) ; foreach ( $ info as $ value ) { if ( ! empty ( $ value -> field_mbrshp_location -> first ( ) ) && $ value -> field_mbrshp_location -> first ( ) -> get ( 'target_id' ) -> getValue ( ) == $ location_id ) { return ! empty ( $ value -> field_mbrshp_link -> first ( ) ) ? $ value -> field_mbrshp_link -> first ( ) -> getUrl ( ) : $ defaultUrl ; } } return NULL ; }
Get Redirect Link.

@param int $location_id
Location ID.
@param string $membership_id
Membership type ID.

@return \Drupal\Core\Url
Redirect url.
Get Redirect Link .