? 540584-domain-source.patch
? 561282-views-filtering.patch
? 576444-select-list-format.patch
Index: domain_source/domain_source.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_source/domain_source.module,v
retrieving revision 1.13
diff -u -p -r1.13 domain_source.module
--- domain_source/domain_source.module	31 May 2009 18:16:41 -0000	1.13
+++ domain_source/domain_source.module	4 Oct 2009 22:56:15 -0000
@@ -14,6 +14,8 @@
  * @ingroup domain_source
  */
 
+define('DOMAIN_SOURCE_USE_ACTIVE', -5);
+
 /**
  * Implement hook_form_alter()
  */
@@ -21,8 +23,15 @@ function domain_source_form_alter(&$form
   // Apply to all node editing forms, but make sure we are not on the CCK field configuration form.
   // See http://drupal.org/node/186624.
   if ($form['#id'] == 'node-form' && !isset($form['#node']->cck_dummy_node_form)) {
-    global $_domain;
+    global $_domain, $user;
+    $account = $user;
+    domain_get_user_domains($account);
+    // Only uses with 'set domain access' can assign content to all affilaites, so they get a new option.
+    // This option allows domain source to be ignored on a per-node basis.
     $options = array();
+    if (user_access('set domain access')) {
+      $options[DOMAIN_SOURCE_USE_ACTIVE] = t('Use active domain');
+    }
     $domains = domain_domains();
     $show = FALSE;
     if (user_access('set domain access')) {
@@ -32,24 +41,28 @@ function domain_source_form_alter(&$form
       }
     }
     // In the case of users with limited permissions, option 3 is the "show options" value.
-    else if (user_access('publish to any assigned domain')) {
-      global $user;
+    else if (user_access('publish to any assigned domains') && !empty($account->domain_user)) {
       // Get the user's allowed domains.
       foreach ($domains as $domain) {
-        if ($user->domain_user[$domain['domain_id']] != 0 && $domain['domain_id'] == $user->domain_user[$domain['domain_id']]) {
-          $options[$domain['domain_id']] = $domain['sitename'];
+        $key = $domain['domain_id'];
+        if ($domain['domain_id'] == 0) {
+          $key = -1;
+        }
+        if ($account->domain_user[$key] != 0 && $key == $account->domain_user[$key]) {
+          $options[$key] = $domain['sitename'];
         }
       }
       // Is this node assigned to a source that the user can control?
       $source = $form['#node']->domain_source;
       if (isset($source)) {
-        if ($user->domain_user[$domain['domain_id']] == $source) {
+        if ($account->domain_user[$source] == $source) {
           $show = TRUE;
         }
         else {
+          $name = ($source != -5) ? $domains[$source]['sitename'] : t('the active domain');
           $form['domain']['domain_source_notes'] = array(
             '#value' => '<label><b>'. t('Source domain:') .'</b></label><div class="description">'.
-              t('This content is assigned to %domain and cannot be reassigned.', array('%domain' => $domains[$source]['sitename'])) .'</div>',
+              t('This content is assigned to %domain and cannot be reassigned.', array('%domain' => $name)) .'</div>',
           );
         }
       }
@@ -98,6 +111,7 @@ function domain_source_form_alter(&$form
  * Implement hook_nodeapi()
  */
 function domain_source_nodeapi(&$node, $op, $a3, $a4) {
+  global $_domain;
   switch ($op) {
     case 'validate':
       // If not set, we ignore.
@@ -112,13 +126,16 @@ function domain_source_nodeapi(&$node, $
       }
       // Here we account for both the 'domains_raw' and 'domains' options.
       // If selected, these clauses will not be zero.
-      else if ((!empty($node->domains) && !$node->domains[$key]) || (!empty($node->domains_raw) && !in_array($key, $node->domains_raw))) {
+      else if ($node->domain_source != DOMAIN_SOURCE_USE_ACTIVE && (!empty($node->domains) && !$node->domains[$key]) || (!empty($node->domains_raw) && !in_array($key, $node->domains_raw))) {
         form_set_error('domain_source', t('The source affiliate must be selected as a publishing option.'));
       }
+      // If 'Use active domain' is selected, then the node must be viewable on all affiliates.
+      if ($node->domain_source == DOMAIN_SOURCE_USE_ACTIVE && !$node->domain_site) {
+        form_set_error('domain_source', t('Only content viewable by all affiliates may be assigned to the active domain.'));
+      }
       break;
     case 'insert':
     case 'update':
-      global $_domain;
       // If not set, we came from a drupal_execute() or other external call, so use the current domain.
       if (!isset($node->domain_source)) {
         $node->domain_source = $_domain['domain_id'];
@@ -137,6 +154,10 @@ function domain_source_nodeapi(&$node, $
       if (empty($source)) {
         $node->domain_source = variable_get('domain_default_source', 0);
       }
+      // DOMAIN_SOURCE_USE_ACTIVE is the status for 'Use active domain.'
+      else if ($source == DOMAIN_SOURCE_USE_ACTIVE){
+        $node->domain_source = $_domain['domain_id'];
+      }
       else {
         $node->domain_source = $source['domain_id'];
       }
