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

nonsie - May 22, 2009 - 13:16

Assuming you're using domain_conf you could try domain_conf_variable_get($domain_id, $variable) which is in the HEAD.

#2

agentrickard - May 22, 2009 - 17:58

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

agentrickard - May 22, 2009 - 17:58
Status:active» by design

#4

BWPanda - May 25, 2009 - 04:46
Status:by design» active

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

agentrickard - May 25, 2009 - 17:21

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

BWPanda - May 26, 2009 - 01:52

Is this what you meant?

<?php
if ($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

BWPanda - May 26, 2009 - 02:35

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...

<?php
 
global $_domain;
  if (
$_domain['domain_id'] != 0) {
    print
domain_conf_variable_get($row->domain_id, 'site_slogan');
  } else {
    print
variable_get('site_slogan', '');
  }
?>

#8

Pasqualle - May 28, 2009 - 18:25

It seems whichever domain I go to, it's slogan is displayed under the primary domain.

I do not understand this sentence. Can you attach a screenshot?

#9

BWPanda - May 28, 2009 - 23:26

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...

AttachmentSize
domain_slogans.png 35.63 KB

#10

nonsie - May 29, 2009 - 00:21

@BWPanda Could you also attach a screenshot of your site slogans on batch updating screen?

#11

BWPanda - May 29, 2009 - 00:43

Here you go...

AttachmentSize
domain_slogans_2.png 52.17 KB

#12

BWPanda - June 25, 2009 - 03:40

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:

warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/brat/public_html/sites/all/modules/domain/domain_conf/domain_conf.module on line 561.

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

nonsie - June 25, 2009 - 04:00

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

agentrickard - June 25, 2009 - 14:00

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

agentrickard - June 25, 2009 - 13:59
Category:support request» bug report
Status:active» needs work

#16

BWPanda - June 25, 2009 - 23:12
Version:6.x-2.0-rc6» 6.x-2.0-rc8

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

agentrickard - June 26, 2009 - 13:58

It is stub code that should be rolled into a patch. It should be right but has not been tested.

#18

nonsie - June 26, 2009 - 17:04

Here are patches against RC8 and HEAD. I've tested the HEAD version only.

AttachmentSize
469856_contributions-modules-domain-HEAD.patch 1002 bytes
469856_contributions-modules-domain-DRUPAL-6--2-0-RC8.patch 1002 bytes

#19

agentrickard - June 26, 2009 - 17:12

Hm. Now there is a double unserialize... We should move the $settings = inside the IF loop.

#20

nonsie - June 26, 2009 - 17:17

You are right, there's no reason to unserialize twice.
/me needs more coffee.

AttachmentSize
469856_contributions-modules-domain-DRUPAL-6--2-0-RC8.patch 1.02 KB
469856_contributions-modules-domain-HEAD.patch 1.02 KB

#21

agentrickard - June 27, 2009 - 14:49
Status:needs work» needs review

Here is an optimized version of the patch against HEAD.

This should be ready to commit.

AttachmentSize
469856-domain-conf-variable-get.patch 2.52 KB

#22

agentrickard - June 28, 2009 - 15:21
Status:needs review» fixed

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!

AttachmentSize
469856-primary-table.patch 4.32 KB

#23

BWPanda - June 28, 2009 - 23:26
Status:fixed» active

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

agentrickard - June 29, 2009 - 00:21

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

agentrickard - June 29, 2009 - 00:24
Status:active» fixed

#26

BWPanda - June 29, 2009 - 00:34

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

agentrickard - June 29, 2009 - 01:50

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

System Message - July 13, 2009 - 02:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.