function domain_save in Domain Access 7.3
Same name and namespace in other branches
- 6.2 domain.module \domain_save()
- 7.2 domain.module \domain_save()
Save a domain record.
Parameters
$values: Form value information required to edit a domain.
$form_values: Form values passed to the submit handler. May be used by other modules.
Return value
$domain array on success or -1 on failure.
10 calls to domain_save()
- DomainCreateTest::testDomainSave in tests/
domain.test - DomainHookTest::testDomainHooks in tests/
domain.test - DomainInvalidTest::testDomainInvalid in tests/
domain.test - DomainTestCase::domainCreateDomains in tests/
domain.test - Helper function to create domains.
- domain_features_rebuild in ./
domain.features.inc - Implements hook_features_rebuild().
1 string reference to 'domain_save'
- MigrateDestinationDomain::import in ./
domain.migrate.inc - Import a single row.
File
- ./
domain.module, line 943 - Core module functions for the Domain Access suite.
Code
function domain_save($values, $form_values = array()) {
// Must this be the default domain?
// Used in cases where there are no domains present.
$count = (bool) db_query("SELECT COUNT(domain_id) FROM {domain} WHERE is_default = 1")
->fetchField();
if (!$count) {
$values['is_default'] = 1;
}
// Ensure we have a machine name.
if (!isset($values['machine_name'])) {
$values['machine_name'] = domain_machine_name($values['subdomain']);
}
// Update or insert a record?
if (!empty($values['domain_id'])) {
$action = 'domain_update';
$update_id = array(
'domain_id',
);
}
else {
$action = 'domain_insert';
$update_id = array();
}
// If this is the default domain, reset other domains.
if (!empty($values['is_default'])) {
db_update('domain')
->fields(array(
'is_default' => 0,
))
->condition('machine_name', $values['machine_name'], '<>')
->execute();
}
// Store the data, using the machine_name to generate a numeric id.
// Note that we _must_ have a numeric key for {node_access}.
drupal_write_record('domain_export', $values, $update_id);
drupal_write_record('domain', $values, $update_id);
// Let other modules act on a proper copy of the domain.
$domain = domain_lookup(NULL, $values['subdomain'], TRUE);
module_invoke_all($action, $domain, $form_values);
// Lookup the modified record and return it.
$domain = domain_lookup(NULL, $values['subdomain'], TRUE);
// Clear static caches.
domain_static_reset();
// In all cases, we need to force a menu rebuild, which also clears the cache.
variable_set('menu_rebuild_needed', TRUE);
return $domain;
}