I have been working on a project that would be most beneficial to have easy access to the domain_user variables inside of blocks. Where I could just print the variable out using some php.

I would like to see if anyone else could see the benefit of this feature. I can not believe it would not be useful to most.

Thank you in advance for the responses.

Comments

agentrickard’s picture

Version: 5.x-1.0rc4 » 5.x-1.0
Category: feature » support

rc4 is no longer supported.

I don't know exactly what you are asking for.

The $_domain variable is a global variable which represents the current active domain, and domain_user implements hook_domainload() to attach the UID (user ID) to the $_domain array. This is created during hook_init(), so all of the domain_user data is available to you at any point in the page load cycle.

I suspect you want something like this for checking the current domain:

global $_domain;
if (isset($_domain['uid'])) {
  // Hey, this is a user domain!  Let's do something!
}

If you need to pull all domain information into a block, use domain_domains().

$domains = domain_domains();
if (!empty($domains)) {
  foreach ($domains as $domain) {
    if (isset($domain['uid'])) {
      // Hey, this is a user domain!  Let's do something!
    }    
  }
}

The module has been carefully designed for extensibility.

Please see the API documentation and section 6.2 of README.txt

ygg’s picture

That would be great if I could just plug that in and go. Maybe I just don't understand this, but I can't get that to do anything. It won't get any of my Domain User info or anything.

Also, I did upgrade to 5.x-1.0 sorry I had missed the update.

agentrickard’s picture

You need to be more clear about what you mean by "my Domain User info."

That code doesn't do anything because there is nothing inside the IF loop except a comment where you can put the code you want.

ygg’s picture

Right, I understand I had to put something in there. The "my Domain User info." I meant was the profile fields that I have added. I can get them in the page.tpl file, but not into the block.

What would I need to put inside that block? I put a print $domain_user->profile_field_i_made; inside of it, but that did nothing. I tried some other things, but seemingly got nowhere.

What i'm saying is maybe that the same $domain_user->profile_field_i_made; snippet of code I'm able to use in the page.tpl would also be accessible in a block.

agentrickard’s picture

You have to create the full $domain_user object with user_load on the UID, taken from $_domain['uid'].

Then run a profile_load_profile().

http://api.drupal.org/api/function/profile_load_profile/5
http://api.drupal.org/api/function/user_load/5

Something like:

$domain_user = profile_load_profile(user_load(array('uid' => $_domain['uid'])));

It would be very wasteful to do this in the main code any time a domain is loaded.

ygg’s picture

I guess i'm just dumb...I can't figure this out at all.

Here is what I have so far and all I want is to pull a created profile field into a block.

<?php
$domains = domain_domains();
if (!empty($domains)) {
  foreach ($domains as $domain) {
    if (isset($domain['uid'])) {
      $domain_user = profile_load_profile(user_load(array('uid' => $_domain['uid'])));
    }   
  }
}
?>
<?php print $domain_user->profile_state; ?>

I'm probably way off with this. I'm not much on PHP, but trying to learn more. All I know is the process it needs to do maybe, but not how to get it to do it.

Thanks for the help in advance.

agentrickard’s picture

Right. You are mixing the two code snippets. Read up on PHP global variables.

You just want to grab the user of the _current_ domain, right?

So use:

// access the current domain global
global $_domain;

// Are we on a user domain?
if (isset($_domain['uid'])) {
  $account = user_load(array('uid' => $_domain['uid']));
  $domain_user = profile_load_profile($account);
  
  // Show the fields we want
  print $domain_user->profile_state;
  // and so on
}
agentrickard’s picture

Status: Active » Closed (fixed)

Might be a nice feature for a later release.

Feature request welcome.