? 540684-domain-source.patch
? 561282-views-filtering.patch
? 564070-source.patch
? 609600-sitename.patch
? big.redirect.patch
? test.patch
Index: domain_source/domain_source.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_source/domain_source.module,v
retrieving revision 1.15
diff -u -p -r1.15 domain_source.module
--- domain_source/domain_source.module	15 Oct 2009 13:56:47 -0000	1.15
+++ domain_source/domain_source.module	20 Oct 2009 18:10:59 -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 domain') && !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 (isset($user->domain_user[$source]) && $user->domain_user[$source] == $source) {
+      if (isset($source) && isset($account->domain_user[$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.
@@ -119,9 +133,13 @@ function domain_source_nodeapi(&$node, $
         // I find this code easier to read than a compound IF statement.
       }
       // Here we account for both the 'domains_raw' and 'domains' options.
-      else if (!in_array($key, $allowed)) {
+      else if ($node->domain_source != DOMAIN_SOURCE_USE_ACTIVE && !in_array($key, $allowed)) {
         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':
@@ -144,6 +162,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'];
       }
