Display site slogan in view?
BWPanda - May 22, 2009 - 05:53
| Project: | Domain Access |
| Version: | 6.x-2.0-rc8 |
| Component: | - Domain Views |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
I've setup a view that lists each of my domains with a link to it, but now I want to display each domain's slogan as well.
I looked through the API documentation and found domain_lookup(), but it doesn't list the slogan for each domain.
Is there something similar to a node_load() I can do for domains? Any assistance would be much appreciated!

#1
Assuming you're using domain_conf you could try domain_conf_variable_get($domain_id, $variable) which is in the HEAD.
#2
And that data is never exposed to Views, so you have to do it at the theme layer.
See #413950: Make domain_conf_variable_get() for the patch or install from HEAD.
#3
#4
Thanks for that. The patch failed to apply for me, so I just copied and pasted the function into the module file manually.
It seems to work well on all domains except the primary domain (ID #0). Nothing is displayed...
I could use an if statement to hard-code the slogan for the primary domain, but that's not ideal (slogan could change in future, etc.).
Any ideas?
#5
On the primary domain you should not use that function, just use variable_get().
Don't hard-code the slogan, just code in the logic to pull in the setting where you need it in your view theme.
#6
Is this what you meant?
<?phpif ($row->domain_id != 0) {
print domain_conf_variable_get($row->domain_id, 'site_slogan');
} else {
print variable_get('site_slogan', '');
}
?>
I've added that code to my views template file and it seems to be working fine now; all domains have their correct slogans listed.
Thanks!
(If the above code is correct and is the best way to do it, you can set this back to 'By design'.)
#7
Oops, I spoke too soon. It seems whichever domain I go to, it's slogan is displayed under the primary domain...
EDIT: I tried the following code, but that doesn't work properly either...
<?phpglobal $_domain;
if ($_domain['domain_id'] != 0) {
print domain_conf_variable_get($row->domain_id, 'site_slogan');
} else {
print variable_get('site_slogan', '');
}
?>
#8
I do not understand this sentence. Can you attach a screenshot?
#9
Using the code from #6 above, the result is the attached screenshot.
The slogan for Brat.info in the 'Our Websites' block is whatever the slogan of the current domain is.
Therefore, when you're on the Brat.info site, it works (left side of screenshot). However, when you're on another website, like CityCentreTravel.com, the slogan is that website's slogan (right side of screenshot).
Hopefully that helps explain it a bit better...
#10
@BWPanda Could you also attach a screenshot of your site slogans on batch updating screen?
#11
Here you go...
#12
Any progress on this?
I posted a recent issue here (#485762: Domain table views try to load NID) but was told that it's related to this issue. Whenever I clear my cache, I get the follow warning for each of my domains:
It doesn't happen normally, just when the cache is cleared.
I'm using the following code in my views-view-fields--Domains.tpl.php file:
<?php
/**
* Add slogan to each domain
*/
?>
<a href="http://<?php print $row->domain_subdomain; ?>"><?php print $row->domain_sitename; ?></a>
<br />
<?php
if ($row->domain_id != 0) {
print domain_conf_variable_get($row->domain_id, 'site_slogan');
} else {
print variable_get('site_slogan', '');
}
?>
#13
I ran into the error caused by domain_conf_variable_get today myself as well. So the issue is not with the view but with domain_conf_variable_get() function.
More to follow as I try to find out what's going on here.
#14
That would indicate that you are using outdated code. Upgrade to rc8.
There is an array_merge on line 563 now, and the problem is that the function
_domain_conf_load_primary()is trying to read the default site variables from the {cache} table.If the cache is cleared, this fails, so we obviously need some logic to rebuild the $conf array from the {variable} table directly.
Around line 623, we need some logic like so:
<?php// Load the query.
$data = db_result(db_query("SELECT data FROM $cache_table WHERE cid = 'variables'"));
if (!empty($data)) {
$settings = unserialize($data);
}
else {
$var_table = db_escape_table($db_prefix['default'] .'variable');
$result = db_query("SELECT name, value FROM $var_table");
while ($vars = db_fetch_array($result)) {
$data[$vars['name']] = unserialize($vars['value']);
}
}
?>
Note that we build the table name dynamically instead of using {} to account for Domain Prefix.
#15
#16
Not sure which of us you were talking to regarding RC8, but my site's already running it.
Is that code ready to be made into a patch to test, or doesn't work yet...?
#17
It is stub code that should be rolled into a patch. It should be right but has not been tested.
#18
Here are patches against RC8 and HEAD. I've tested the HEAD version only.
#19
Hm. Now there is a double unserialize... We should move the $settings = inside the IF loop.
#20
You are right, there's no reason to unserialize twice.
/me needs more coffee.
#21
Here is an optimized version of the patch against HEAD.
This should be ready to commit.
#22
Here is a better patch, which moves the table escape function into the bootstrap, since we actually need it there. Now other modules can call the function if they need to.
Committed to HEAD.
Nice work all!
#23
Thanks agentrickard, array_merge() warnings gone!
However, I'm still having the issue of my primary domain displaying the slogan for the current site in my view, as described in #9 above...
#24
If you are unsure that you are on the primary domain, you must use domain_conf_variable_get(0, NAME_OF_VAR);
variable_get() will always return the value for the active domain.
#25
#26
Thanks, that worked!
I'm not sure why I had different code for the primary domain (#4 above seems to suggest I was having problems with it), but with just the one
domain_conf_variable_get($row->domain_id, 'site_slogan')function, all slogans are displaying properly. Maybe your patches fixed it...Thanks again!
#27
It was just a bit of confusion about which domain the View was being loaded on. If you are unsure, you always must use domain_conf_variable_get().
#28
Automatically closed -- issue fixed for 2 weeks with no activity.