function domain_get_node_defaults in Domain Access 7.3
Returns default node access settings, ready for a node object.
Use domain_default_node_access_settings() when you need those settings in forms, or when you look for default access settings in general.
First level keys are
- 'domain_site' (publish to all affiliates) with value TRUE or FALSE.
- 'domain_id' contains the assigned affiliates, where both keys and values are the domain id.
Array of assigned domains can be empty, but only if an admin explicitly defined this. Use $fallback_domains to prevent zero assignments. See domain_default() as an example for a possible fallback domain.
Parameters
$type: The type of the node (like 'article').
$fallback_domains (optional): An array of domains which are used if no default domain is assigned.
Return value
An array of default settings, formatted as explained above.
See also
domain_default_node_access_settings()
3 calls to domain_get_node_defaults()
- domain_form_alter in ./
domain.module - Implements hook_form_alter().
- domain_node_access_records in ./
domain.module - Implements hook_node_access_records().
- domain_node_load in ./
domain.module - Implements hook_node_load().
File
- ./
domain.module, line 4285 - Core module functions for the Domain Access suite.
Code
function domain_get_node_defaults($type, $fallback_domains = array()) {
$_domain = domain_get_domain();
$defaults = array(
'domain_id' => array(),
);
// We use array_flip for compatibility with node_type_form_submit().
$settings = array_flip(domain_default_node_access_settings($type));
$defaults['domain_site'] = isset($settings['DOMAIN_ALL']) ? TRUE : FALSE;
// Assign the currently active domain, if not disabled by user.
if (isset($settings['DOMAIN_ACTIVE'])) {
$defaults['domain_id'][$_domain['domain_id']] = $_domain['domain_id'];
}
// Assign the default affiliates.
foreach ($settings as $key => $value) {
if ($key != 'DOMAIN_ACTIVE' && $key != 'DOMAIN_ALL') {
if ($domain = domain_machine_name_load($key)) {
$defaults['domain_id'][$domain['domain_id']] = $domain['domain_id'];
}
}
}
// Use fallback domains when no default affiliate exists.
if (empty($defaults['domain_id']) && !empty($fallback_domains)) {
foreach ($fallback_domains as $domain) {
$defaults['domain_id'][$domain['domain_id']] = $domain['domain_id'];
}
}
return $defaults;
}