Drupal Domain Access Automatically create subdomain using page title or Field

Date: 
Tuesday, May 15, 2018 - 18:15

The purpose is to allow Franchise Members to add a value to a field which would be automatically used to create a subdomain for their site.
To do this we may need a custom module. It would have to cover a few things:

- Hook into user creation to auto-create a domain record (domain.creator service).
- Assign permissions / access rules for domains. Domain Access adds fields to the User entity that could store this relationship.
- Restrict access control to domains that the user belongs.
https://www.drupal.org/project/domain/issues/2877422

Project: 
Status: 
inserted
Priority: 
normal

Comments

Posted by developer7 on 05/24/2018 - 11:32

Some code with additional issues and concerns: Please see https://www.drupal.org/project/domain/issues/1221776 before using this code
Domain name ==> the name to use, a text field
Subdomain string ==> the subdomain to prepend to 'example.com'.
function custom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// Assumes a CCK field has our data.
if ($op != 'insert' || empty($node->field_domain_name)) {
return;
}
$default = domain_default();
$domain = array(
'sitename' => $node->field_domain_name, // This may be an array that needs more handling.
'subdomain' => $node->field_domain_subdomain . '.' . $default['subdomain'],
// etc.
);
domain_save($domain, $domain); // Twice due to some legacy form stuff.
}

Project Management