0

Im using Domains Access to create a subdomain and already created all the virtualhosts, so that one is working.

Is it possible to show a user based on domain name?

Im creating a view, and i need to show for example:

lucas.site.com and show user lucas.

I have tried by adding contextual filter: User ID context on route.
But it doesn't take effect, it looks in lucas.site.com/lucas maybe im missing something?

2
  • You can try this drupal.org/project/user_field_value in your contextual filter or really contextual filters don't really look for the domain or subdomain .. So you want to display the domain that user belongs to ?? please include more info on the view you are creating could you just use a custom text field and a twig replacement ?
    – taggartJ
    Jan 6, 2020 at 4:42
  • Thank you, already done with a custom view. Jan 6, 2020 at 13:20

1 Answer 1

0

Reply to my self:

I have created a custom Controller that get the user from db based on the domain, i get the subdomain using this:

$subdomain = substr_count($_SERVER['HTTP_HOST'], '.') > 1 ? substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')) : '';

Not sure if its the best.

Then i compare to the user on db:

$result = \Drupal::database()->select('user_data', 'n')
            ->fields('n', array('id', 'user_domain', 'user_email'))
            ->condition('n.user_domain', $subdomain)
            ->execute()->fetchAllAssoc('id');

First you need to create a install schema with the domain created so you can fetch this.

Then loading by user email:

$user = user_load_by_mail($userEmail); 

and pass the variable to the Twig. Not sure if its the best way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.