Vitalii Zinenko vzinenko@adyax.com
Andrey Postnikov apostnikov@gmail.com
Capabilities
Possible issues:
Domain access vs Multi-site:
Multi-site
Domain Access
Installing module. You should know:
<VirtualHost *:80>
DocumentRoot /path/to/drupal/install
ServerName drupal8.test
ServerAlias *.drupal8.test drupal8.test
</VirtualHost>
sudo nano /etc/hosts
127.0.0.1 domain1.drupal8.test
127.0.0.1 domain2.drupal8.test
127.0.0.1 domain3.drupal8.test
127.0.0.1 another-domain.test
Installing on shared hosting with Cpanel:
Installing module:
$settings['trusted_host_patterns'] = array(
'^*\.drupal8\.test$',
'^another-domain\.test$',
);
View permissions:
Provided blocks:
Manage domains in BO:
Set domain for Entity:
Available hooks:
/**
* Notifies other modules that we are loading a domain record from the database.
*
* When using this hook, you should invoke the namespace with:
*
* use Drupal\domain\DomainInterface;
*
* @param array $domains
* An array of $domain record objects.
*/
function hook_domain_load(array $domains) {
// Add a variable to the $domain.
foreach ($domains as $domain) {
$domain->addProperty('myvar', 'mydomainvar');
}
}
/**
* Allows modules to modify the inbound domain request.
*
* When using this hook, first check $domain->getMatchType(), which returns a
* numeric constant indicating the type of match derived by the caller or by
* earlier returns of this hook (such as domain_alias_request_alter()).
* Use this value to determine if the request needs to be overridden. Valid
* types are DomainNegotiator::DOMAIN_MATCH_NONE,
* DomainNegotiator::DOMAIN_MATCH_EXACT, DomainNegotiator::DOMAIN_MATCH_ALIAS.
*/
function hook_domain_request_alter(\Drupal\domain\DomainInterface &$domain) {
// Add a special case to the example domain.
if ($domain->getMatchType() == \Drupal\domain\DomainNegotiator::DOMAIN_MATCH_EXACT && $domain->id() == 'example_com') {
// Do something here.
$domain->addProperty('foo', 'Bar');
}
}
/**
* Adds administrative operations for the domain overview form.
*
* These operations are only available to users who can administer the domain.
* That access check happens prior to this hook being called. If your use-case
* requires additional permission checking, you should provide it before
* returning any values.
*/
function hook_domain_operations(\Drupal\domain\DomainInterface $domain, \Drupal\Core\Session\AccountInterface $account) {
$operations = [];
// Check permissions.
if ($account->hasPermission('view domain aliases') || $account->hasPermission('administer domain aliases')) {
// Add aliases to the list.
$id = $domain->id();
$operations['domain_alias'] = array(
'title' => t('Aliases'),
'url' => Url::fromRoute('domain_alias.admin', array('domain' => $id)),
'weight' => 60,
);
}
return $operations;
}
/**
* Alter the list of domains that may be referenced.
*
* Note that this hook does not fire for users with the 'administer domains'
* permission.
*
*/
function hook_domain_references_alter($query, $account, $context) {
// Remove the default domain from non-admins when editing nodes.
if ($context['entity_type'] == 'node' && $context['field_type'] == 'editor' && !$account->hasPermission('edit assigned domains')) {
$default = \Drupal::service('domain.loader')->loadDefaultId();
$query->condition('id', $default, '<>');
}
}
/**
* Alter the validation step of a domain record.
*
* This hook allows modules to change or extend how domain validation
* happens. Most useful for international domains or other special cases
* where a site wants to restrict domain creation is some manner.
*
*/
function hook_domain_validate_alter(&$error_list, $hostname) {
// Only allow TLDs to be .org for our site.
if (substr($hostname, -4) != '.org') {
$error_list[] = t('Only .org domains may be registered.');
}
}
Submodules:
Created modules:
Questions?
usefull links
https://www.drupal.org/project/domain
https://github.com/agentrickard/domain
Vitalii Zinenko vzinenko@adyax.com
Andrey Postnikov apostnikov@gmail.com