added domain_menu_access, updated domain to last dev
This commit is contained in:
@@ -4,22 +4,22 @@ sudo: false
|
|||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
- env: DRUPAL=8.4.x
|
- env: DRUPAL=8.5.x
|
||||||
php: 7.1
|
|
||||||
- env: DRUPAL=8.4.x
|
|
||||||
php: 7.0
|
|
||||||
- env: DRUPAL=8.4.x
|
|
||||||
php: 5.6
|
|
||||||
- env: DRUPAL=8.4.x
|
|
||||||
php: 5.5
|
php: 5.5
|
||||||
- env: DRUPAL=8.5.x
|
|
||||||
php: 7.1
|
|
||||||
- env: DRUPAL=8.5.x
|
|
||||||
php: 7.0
|
|
||||||
- env: DRUPAL=8.5.x
|
- env: DRUPAL=8.5.x
|
||||||
php: 5.6
|
php: 5.6
|
||||||
- env: DRUPAL=8.5.x
|
- env: DRUPAL=8.5.x
|
||||||
|
php: 7.1
|
||||||
|
- env: DRUPAL=8.5.x
|
||||||
|
php: 7.2
|
||||||
|
- env: DRUPAL=8.6.x
|
||||||
php: 5.5
|
php: 5.5
|
||||||
|
- env: DRUPAL=8.6.x
|
||||||
|
php: 5.6
|
||||||
|
- env: DRUPAL=8.6.x
|
||||||
|
php: 7.1
|
||||||
|
- env: DRUPAL=8.6.x
|
||||||
|
php: 7.2
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
hosts:
|
hosts:
|
||||||
@@ -76,6 +76,9 @@ before_script:
|
|||||||
- travis_retry drush dl drupal-$DRUPAL --drupal-project-rename=drupal
|
- travis_retry drush dl drupal-$DRUPAL --drupal-project-rename=drupal
|
||||||
- cd drupal
|
- cd drupal
|
||||||
|
|
||||||
|
# Update PHPUnit.
|
||||||
|
- composer run-script drupal-phpunit-upgrade
|
||||||
|
|
||||||
# Make the module appear in the correct place
|
# Make the module appear in the correct place
|
||||||
- ln -s $TESTDIR modules/domain
|
- ln -s $TESTDIR modules/domain
|
||||||
|
|
||||||
@@ -91,11 +94,11 @@ before_script:
|
|||||||
- until curl -s example.com:8080; do true; done > /dev/null
|
- until curl -s example.com:8080; do true; done > /dev/null
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Kernel" --php `which php` --url http://example.com:8080 domain
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Kernel" --php `which php` --url http://example.com:8080 domain
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_access
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_access
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_alias
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_alias
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Kernel" --php `which php` --url http://example.com:8080 domain_alias
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Kernel" --php `which php` --url http://example.com:8080 domain_alias
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_config
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_config
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_content
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_content
|
||||||
- php core/scripts/run-tests.sh --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_source
|
- php core/scripts/run-tests.sh --suppress-deprecations --verbose --color --concurrency 4 --types "PHPUnit-Functional" --php `which php` --url http://example.com:8080 domain_source
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ Changelog
|
|||||||
01-DEC-2017 8.x-1.0-alpha10
|
01-DEC-2017 8.x-1.0-alpha10
|
||||||
19-DEC-2017 8.x-1.0-alpha11
|
19-DEC-2017 8.x-1.0-alpha11
|
||||||
12-FEB-2018 8.x-1.0-alpha12
|
12-FEB-2018 8.x-1.0-alpha12
|
||||||
07-MAR-2018 8.x.1.0-alpha13
|
07-MAR-2018 8.x-1.0-alpha13
|
||||||
|
19-OCT-2018 8.x-1.0-alpha14
|
||||||
|
|
||||||
Status
|
Status
|
||||||
====
|
====
|
||||||
@@ -118,7 +119,6 @@ marked with [x] are considered complete.
|
|||||||
- [ ] Caching strategies in DomainNegotiator
|
- [ ] Caching strategies in DomainNegotiator
|
||||||
- [ ] Caching strategies in DomainConfigOverrides
|
- [ ] Caching strategies in DomainConfigOverrides
|
||||||
- [ ] Cache in the DomainAccessManager
|
- [ ] Cache in the DomainAccessManager
|
||||||
- [ ] Add filter options to domain_access and domain_source views
|
|
||||||
- [ ] Proper handling of default node values
|
- [ ] Proper handling of default node values
|
||||||
- [ ] Do not allow actions to be edited?
|
- [ ] Do not allow actions to be edited?
|
||||||
- [o] Recreate the Domain Theme module -- see https://www.drupal.org/project/domain_theme_switch
|
- [o] Recreate the Domain Theme module -- see https://www.drupal.org/project/domain_theme_switch
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ Current Status
|
|||||||
|
|
||||||
Domain module for Drupal port to Drupal 8, under active development.
|
Domain module for Drupal port to Drupal 8, under active development.
|
||||||
|
|
||||||
Active branch is 8-x.1-x. Begin any forks from there.
|
Domain required Drupal 8.5 or higher.
|
||||||
|
|
||||||
|
Active branch is the 8-x.1-x branch in GitHub. Begin any forks from there.
|
||||||
|
|
||||||
The underlying API is stable, and it's currently usable for access control.
|
The underlying API is stable, and it's currently usable for access control.
|
||||||
The configuration supports manual editing. Themes should work. Views and Bulk
|
The configuration supports manual editing. Themes should work. Views and Bulk
|
||||||
@@ -37,9 +39,6 @@ Included modules
|
|||||||
`environment`, so that different hosts are used consistently across development
|
`environment`, so that different hosts are used consistently across development
|
||||||
environments. See the README file for Domain Alias for more information.
|
environments. See the README file for Domain Alias for more information.
|
||||||
|
|
||||||
* *Domain Alpha*
|
|
||||||
Provides limited alpha-to-alpha updates. Recommended.
|
|
||||||
|
|
||||||
* *Domain Config*
|
* *Domain Config*
|
||||||
Provides a means for changing configuration settings on a per-domain basis. See the
|
Provides a means for changing configuration settings on a per-domain basis. See the
|
||||||
README for Domain Config for more information.
|
README for Domain Config for more information.
|
||||||
@@ -54,17 +53,6 @@ Included modules
|
|||||||
the module's README for more information.
|
the module's README for more information.
|
||||||
|
|
||||||
|
|
||||||
Alpha release updates
|
|
||||||
------
|
|
||||||
|
|
||||||
A limited set of updates are provided for major architecture changes during the
|
|
||||||
alpha release.
|
|
||||||
|
|
||||||
You can run these updates by enabling the `domain_alpha` module and running
|
|
||||||
Drupal's database updates. The updates and affected versions are:
|
|
||||||
|
|
||||||
* Update 8001: Affects versions of Alpha6 or lower.
|
|
||||||
|
|
||||||
Implementation Notes
|
Implementation Notes
|
||||||
======
|
======
|
||||||
|
|
||||||
@@ -241,4 +229,3 @@ in most test cases. See `DomainTestBase::domainCreateTestDomains()` for the logi
|
|||||||
When running tests, you normally need to be on the default domain.
|
When running tests, you normally need to be on the default domain.
|
||||||
|
|
||||||
If anyone is capable of building a vagrant box to simplify testing, that would be ideal.
|
If anyone is capable of building a vagrant box to simplify testing, that would be ideal.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
allow_non_ascii: false
|
allow_non_ascii: false
|
||||||
www_prefix: false
|
www_prefix: false
|
||||||
login_paths: '/user/login\r\n/user/password'
|
login_paths: "/user/login\r\n/user/password"
|
||||||
css_classes: ''
|
css_classes: ''
|
||||||
|
|||||||
@@ -83,3 +83,13 @@ condition.plugin.domain:
|
|||||||
sequence:
|
sequence:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
views.access.domain:
|
||||||
|
type: mapping
|
||||||
|
label: 'Domains'
|
||||||
|
mapping:
|
||||||
|
domain:
|
||||||
|
type: sequence
|
||||||
|
label: 'List of domains'
|
||||||
|
sequence:
|
||||||
|
type: string
|
||||||
|
label: 'Domain'
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
*
|
*
|
||||||
* use Drupal\domain\DomainInterface;
|
* use Drupal\domain\DomainInterface;
|
||||||
*
|
*
|
||||||
* @param array $domains
|
* @param \Drupal\domain\DomainInterface[] $domains
|
||||||
* An array of $domain record objects.
|
* An array of $domain record objects.
|
||||||
*/
|
*/
|
||||||
function hook_domain_load(array $domains) {
|
function hook_domain_load(array $domains) {
|
||||||
@@ -70,11 +70,11 @@ function hook_domain_operations(\Drupal\domain\DomainInterface $domain, \Drupal\
|
|||||||
if ($account->hasPermission('view domain aliases') || $account->hasPermission('administer domain aliases')) {
|
if ($account->hasPermission('view domain aliases') || $account->hasPermission('administer domain aliases')) {
|
||||||
// Add aliases to the list.
|
// Add aliases to the list.
|
||||||
$id = $domain->id();
|
$id = $domain->id();
|
||||||
$operations['domain_alias'] = array(
|
$operations['domain_alias'] = [
|
||||||
'title' => t('Aliases'),
|
'title' => t('Aliases'),
|
||||||
'url' => Url::fromRoute('domain_alias.admin', array('domain' => $id)),
|
'url' => \Drupal\Core\Url::fromRoute('domain_alias.admin', ['domain' => $id]),
|
||||||
'weight' => 60,
|
'weight' => 60,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $operations;
|
return $operations;
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,9 @@ function hook_domain_operations(\Drupal\domain\DomainInterface $domain, \Drupal\
|
|||||||
*
|
*
|
||||||
* NOTE: This does not apply to Domain Alias records.
|
* NOTE: This does not apply to Domain Alias records.
|
||||||
*
|
*
|
||||||
|
* No return value. Modify $error_list by reference. Return an empty array
|
||||||
|
* or NULL to validate this domain.
|
||||||
|
*
|
||||||
* @param array &$error_list
|
* @param array &$error_list
|
||||||
* The list of current validation errors. Modify this value by reference.
|
* The list of current validation errors. Modify this value by reference.
|
||||||
* If you return an empty array or NULL, the domain is considered valid.
|
* If you return an empty array or NULL, the domain is considered valid.
|
||||||
@@ -96,12 +99,9 @@ function hook_domain_operations(\Drupal\domain\DomainInterface $domain, \Drupal\
|
|||||||
* Note that this is checked for uniqueness separately. This value is not
|
* Note that this is checked for uniqueness separately. This value is not
|
||||||
* modifiable.
|
* modifiable.
|
||||||
*
|
*
|
||||||
* No return value. Modify $error_list by reference. Return an empty array
|
|
||||||
* or NULL to validate this domain.
|
|
||||||
*
|
|
||||||
* @see domain_valid_domain()
|
* @see domain_valid_domain()
|
||||||
*/
|
*/
|
||||||
function hook_domain_validate_alter(&$error_list, $hostname) {
|
function hook_domain_validate_alter(array &$error_list, $hostname) {
|
||||||
// Only allow TLDs to be .org for our site.
|
// Only allow TLDs to be .org for our site.
|
||||||
if (substr($hostname, -4) != '.org') {
|
if (substr($hostname, -4) != '.org') {
|
||||||
$error_list[] = t('Only .org domains may be registered.');
|
$error_list[] = t('Only .org domains may be registered.');
|
||||||
@@ -114,6 +114,8 @@ function hook_domain_validate_alter(&$error_list, $hostname) {
|
|||||||
* Note that this hook does not fire for users with the 'administer domains'
|
* Note that this hook does not fire for users with the 'administer domains'
|
||||||
* permission.
|
* permission.
|
||||||
*
|
*
|
||||||
|
* No return value. Modify the $query object via methods.
|
||||||
|
*
|
||||||
* @param \Drupal\Core\Entity\Query\QueryInterface $query
|
* @param \Drupal\Core\Entity\Query\QueryInterface $query
|
||||||
* An entity query prepared by DomainSelection::buildEntityQuery().
|
* An entity query prepared by DomainSelection::buildEntityQuery().
|
||||||
* @param \Drupal\Core\Session\AccountInterface $account
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
@@ -126,13 +128,11 @@ function hook_domain_validate_alter(&$error_list, $hostname) {
|
|||||||
* 'editor' for assigning editorial permissions (as in Domain Access)
|
* 'editor' for assigning editorial permissions (as in Domain Access)
|
||||||
* 'admin' for assigning administrative permissions for a specific domain.
|
* 'admin' for assigning administrative permissions for a specific domain.
|
||||||
* Most contributed modules will use 'editor'.
|
* Most contributed modules will use 'editor'.
|
||||||
*
|
|
||||||
* No return value. Modify the $query object via methods.
|
|
||||||
*/
|
*/
|
||||||
function hook_domain_references_alter($query, $account, $context) {
|
function hook_domain_references_alter(\Drupal\Core\Entity\Query\QueryInterface $query, \Drupal\Core\Session\AccountInterface $account, array $context) {
|
||||||
// Remove the default domain from non-admins when editing nodes.
|
// Remove the default domain from non-admins when editing nodes.
|
||||||
if ($context['entity_type'] == 'node' && $context['field_type'] == 'editor' && !$account->hasPermission('edit assigned domains')) {
|
if ($context['entity_type'] == 'node' && $context['field_type'] == 'editor' && !$account->hasPermission('edit assigned domains')) {
|
||||||
$default = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultId();
|
$default = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultId();
|
||||||
$query->condition('id', $default, '<>');
|
$query->condition('id', $default, '<>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,146 +13,146 @@ use GuzzleHttp\Exception\RequestException;
|
|||||||
* Implements hook_drush_command().
|
* Implements hook_drush_command().
|
||||||
*/
|
*/
|
||||||
function domain_drush_command() {
|
function domain_drush_command() {
|
||||||
$items = array();
|
$items = [];
|
||||||
|
|
||||||
$items['domain-list'] = array(
|
$items['domain-list'] = [
|
||||||
'description' => 'List active domains for the site.',
|
'description' => 'List active domains for the site.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-list',
|
'drush domain-list',
|
||||||
'drush domains',
|
'drush domains',
|
||||||
),
|
],
|
||||||
'aliases' => array('domains'),
|
'aliases' => ['domains'],
|
||||||
);
|
];
|
||||||
$items['domain-add'] = array(
|
$items['domain-add'] = [
|
||||||
'description' => 'Add a new domain to the site.',
|
'description' => 'Add a new domain to the site.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-add example.com \'My Test Site\'',
|
'drush domain-add example.com \'My Test Site\'',
|
||||||
'drush domain-add example.com \'My Test Site\' --inactive=1 --https==1',
|
'drush domain-add example.com \'My Test Site\' --inactive=1 --https==1',
|
||||||
'drush domain-add example.com \'My Test Site\' --weight=10',
|
'drush domain-add example.com \'My Test Site\' --weight=10',
|
||||||
'drush domain-add example.com \'My Test Site\' --validate=1',
|
'drush domain-add example.com \'My Test Site\' --validate=1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'hostname' => 'The domain hostname to register (e.g. example.com).',
|
'hostname' => 'The domain hostname to register (e.g. example.com).',
|
||||||
'name' => 'The name of the site (e.g. Domain Two).',
|
'name' => 'The name of the site (e.g. Domain Two).',
|
||||||
),
|
],
|
||||||
'options' => array(
|
'options' => [
|
||||||
'inactive' => 'Set the domain to inactive status if set.',
|
'inactive' => 'Set the domain to inactive status if set.',
|
||||||
'https' => 'Use https protocol for this domain if set.',
|
'https' => 'Use https protocol for this domain if set.',
|
||||||
'weight' => 'Set the order (weight) of the domain.',
|
'weight' => 'Set the order (weight) of the domain.',
|
||||||
'is_default' => 'Set this domain as the default domain.',
|
'is_default' => 'Set this domain as the default domain.',
|
||||||
'validate' => 'Force a check of the URL response before allowing registration.',
|
'validate' => 'Force a check of the URL response before allowing registration.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-delete'] = array(
|
$items['domain-delete'] = [
|
||||||
'description' => 'Delete a domain from the site.',
|
'description' => 'Delete a domain from the site.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-delete example.com',
|
'drush domain-delete example.com',
|
||||||
'drush domain-delete 1',
|
'drush domain-delete 1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain' => 'The numeric id or hostname of the domain to delete.',
|
'domain' => 'The numeric id or hostname of the domain to delete.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-test'] = array(
|
$items['domain-test'] = [
|
||||||
'description' => 'Tests domains for proper response. If run from a subfolder, you must specify the --uri.',
|
'description' => 'Tests domains for proper response. If run from a subfolder, you must specify the --uri.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-test',
|
'drush domain-test',
|
||||||
'drush domain-test example.com',
|
'drush domain-test example.com',
|
||||||
'drush domain-test 1',
|
'drush domain-test 1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to test. If no value is passed, all domains are tested.',
|
'domain_id' => 'The numeric id or hostname of the domain to test. If no value is passed, all domains are tested.',
|
||||||
),
|
],
|
||||||
'options' => array(
|
'options' => [
|
||||||
'base_path' => 'The subdirectory name if Drupal is installed in a folder other than server root.',
|
'base_path' => 'The subdirectory name if Drupal is installed in a folder other than server root.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-default'] = array(
|
$items['domain-default'] = [
|
||||||
'description' => 'Sets the default domain. If run from a subfolder, you must specify the --uri.',
|
'description' => 'Sets the default domain. If run from a subfolder, you must specify the --uri.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-default example.com',
|
'drush domain-default example.com',
|
||||||
'drush domain-default 1',
|
'drush domain-default 1',
|
||||||
'drush domain-default 1 --validate=1',
|
'drush domain-default 1 --validate=1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to make default.',
|
'domain_id' => 'The numeric id or hostname of the domain to make default.',
|
||||||
),
|
],
|
||||||
'options' => array(
|
'options' => [
|
||||||
'validate' => 'Force a check of the URL response before allowing registration.',
|
'validate' => 'Force a check of the URL response before allowing registration.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-disable'] = array(
|
$items['domain-disable'] = [
|
||||||
'description' => 'Sets a domain status to off.',
|
'description' => 'Sets a domain status to off.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-disable example.com',
|
'drush domain-disable example.com',
|
||||||
'drush domain-disable 1',
|
'drush domain-disable 1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to disable.',
|
'domain_id' => 'The numeric id or hostname of the domain to disable.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-enable'] = array(
|
$items['domain-enable'] = [
|
||||||
'description' => 'Sets a domain status to on.',
|
'description' => 'Sets a domain status to on.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-disable example.com',
|
'drush domain-disable example.com',
|
||||||
'drush domain-disable 1',
|
'drush domain-disable 1',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to enable.',
|
'domain_id' => 'The numeric id or hostname of the domain to enable.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-name'] = array(
|
$items['domain-name'] = [
|
||||||
'description' => 'Changes a domain label.',
|
'description' => 'Changes a domain label.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-name example.com Foo',
|
'drush domain-name example.com Foo',
|
||||||
'drush domain-name 1 Foo',
|
'drush domain-name 1 Foo',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to relabel.',
|
'domain_id' => 'The numeric id or hostname of the domain to relabel.',
|
||||||
'name' => 'The name to use for the domain.',
|
'name' => 'The name to use for the domain.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-machine-name'] = array(
|
$items['domain-machine-name'] = [
|
||||||
'description' => 'Changes a domain name.',
|
'description' => 'Changes a domain name.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-machine-name example.com foo',
|
'drush domain-machine-name example.com foo',
|
||||||
'drush domain-machine-name 1 foo',
|
'drush domain-machine-name 1 foo',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to rename.',
|
'domain_id' => 'The numeric id or hostname of the domain to rename.',
|
||||||
'name' => 'The machine-readable name to use for the domain.',
|
'name' => 'The machine-readable name to use for the domain.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['domain-scheme'] = array(
|
$items['domain-scheme'] = [
|
||||||
'description' => 'Changes a domain scheme.',
|
'description' => 'Changes a domain scheme.',
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-scheme example.com https',
|
'drush domain-scheme example.com https',
|
||||||
'drush domain-scheme 1 https',
|
'drush domain-scheme 1 https',
|
||||||
),
|
],
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'domain_id' => 'The numeric id or hostname of the domain to change.',
|
'domain_id' => 'The numeric id or hostname of the domain to change.',
|
||||||
'scheme' => 'The URL schema (http or https) to use for the domain.',
|
'scheme' => 'The URL schema (http or https) to use for the domain.',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$items['generate-domains'] = array(
|
$items['generate-domains'] = [
|
||||||
'description' => 'Generate domains for testing.',
|
'description' => 'Generate domains for testing.',
|
||||||
'arguments' => array(
|
'arguments' => [
|
||||||
'primary' => 'The primary domain to use. This will be created and used for *.example.com hostnames.',
|
'primary' => 'The primary domain to use. This will be created and used for *.example.com hostnames.',
|
||||||
),
|
],
|
||||||
'options' => array(
|
'options' => [
|
||||||
'count' => 'The count of extra domains to generate. Default is 15.',
|
'count' => 'The count of extra domains to generate. Default is 15.',
|
||||||
'empty' => 'Pass empty=1 to truncate the {domain} table before creating records.'
|
'empty' => 'Pass empty=1 to truncate the {domain} table before creating records.',
|
||||||
),
|
],
|
||||||
'examples' => array(
|
'examples' => [
|
||||||
'drush domain-generate example.com',
|
'drush domain-generate example.com',
|
||||||
'drush domain-generate example.com --count=25',
|
'drush domain-generate example.com --count=25',
|
||||||
'drush domain-generate example.com --count=25 --empty=1',
|
'drush domain-generate example.com --count=25 --empty=1',
|
||||||
'drush gend',
|
'drush gend',
|
||||||
'drush gend --count=25',
|
'drush gend --count=25',
|
||||||
'drush gend --count=25 --empty=1',
|
'drush gend --count=25 --empty=1',
|
||||||
),
|
],
|
||||||
'aliases' => array('gend'),
|
'aliases' => ['gend'],
|
||||||
);
|
];
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,14 +171,14 @@ function domain_drush_help($section) {
|
|||||||
* Shows the domain list.
|
* Shows the domain list.
|
||||||
*/
|
*/
|
||||||
function drush_domain_list() {
|
function drush_domain_list() {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultipleSorted(NULL, TRUE);
|
||||||
|
|
||||||
if (empty($domains)) {
|
if (empty($domains)) {
|
||||||
drush_print(dt('No domains have been created. Use drush domain-add to create one.'));
|
drush_print(dt('No domains have been created. Use drush domain-add to create one.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = array(
|
$header = [
|
||||||
'weight' => dt('Weight'),
|
'weight' => dt('Weight'),
|
||||||
'name' => dt('Name'),
|
'name' => dt('Name'),
|
||||||
'hostname' => dt('Hostname'),
|
'hostname' => dt('Hostname'),
|
||||||
@@ -187,10 +187,10 @@ function drush_domain_list() {
|
|||||||
'is_default' => dt('Default'),
|
'is_default' => dt('Default'),
|
||||||
'domain_id' => dt('Domain Id'),
|
'domain_id' => dt('Domain Id'),
|
||||||
'id' => dt('Machine name'),
|
'id' => dt('Machine name'),
|
||||||
);
|
];
|
||||||
$rows = array(array_values($header));
|
$rows = [array_values($header)];
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$row = array();
|
$row = [];
|
||||||
foreach ($header as $key => $name) {
|
foreach ($header as $key => $name) {
|
||||||
$row[] = Html::escape($domain->get($key));
|
$row[] = Html::escape($domain->get($key));
|
||||||
}
|
}
|
||||||
@@ -210,28 +210,25 @@ function drush_domain_list() {
|
|||||||
* The script may also add test1, test2, test3 up to any number to test a
|
* The script may also add test1, test2, test3 up to any number to test a
|
||||||
* large number of domains. This test is mostly for UI testing.
|
* large number of domains. This test is mostly for UI testing.
|
||||||
*
|
*
|
||||||
* @param $primary
|
* @param string $primary
|
||||||
* The root domain to use for domain creation.
|
* The root domain to use for domain creation.
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* A list of the domains created.
|
|
||||||
*/
|
*/
|
||||||
function drush_domain_generate_domains($primary = 'example.com') {
|
function drush_domain_generate_domains($primary = 'example.com') {
|
||||||
// Check the number of domains to create.
|
// Check the number of domains to create.
|
||||||
$count = drush_get_option('count');
|
$count = drush_get_option('count');
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
if (empty($count)) {
|
if (empty($count)) {
|
||||||
$count = 15;
|
$count = 15;
|
||||||
}
|
}
|
||||||
// Ensure we don't duplicate any domains.
|
// Ensure we don't duplicate any domains.
|
||||||
$existing = array();
|
$existing = [];
|
||||||
if (!empty($domains)) {
|
if (!empty($domains)) {
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$existing[] = $domain->getHostname();
|
$existing[] = $domain->getHostname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set up one.* and so on.
|
// Set up one.* and so on.
|
||||||
$names = array(
|
$names = [
|
||||||
'one',
|
'one',
|
||||||
'two',
|
'two',
|
||||||
'three',
|
'three',
|
||||||
@@ -245,23 +242,23 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
|||||||
'foo',
|
'foo',
|
||||||
'bar',
|
'bar',
|
||||||
'baz',
|
'baz',
|
||||||
);
|
];
|
||||||
// Set the creation array.
|
// Set the creation array.
|
||||||
$new = array($primary);
|
$new = [$primary];
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
$new[] = $name . '.' . $primary;
|
$new[] = $name . '.' . $primary;
|
||||||
}
|
}
|
||||||
// Include a non hostname.
|
// Include a non hostname.
|
||||||
$new[] = 'my' . $primary;
|
$new[] = 'my' . $primary;
|
||||||
// Filter against existing so we can count correctly.
|
// Filter against existing so we can count correctly.
|
||||||
$prepared = array();
|
$prepared = [];
|
||||||
foreach ($new as $key => $value) {
|
foreach ($new as $key => $value) {
|
||||||
if (!in_array($value, $existing)) {
|
if (!in_array($value, $existing)) {
|
||||||
$prepared[] = $value;
|
$prepared[] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add any test domains that have numeric prefixes. We don't expect these URLs to work,
|
// Add any test domains that have numeric prefixes. We don't expect these URLs
|
||||||
// and mainly use these for testing the user interface.
|
// to work, and mainly use these for testing the user interface.
|
||||||
$needed = $count - count($prepared);
|
$needed = $count - count($prepared);
|
||||||
for ($i = 1; $i <= $needed; $i++) {
|
for ($i = 1; $i <= $needed; $i++) {
|
||||||
$prepared[] = 'test' . $i . '.' . $primary;
|
$prepared[] = 'test' . $i . '.' . $primary;
|
||||||
@@ -273,17 +270,17 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
|||||||
|
|
||||||
// Create the domains.
|
// Create the domains.
|
||||||
foreach ($prepared as $key => $item) {
|
foreach ($prepared as $key => $item) {
|
||||||
$hostname = strtolower($item);
|
$hostname = mb_strtolower($item);
|
||||||
$values = array(
|
$values = [
|
||||||
'name' => ($item != $primary) ? ucwords(str_replace(".$primary", '', $item)) : \Drupal::config('system.site')->get('name'),
|
'name' => ($item != $primary) ? ucwords(str_replace(".$primary", '', $item)) : \Drupal::config('system.site')->get('name'),
|
||||||
'hostname' => $hostname,
|
'hostname' => $hostname,
|
||||||
'scheme' => 'http',
|
'scheme' => 'http',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'weight' => ($item != $primary) ? $key + $start_weight + 1 : -1,
|
'weight' => ($item != $primary) ? $key + $start_weight + 1 : -1,
|
||||||
'is_default' => 0,
|
'is_default' => 0,
|
||||||
'id' => \Drupal::service('entity_type.manager')->getStorage('domain')->createMachineName($hostname),
|
'id' => \Drupal::entityTypeManager()->getStorage('domain')->createMachineName($hostname),
|
||||||
);
|
];
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create($values);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||||
domain_drush_create($domain);
|
domain_drush_create($domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +293,7 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
|||||||
/**
|
/**
|
||||||
* Validates the domain generation script.
|
* Validates the domain generation script.
|
||||||
*
|
*
|
||||||
* @param $primary
|
* @param string $primary
|
||||||
* The root domain to use for domain creation.
|
* The root domain to use for domain creation.
|
||||||
*/
|
*/
|
||||||
function drush_domain_generate_domains_validate($primary = 'example.com') {
|
function drush_domain_generate_domains_validate($primary = 'example.com') {
|
||||||
@@ -304,11 +301,7 @@ function drush_domain_generate_domains_validate($primary = 'example.com') {
|
|||||||
db_query("TRUNCATE TABLE {domain}");
|
db_query("TRUNCATE TABLE {domain}");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
// TODO: Update this validation.
|
// TODO: Add validation.
|
||||||
$error = domain_valid_domain($primary);
|
|
||||||
if (!empty($error)) {
|
|
||||||
return drush_set_error('domain', $error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -322,10 +315,10 @@ function drush_domain_generate_domains_validate($primary = 'example.com') {
|
|||||||
function drush_domain_add($hostname, $name) {
|
function drush_domain_add($hostname, $name) {
|
||||||
$records_count = \Drupal::entityTypeManager()->getStorage('domain')->getQuery()->count()->execute();
|
$records_count = \Drupal::entityTypeManager()->getStorage('domain')->getQuery()->count()->execute();
|
||||||
$start_weight = $records_count + 1;
|
$start_weight = $records_count + 1;
|
||||||
$hostname = strtolower($hostname);
|
$hostname = mb_strtolower($hostname);
|
||||||
/** @var \Drupal\domain\DomainStorageInterface $domain_storage */
|
/** @var \Drupal\domain\DomainStorageInterface $domain_storage */
|
||||||
$domain_storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$values = array(
|
$values = [
|
||||||
'hostname' => $hostname,
|
'hostname' => $hostname,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'status' => (!drush_get_option('invalid')) ? 1 : 0,
|
'status' => (!drush_get_option('invalid')) ? 1 : 0,
|
||||||
@@ -334,7 +327,7 @@ function drush_domain_add($hostname, $name) {
|
|||||||
'is_default' => ($is_default = drush_get_option('is_default')) ? $is_default : 0,
|
'is_default' => ($is_default = drush_get_option('is_default')) ? $is_default : 0,
|
||||||
'id' => $domain_storage->createMachineName($hostname),
|
'id' => $domain_storage->createMachineName($hostname),
|
||||||
'validate_url' => (drush_get_option('validate')) ? 1 : 0,
|
'validate_url' => (drush_get_option('validate')) ? 1 : 0,
|
||||||
);
|
];
|
||||||
$domain = $domain_storage->create($values);
|
$domain = $domain_storage->create($values);
|
||||||
domain_drush_create($domain);
|
domain_drush_create($domain);
|
||||||
}
|
}
|
||||||
@@ -355,7 +348,7 @@ function drush_domain_add_validate($hostname, $name) {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return drush_set_error('domain', $errors);
|
return drush_set_error('domain', $errors);
|
||||||
}
|
}
|
||||||
elseif (\Drupal::service('entity_type.manager')->getStorage('domain')->loadByHostname($hostname)) {
|
elseif (\Drupal::entityTypeManager()->getStorage('domain')->loadByHostname($hostname)) {
|
||||||
return drush_set_error('domain', dt('The hostname is already registered.'));
|
return drush_set_error('domain', dt('The hostname is already registered.'));
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -374,7 +367,7 @@ function domain_drush_create(DomainInterface $domain) {
|
|||||||
else {
|
else {
|
||||||
$domain->save();
|
$domain->save();
|
||||||
if ($domain->getDomainId()) {
|
if ($domain->getDomainId()) {
|
||||||
drush_print(dt('Created @name at @domain.', array('@name' => $domain->label(), '@domain' => $domain->getHostname())));
|
drush_print(dt('Created @name at @domain.', ['@name' => $domain->label(), '@domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drush_print(dt('The request could not be completed.'));
|
drush_print(dt('The request could not be completed.'));
|
||||||
@@ -417,7 +410,7 @@ function domain_drush_check_response(DomainInterface $domain) {
|
|||||||
/**
|
/**
|
||||||
* Validates a domain.
|
* Validates a domain.
|
||||||
*
|
*
|
||||||
* @param $hostname
|
* @param string $hostname
|
||||||
* The domain name to validate for syntax and uniqueness.
|
* The domain name to validate for syntax and uniqueness.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
@@ -434,7 +427,7 @@ function domain_drush_validate_domain($hostname) {
|
|||||||
/**
|
/**
|
||||||
* Deletes a domain record.
|
* Deletes a domain record.
|
||||||
*
|
*
|
||||||
* @param $argument
|
* @param string $argument
|
||||||
* The domain_id to delete. Pass 'all' to delete all records.
|
* The domain_id to delete. Pass 'all' to delete all records.
|
||||||
*/
|
*/
|
||||||
function drush_domain_delete($argument = NULL) {
|
function drush_domain_delete($argument = NULL) {
|
||||||
@@ -442,12 +435,12 @@ function drush_domain_delete($argument = NULL) {
|
|||||||
drush_set_error('domain', dt('You must specify a domain to delete.'));
|
drush_set_error('domain', dt('You must specify a domain to delete.'));
|
||||||
}
|
}
|
||||||
if ($argument == 'all') {
|
if ($argument == 'all') {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
if (empty($domains)) {
|
if (empty($domains)) {
|
||||||
drush_print(dt('There are no domains to delete.'));
|
drush_print(dt('There are no domains to delete.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$content = drush_choice(array(1 => dt('Delete all domains')), dt('This action may not be undone. Continue?'), '!value');
|
$content = drush_choice([1 => dt('Delete all domains')], dt('This action may not be undone. Continue?'), '!value');
|
||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -464,14 +457,14 @@ function drush_domain_delete($argument = NULL) {
|
|||||||
}
|
}
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$domain->delete();
|
$domain->delete();
|
||||||
drush_print(dt('Domain record @domain deleted.', array('@domain' => $domain->getHostname())));
|
drush_print(dt('Domain record @domain deleted.', ['@domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: Set options for re-assigning content.
|
// TODO: Set options for re-assigning content.
|
||||||
$list = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$list = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
$options = array('0' => dt('Do not reassign'));
|
$options = ['0' => dt('Do not reassign')];
|
||||||
foreach ($list as $data) {
|
foreach ($list as $data) {
|
||||||
if ($data->id() != $domain->id()) {
|
if ($data->id() != $domain->id()) {
|
||||||
$options[$data->getDomainId()] = $data->getHostname();
|
$options[$data->getDomainId()] = $data->getHostname();
|
||||||
@@ -496,7 +489,7 @@ function drush_domain_delete($argument = NULL) {
|
|||||||
/**
|
/**
|
||||||
* Tests a domain record for the proper HTTP response.
|
* Tests a domain record for the proper HTTP response.
|
||||||
*
|
*
|
||||||
* @param $argument
|
* @param string $argument
|
||||||
* The domain_id to test. Passing no value tests all records.
|
* The domain_id to test. Passing no value tests all records.
|
||||||
*/
|
*/
|
||||||
function drush_domain_test($argument = NULL) {
|
function drush_domain_test($argument = NULL) {
|
||||||
@@ -505,11 +498,11 @@ function drush_domain_test($argument = NULL) {
|
|||||||
$GLOBALS['base_path'] = '/' . $base_path . '/';
|
$GLOBALS['base_path'] = '/' . $base_path . '/';
|
||||||
}
|
}
|
||||||
if (is_null($argument)) {
|
if (is_null($argument)) {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||||
$domains = array($domain);
|
$domains = [$domain];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
@@ -517,10 +510,10 @@ function drush_domain_test($argument = NULL) {
|
|||||||
}
|
}
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
if ($domain->getResponse() != 200) {
|
if ($domain->getResponse() != 200) {
|
||||||
drush_print(dt('Fail: !error. Please pass a --uri parameter or a --base_path to retest.' , array('!error' => $domain->getResponse())));
|
drush_print(dt('Fail: !error. Please pass a --uri parameter or a --base_path to retest.', ['!error' => $domain->getResponse()]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drush_print(dt('Success: !url tested successfully.', array('!url' => $domain->getPath())));
|
drush_print(dt('Success: !url tested successfully.', ['!url' => $domain->getPath()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,7 +531,7 @@ function drush_domain_default($argument) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$domain->saveDefault();
|
$domain->saveDefault();
|
||||||
drush_print(dt('!domain set to primary domain.', array('!domain' => $domain->getHostname())));
|
drush_print(dt('!domain set to primary domain.', ['!domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,10 +544,10 @@ function drush_domain_disable($argument) {
|
|||||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||||
if ($domain->status()) {
|
if ($domain->status()) {
|
||||||
$domain->disable();
|
$domain->disable();
|
||||||
drush_print(dt('!domain has been disabled.', array('!domain' => $domain->getHostname())));
|
drush_print(dt('!domain has been disabled.', ['!domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drush_print(dt('!domain is already disabled.', array('!domain' => $domain->getHostname())));
|
drush_print(dt('!domain is already disabled.', ['!domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,10 +560,10 @@ function drush_domain_enable($argument) {
|
|||||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||||
if (!$domain->status()) {
|
if (!$domain->status()) {
|
||||||
$domain->enable();
|
$domain->enable();
|
||||||
drush_print(dt('!domain has been enabled.', array('!domain' => $domain->getHostname())));
|
drush_print(dt('!domain has been enabled.', ['!domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drush_print(dt('!domain is already enabled.', array('!domain' => $domain->getHostname())));
|
drush_print(dt('!domain is already enabled.', ['!domain' => $domain->getHostname()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -589,15 +582,15 @@ function drush_domain_name($argument, $name) {
|
|||||||
* Changes a domain machine_name.
|
* Changes a domain machine_name.
|
||||||
*/
|
*/
|
||||||
function drush_domain_machine_name($argument, $machine_name) {
|
function drush_domain_machine_name($argument, $machine_name) {
|
||||||
$machine_name = \Drupal::service('entity_type.manager')->getStorage('domain')->createMachineName($machine_name);
|
$machine_name = \Drupal::entityTypeManager()->getStorage('domain')->createMachineName($machine_name);
|
||||||
// Resolve the domain.
|
// Resolve the domain.
|
||||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||||
$results = \Drupal::entityTypeManager()
|
$results = \Drupal::entityTypeManager()
|
||||||
->getStorage('domain')
|
->getStorage('domain')
|
||||||
->loadByProperties(array('machine_name' => $machine_name));
|
->loadByProperties(['machine_name' => $machine_name]);
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
if ($result->id() == $machine_name) {
|
if ($result->id() == $machine_name) {
|
||||||
drush_print(dt('The machine_name @machine_name is being used by domain @hostname.', array('@machine_name' => $machine_name, '@hostname' => $result->getHostname())));
|
drush_print(dt('The machine_name @machine_name is being used by domain @hostname.', ['@machine_name' => $machine_name, '@hostname' => $result->getHostname()]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,7 +604,7 @@ function drush_domain_machine_name($argument, $machine_name) {
|
|||||||
function drush_domain_scheme($argument) {
|
function drush_domain_scheme($argument) {
|
||||||
// Resolve the domain.
|
// Resolve the domain.
|
||||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||||
$content = drush_choice(array(1 => dt('http'), 2 => dt('https')), dt('Select the default http scheme:'), '!value');
|
$content = drush_choice([1 => dt('http'), 2 => dt('https')], dt('Select the default http scheme:'), '!value');
|
||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -629,9 +622,9 @@ function drush_domain_scheme($argument) {
|
|||||||
* On failure, throws a drush error.
|
* On failure, throws a drush error.
|
||||||
*/
|
*/
|
||||||
function drush_domain_get_from_argument($argument) {
|
function drush_domain_get_from_argument($argument) {
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->load($argument);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->load($argument);
|
||||||
if (!$domain) {
|
if (!$domain) {
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->loadByHostname($argument);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->loadByHostname($argument);
|
||||||
}
|
}
|
||||||
if (!$domain) {
|
if (!$domain) {
|
||||||
drush_set_error('domain', dt('Domain record not found.'));
|
drush_set_error('domain', dt('Domain record not found.'));
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ package: Domain
|
|||||||
# version: VERSION
|
# version: VERSION
|
||||||
# core: 8.x
|
# core: 8.x
|
||||||
dependencies:
|
dependencies:
|
||||||
- options
|
- drupal:system (>=8.5)
|
||||||
|
- drupal:options
|
||||||
configure: domain.admin
|
configure: domain.admin
|
||||||
|
|
||||||
# Information added by Drupal.org packaging script on 2018-03-08
|
# Information added by Drupal.org packaging script on 2018-11-14
|
||||||
version: '8.x-1.0-alpha13'
|
version: '8.x-1.0-alpha14+9-dev'
|
||||||
core: '8.x'
|
core: '8.x'
|
||||||
project: 'domain'
|
project: 'domain'
|
||||||
datestamp: 1520519900
|
datestamp: 1542230887
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ function _domain_configure_field() {
|
|||||||
$display->setComponent(DOMAIN_ADMIN_FIELD, [
|
$display->setComponent(DOMAIN_ADMIN_FIELD, [
|
||||||
'type' => 'options_buttons',
|
'type' => 'options_buttons',
|
||||||
'weight' => 50,
|
'weight' => 50,
|
||||||
])
|
])->save();
|
||||||
->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
* Defines a Domain concept for use with Drupal.
|
* Defines a Domain concept for use with Drupal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Drupal\Core\Render\BubbleableMetadata;
|
||||||
use Drupal\Core\Url;
|
use Drupal\Core\Url;
|
||||||
use Drupal\domain\DomainInterface;
|
use Drupal\domain\DomainInterface;
|
||||||
use Drupal\Core\Routing\RouteMatchInterface;
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||||||
use Drupal\Component\Utility\Html;
|
use Drupal\Component\Utility\Html;
|
||||||
use Drupal\field\Entity\FieldStorageConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the node access control field.
|
* The name of the node access control field.
|
||||||
@@ -71,11 +71,10 @@ function domain_token_info() {
|
|||||||
/**
|
/**
|
||||||
* Implements hook_tokens().
|
* Implements hook_tokens().
|
||||||
*/
|
*/
|
||||||
function domain_tokens($type, $tokens, array $data, array $options, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
|
function domain_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
|
||||||
return \Drupal::service('domain.token')->getTokens($type, $tokens, $data, $options, $bubbleable_metadata);
|
return \Drupal::service('domain.token')->getTokens($type, $tokens, $data, $options, $bubbleable_metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_preprocess_HOOK() for html.html.twig.
|
* Implements hook_preprocess_HOOK() for html.html.twig.
|
||||||
*/
|
*/
|
||||||
@@ -128,7 +127,7 @@ function domain_domain_references_alter($query, $account, $context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_views_data_alter.
|
* Implements hook_views_data_alter().
|
||||||
*/
|
*/
|
||||||
function domain_views_data_alter(array &$data) {
|
function domain_views_data_alter(array &$data) {
|
||||||
$table = 'user__' . DOMAIN_ADMIN_FIELD;
|
$table = 'user__' . DOMAIN_ADMIN_FIELD;
|
||||||
@@ -155,8 +154,8 @@ function domain_theme() {
|
|||||||
* @param array $variables
|
* @param array $variables
|
||||||
* An associative array containing:
|
* An associative array containing:
|
||||||
* - items: An array of labels and urls for use in the list.
|
* - items: An array of labels and urls for use in the list.
|
||||||
* Properties used: 'label', 'url', 'active'
|
* Properties used: 'label', 'url', 'active'.
|
||||||
*/
|
*/
|
||||||
function template_preprocess_domain_nav_block(&$variables) {
|
function template_preprocess_domain_nav_block(array &$variables) {
|
||||||
$variables['items'] = $variables['items']['#items'];
|
$variables['items'] = $variables['items']['#items'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ class DomainAccessCheck implements AccessCheckInterface {
|
|||||||
/**
|
/**
|
||||||
* Constructs the object.
|
* Constructs the object.
|
||||||
*
|
*
|
||||||
* @param DomainNegotiatorInterface $negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||||
* The domain negotiation service.
|
* The domain negotiation service.
|
||||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||||
* The config factory.
|
* The config factory.
|
||||||
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
|
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
|
||||||
* The path matcher service
|
* The path matcher service.
|
||||||
*/
|
*/
|
||||||
public function __construct(DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory, PathMatcherInterface $path_matcher) {
|
public function __construct(DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory, PathMatcherInterface $path_matcher) {
|
||||||
$this->domainNegotiator = $negotiator;
|
$this->domainNegotiator = $negotiator;
|
||||||
@@ -71,7 +71,6 @@ class DomainAccessCheck implements AccessCheckInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function access(AccountInterface $account) {
|
public function access(AccountInterface $account) {
|
||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
|
||||||
$domain = $this->domainNegotiator->getActiveDomain();
|
$domain = $this->domainNegotiator->getActiveDomain();
|
||||||
// Is the domain allowed?
|
// Is the domain allowed?
|
||||||
// No domain, let it pass.
|
// No domain, let it pass.
|
||||||
@@ -84,7 +83,7 @@ class DomainAccessCheck implements AccessCheckInterface {
|
|||||||
}
|
}
|
||||||
// Inactive domain, require permissions.
|
// Inactive domain, require permissions.
|
||||||
else {
|
else {
|
||||||
$permissions = array('administer domains', 'access inactive domains');
|
$permissions = ['administer domains', 'access inactive domains'];
|
||||||
$operator = 'OR';
|
$operator = 'OR';
|
||||||
return AccessResult::allowedIfHasPermissions($account, $permissions, $operator)->setCacheMaxAge(0);
|
return AccessResult::allowedIfHasPermissions($account, $permissions, $operator)->setCacheMaxAge(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class DomainListCheck {
|
|||||||
* The account making the route request.
|
* The account making the route request.
|
||||||
*
|
*
|
||||||
* @return \Drupal\Core\Access\AccessResult
|
* @return \Drupal\Core\Access\AccessResult
|
||||||
|
* The access result.
|
||||||
*/
|
*/
|
||||||
public static function viewDomainList(AccountInterface $account) {
|
public static function viewDomainList(AccountInterface $account) {
|
||||||
if ($account->hasPermission('administer domains') || $account->hasPermission('view domain list') || $account->hasPermission('view assigned domains')) {
|
if ($account->hasPermission('administer domains') || $account->hasPermission('view domain list') || $account->hasPermission('view assigned domains')) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use Drupal\domain\DomainNegotiatorInterface;
|
|||||||
* Determines access to routes based on domains.
|
* Determines access to routes based on domains.
|
||||||
*
|
*
|
||||||
* You can specify the '_domain' key on route requirements. If you specify a
|
* You can specify the '_domain' key on route requirements. If you specify a
|
||||||
* single domain, users with that domain with have access. If you specify multiple
|
* single domain, users with that domain with have access. If you specify
|
||||||
* ones you can join them by using "+".
|
* multiple ones you can join them by using "+".
|
||||||
*
|
*
|
||||||
* This access checker is separate from the global check used by inactive
|
* This access checker is separate from the global check used by inactive
|
||||||
* domains. It is expressly for use with Views and other systems that need
|
* domains. It is expressly for use with Views and other systems that need
|
||||||
@@ -28,7 +28,6 @@ class DomainRouteCheck implements AccessInterface {
|
|||||||
*/
|
*/
|
||||||
protected $requirementsKey = '_domain';
|
protected $requirementsKey = '_domain';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Domain negotiator.
|
* The Domain negotiator.
|
||||||
*
|
*
|
||||||
@@ -39,7 +38,7 @@ class DomainRouteCheck implements AccessInterface {
|
|||||||
/**
|
/**
|
||||||
* Constructs the object.
|
* Constructs the object.
|
||||||
*
|
*
|
||||||
* @param DomainNegotiatorInterface $negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||||
* The domain negotiation service.
|
* The domain negotiation service.
|
||||||
*/
|
*/
|
||||||
public function __construct(DomainNegotiatorInterface $negotiator) {
|
public function __construct(DomainNegotiatorInterface $negotiator) {
|
||||||
|
|||||||
+2
-1
@@ -59,7 +59,8 @@ class CurrentDomainContext implements ContextProviderInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getAvailableContexts() {
|
public function getAvailableContexts() {
|
||||||
return $this->getRuntimeContexts([]);
|
$context = new Context(new ContextDefinition('entity:domain', $this->t('Active domain')));
|
||||||
|
return ['entity:domain' => $context];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class DomainController {
|
|||||||
*
|
*
|
||||||
* @param \Drupal\domain\DomainInterface $domain
|
* @param \Drupal\domain\DomainInterface $domain
|
||||||
* A domain record object.
|
* A domain record object.
|
||||||
* @param string|NULL $op
|
* @param string|null $op
|
||||||
* The operation being performed, either 'default' to make the domain record
|
* The operation being performed, either 'default' to make the domain record
|
||||||
* the default, 'enable' to enable the domain record, or 'disable' to
|
* the default, 'enable' to enable the domain record, or 'disable' to
|
||||||
* disable the domain record.
|
* disable the domain record.
|
||||||
@@ -62,14 +62,14 @@ class DomainController {
|
|||||||
|
|
||||||
// Set a message.
|
// Set a message.
|
||||||
if ($success) {
|
if ($success) {
|
||||||
drupal_set_message($message);
|
\Drupal::messenger()->addMessage($message);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message($this->t('The operation failed.'));
|
\Drupal::messenger()->addMessage($this->t('The operation failed.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return to the invoking page.
|
// Return to the invoking page.
|
||||||
$url = Url::fromRoute('domain.admin', array(), array('absolute' => TRUE));
|
$url = Url::fromRoute('domain.admin', [], ['absolute' => TRUE]);
|
||||||
return new RedirectResponse($url->toString(), 302);
|
return new RedirectResponse($url->toString(), 302);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\domain\Controller;
|
namespace Drupal\domain\Controller;
|
||||||
|
|
||||||
use Drupal\Core\Controller\ControllerBase;
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Drupal\domain\DomainStorageInterface;
|
use Drupal\domain\DomainStorageInterface;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface;
|
|||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainElementManagerInterface;
|
|
||||||
use Drupal\user\UserStorageInterface;
|
use Drupal\user\UserStorageInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
class DomainAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
|
class DomainAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entity type manager
|
* The entity type manager.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
*/
|
*/
|
||||||
@@ -105,10 +104,11 @@ class DomainAccessControlHandler extends EntityAccessControlHandler implements E
|
|||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||||
* The entity to retrieve field data from.
|
* The entity to retrieve field data from.
|
||||||
* @param \Drupal\Core\Session\AccountInterface
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
* The user account.
|
* The user account.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool
|
||||||
|
* TRUE if a user can administer a specific domain, or FALSE.
|
||||||
*/
|
*/
|
||||||
public function isDomainAdmin(EntityInterface $entity, AccountInterface $account) {
|
public function isDomainAdmin(EntityInterface $entity, AccountInterface $account) {
|
||||||
$user = $this->userStorage->load($account->id());
|
$user = $this->userStorage->load($account->id());
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ class DomainCreator implements DomainCreatorInterface {
|
|||||||
/**
|
/**
|
||||||
* The Domain loader.
|
* The Domain loader.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain\DomainLoaderInterface $loader
|
* @var \Drupal\domain\DomainLoaderInterface
|
||||||
*/
|
*/
|
||||||
protected $loader;
|
protected $loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Domain negotiator.
|
* The Domain negotiator.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain\DomainNegotiatorInterface $negotiator
|
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||||
*/
|
*/
|
||||||
protected $negotiator;
|
protected $negotiator;
|
||||||
|
|
||||||
@@ -43,19 +43,19 @@ class DomainCreator implements DomainCreatorInterface {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function createDomain(array $values = array()) {
|
public function createDomain(array $values = []) {
|
||||||
$default = $this->loader->loadDefaultId();
|
$default = $this->loader->loadDefaultId();
|
||||||
$domains = $this->loader->loadMultiple();
|
$domains = $this->loader->loadMultiple();
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
$values['hostname'] = $this->createHostname();
|
$values['hostname'] = $this->createHostname();
|
||||||
$values['name'] = \Drupal::config('system.site')->get('name');
|
$values['name'] = \Drupal::config('system.site')->get('name');
|
||||||
}
|
}
|
||||||
$values += array(
|
$values += [
|
||||||
'scheme' => \Drupal::service('entity_type.manager')->getStorage('domain')->getDefaultScheme(),
|
'scheme' => \Drupal::entityTypeManager()->getStorage('domain')->getDefaultScheme(),
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'weight' => count($domains) + 1,
|
'weight' => count($domains) + 1,
|
||||||
'is_default' => (int) empty($default),
|
'is_default' => (int) empty($default),
|
||||||
);
|
];
|
||||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||||
|
|
||||||
return $domain;
|
return $domain;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Drupal\domain;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the creation of new domain records.
|
* Handles the creation of new domain records.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* This interface will be removed before the 8.1.0 release.
|
* This interface will be removed before the 8.1.0 release.
|
||||||
*/
|
*/
|
||||||
@@ -17,10 +18,10 @@ interface DomainCreatorInterface {
|
|||||||
* Required values are: hostname, name.
|
* Required values are: hostname, name.
|
||||||
* Passing an empty array will create a domain from the current request.
|
* Passing an empty array will create a domain from the current request.
|
||||||
*
|
*
|
||||||
* @return DomainInterface $domain
|
* @return \Drupal\domain\DomainInterface
|
||||||
* A domain record object.
|
* A domain record object.
|
||||||
*/
|
*/
|
||||||
public function createDomain(array $values = array());
|
public function createDomain(array $values = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the hostname of the active request.
|
* Gets the hostname of the active request.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Drupal\domain;
|
namespace Drupal\domain;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
@@ -16,21 +17,23 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|||||||
*
|
*
|
||||||
* This class has some similarities to DomainAccessManager, but only cares
|
* This class has some similarities to DomainAccessManager, but only cares
|
||||||
* about form handling. It can be used as a base class by other modules that
|
* about form handling. It can be used as a base class by other modules that
|
||||||
* show/hide domain options. See the DomainSourceElementManager for a non-default
|
* show/hide domain options. See the DomainSourceElementManager for a
|
||||||
* implementation.
|
* non-default implementation.
|
||||||
*/
|
*/
|
||||||
class DomainElementManager implements DomainElementManagerInterface {
|
class DomainElementManager implements DomainElementManagerInterface {
|
||||||
|
|
||||||
use StringTranslationTrait;
|
use StringTranslationTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entity type manager
|
* The entity type manager.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
*/
|
*/
|
||||||
protected $entityTypeManager;
|
protected $entityTypeManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The domain storage.
|
||||||
|
*
|
||||||
* @var \Drupal\domain\DomainStorageInterface
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
*/
|
*/
|
||||||
protected $domainStorage;
|
protected $domainStorage;
|
||||||
@@ -38,7 +41,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
/**
|
/**
|
||||||
* Constructs a DomainElementManager object.
|
* Constructs a DomainElementManager object.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
*/
|
*/
|
||||||
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||||
@@ -47,7 +50,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setFormOptions(array $form, FormStateInterface $form_state, $field_name, $hide_on_disallow = FALSE) {
|
public function setFormOptions(array $form, FormStateInterface $form_state, $field_name, $hide_on_disallow = FALSE) {
|
||||||
// There are cases, such as Entity Browser, where the form is partially
|
// There are cases, such as Entity Browser, where the form is partially
|
||||||
@@ -59,8 +62,9 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
$disallowed = $this->disallowedOptions($form_state, $form[$field_name]);
|
$disallowed = $this->disallowedOptions($form_state, $form[$field_name]);
|
||||||
$empty = empty($form[$field_name]['widget']['#options']);
|
$empty = empty($form[$field_name]['widget']['#options']);
|
||||||
|
|
||||||
// If the domain form element is set as a group, and the field is not assigned to
|
// If the domain form element is set as a group, and the field is not
|
||||||
// another group, then move it. See domain_access_form_node_form_alter().
|
// assigned to another group, then move it. See
|
||||||
|
// domain_access_form_node_form_alter().
|
||||||
if (isset($form['domain']) && !isset($form[$field_name]['#group'])) {
|
if (isset($form['domain']) && !isset($form[$field_name]['#group'])) {
|
||||||
$form[$field_name]['#group'] = 'domain';
|
$form[$field_name]['#group'] = 'domain';
|
||||||
}
|
}
|
||||||
@@ -68,14 +72,14 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
// Check for domains the user cannot access or the absence of any options.
|
// Check for domains the user cannot access or the absence of any options.
|
||||||
if (!empty($disallowed) || $empty) {
|
if (!empty($disallowed) || $empty) {
|
||||||
// @TODO: Potentially show this information to users with permission.
|
// @TODO: Potentially show this information to users with permission.
|
||||||
$form[$field_name . '_disallowed'] = array(
|
$form[$field_name . '_disallowed'] = [
|
||||||
'#type' => 'value',
|
'#type' => 'value',
|
||||||
'#value' => $disallowed,
|
'#value' => $disallowed,
|
||||||
);
|
];
|
||||||
$form['domain_hidden_fields'] = array(
|
$form['domain_hidden_fields'] = [
|
||||||
'#type' => 'value',
|
'#type' => 'value',
|
||||||
'#value' => $fields,
|
'#value' => $fields,
|
||||||
);
|
];
|
||||||
if ($hide_on_disallow || $empty) {
|
if ($hide_on_disallow || $empty) {
|
||||||
$form[$field_name]['#access'] = FALSE;
|
$form[$field_name]['#access'] = FALSE;
|
||||||
}
|
}
|
||||||
@@ -97,7 +101,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function submitEntityForm(array &$form, FormStateInterface $form_state) {
|
public static function submitEntityForm(array &$form, FormStateInterface $form_state) {
|
||||||
$fields = $form_state->getValue('domain_hidden_fields');
|
$fields = $form_state->getValue('domain_hidden_fields');
|
||||||
@@ -121,9 +125,9 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function disallowedOptions(FormStateInterface $form_state, $field) {
|
public function disallowedOptions(FormStateInterface $form_state, array $field) {
|
||||||
$options = [];
|
$options = [];
|
||||||
$info = $form_state->getBuildInfo();
|
$info = $form_state->getBuildInfo();
|
||||||
$entity = $form_state->getFormObject()->getEntity();
|
$entity = $form_state->getFormObject()->getEntity();
|
||||||
@@ -135,7 +139,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function fieldList($field_name) {
|
public function fieldList($field_name) {
|
||||||
static $fields = [];
|
static $fields = [];
|
||||||
@@ -146,9 +150,9 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getFieldValues($entity, $field_name) {
|
public function getFieldValues(EntityInterface $entity, $field_name) {
|
||||||
// @TODO: static cache.
|
// @TODO: static cache.
|
||||||
$list = [];
|
$list = [];
|
||||||
// @TODO In tests, $entity is returning NULL.
|
// @TODO In tests, $entity is returning NULL.
|
||||||
@@ -171,7 +175,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSubmitHandler() {
|
public function getSubmitHandler() {
|
||||||
return '\\Drupal\\domain\\DomainElementManager::submitEntityForm';
|
return '\\Drupal\\domain\\DomainElementManager::submitEntityForm';
|
||||||
@@ -192,10 +196,10 @@ class DomainElementManager implements DomainElementManagerInterface {
|
|||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$items[] = $domain->label();
|
$items[] = $domain->label();
|
||||||
}
|
}
|
||||||
$build = array(
|
$build = [
|
||||||
'#theme' => 'item_list',
|
'#theme' => 'item_list',
|
||||||
'#items' => $items,
|
'#items' => $items,
|
||||||
);
|
];
|
||||||
$string .= render($build);
|
$string .= render($build);
|
||||||
return '<div class="disallowed">' . $string . '</div>';
|
return '<div class="disallowed">' . $string . '</div>';
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Drupal\domain;
|
namespace Drupal\domain;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,16 +23,16 @@ interface DomainElementManagerInterface {
|
|||||||
*
|
*
|
||||||
* @param array $form
|
* @param array $form
|
||||||
* The form array.
|
* The form array.
|
||||||
* @param FormStateInterface $form_state
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
* The form state object.
|
* The form state object.
|
||||||
* @param $field_name
|
* @param string $field_name
|
||||||
* The name of the field to check.
|
* The name of the field to check.
|
||||||
* @param boolean $hide_on_disallow
|
* @param bool $hide_on_disallow
|
||||||
* If the field is set to a value that cannot be altered by the user who
|
* If the field is set to a value that cannot be altered by the user who
|
||||||
* is not assigned to that domain, pass TRUE to remove the form element
|
* is not assigned to that domain, pass TRUE to remove the form element
|
||||||
* entirely. See DomainSourceElementManager for the use-case.
|
* entirely. See DomainSourceElementManager for the use-case.
|
||||||
*
|
*
|
||||||
* @return array $form
|
* @return array
|
||||||
* Return the modified form array.
|
* Return the modified form array.
|
||||||
*/
|
*/
|
||||||
public function setFormOptions(array $form, FormStateInterface $form_state, $field_name, $hide_on_disallow = FALSE);
|
public function setFormOptions(array $form, FormStateInterface $form_state, $field_name, $hide_on_disallow = FALSE);
|
||||||
@@ -42,30 +43,29 @@ interface DomainElementManagerInterface {
|
|||||||
* On form submit, loop through the hidden form values and add those to the
|
* On form submit, loop through the hidden form values and add those to the
|
||||||
* entity being saved.
|
* entity being saved.
|
||||||
*
|
*
|
||||||
* @param $form
|
|
||||||
* The form array.
|
|
||||||
* @param Drupal\Core\Form\FormStateInterface $form_state
|
|
||||||
* The form state object.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* No return value. Hidden values are added to the field values directly.
|
* No return value. Hidden values are added to the field values directly.
|
||||||
|
*
|
||||||
|
* @param array $form
|
||||||
|
* The form array.
|
||||||
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
|
* The form state object.
|
||||||
*/
|
*/
|
||||||
public static function submitEntityForm(array &$form, FormStateInterface $form_state);
|
public static function submitEntityForm(array &$form, FormStateInterface $form_state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds options not accessible to the current user.
|
* Finds options not accessible to the current user.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Form\FormStateInterface $form_state
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
* The form state object.
|
* The form state object.
|
||||||
* @param array $field
|
* @param array $field
|
||||||
* The field element being processed.
|
* The field element being processed.
|
||||||
*/
|
*/
|
||||||
public function disallowedOptions(FormStateInterface $form_state, $field);
|
public function disallowedOptions(FormStateInterface $form_state, array $field);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a static list of fields that have been disallowed.
|
* Stores a static list of fields that have been disallowed.
|
||||||
*
|
*
|
||||||
* @param $field_name
|
* @param string $field_name
|
||||||
* The name of the field being processed. Inherited from setFormOptions.
|
* The name of the field being processed. Inherited from setFormOptions.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
@@ -85,7 +85,7 @@ interface DomainElementManagerInterface {
|
|||||||
* The domain access field values, keyed by id (machine_name) with value of
|
* The domain access field values, keyed by id (machine_name) with value of
|
||||||
* the numeric domain_id used by node access.
|
* the numeric domain_id used by node access.
|
||||||
*/
|
*/
|
||||||
public function getFieldValues($entity, $field_name);
|
public function getFieldValues(EntityInterface $entity, $field_name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default submit handler to be used for a field element.
|
* Returns the default submit handler to be used for a field element.
|
||||||
@@ -97,7 +97,7 @@ interface DomainElementManagerInterface {
|
|||||||
* The method must be public and static, since it will be called from the
|
* The method must be public and static, since it will be called from the
|
||||||
* form submit handler without knowledge of the parent class.
|
* form submit handler without knowledge of the parent class.
|
||||||
*
|
*
|
||||||
* The base implementat is submitEntityForm, and can be overridden by
|
* The base implementation is submitEntityForm, and can be overridden by
|
||||||
* specific subclasses.
|
* specific subclasses.
|
||||||
*/
|
*/
|
||||||
public function getSubmitHandler();
|
public function getSubmitHandler();
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace Drupal\domain;
|
namespace Drupal\domain;
|
||||||
|
|
||||||
use Drupal\Core\Config\ConfigValueException;
|
|
||||||
use Drupal\Core\Entity\EntityForm;
|
use Drupal\Core\Entity\EntityForm;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\Render\RendererInterface;
|
use Drupal\Core\Render\RendererInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Drupal\domain\DomainStorageInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base form for domain edit forms.
|
* Base form for domain edit forms.
|
||||||
@@ -37,7 +35,7 @@ class DomainForm extends EntityForm {
|
|||||||
protected $validator;
|
protected $validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entity type manager
|
* The entity type manager.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +50,7 @@ class DomainForm extends EntityForm {
|
|||||||
* The renderer.
|
* The renderer.
|
||||||
* @param \Drupal\domain\DomainValidatorInterface $validator
|
* @param \Drupal\domain\DomainValidatorInterface $validator
|
||||||
* The domain validator.
|
* The domain validator.
|
||||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
*/
|
*/
|
||||||
public function __construct(DomainStorageInterface $domain_storage, RendererInterface $renderer, DomainValidatorInterface $validator, EntityTypeManagerInterface $entity_type_manager) {
|
public function __construct(DomainStorageInterface $domain_storage, RendererInterface $renderer, DomainValidatorInterface $validator, EntityTypeManagerInterface $entity_type_manager) {
|
||||||
@@ -88,70 +86,74 @@ class DomainForm extends EntityForm {
|
|||||||
$domain->addProperty('hostname', $this->domainStorage->createHostname());
|
$domain->addProperty('hostname', $this->domainStorage->createHostname());
|
||||||
$domain->addProperty('name', $this->config('system.site')->get('name'));
|
$domain->addProperty('name', $this->config('system.site')->get('name'));
|
||||||
}
|
}
|
||||||
$form['domain_id'] = array(
|
$form['domain_id'] = [
|
||||||
'#type' => 'value',
|
'#type' => 'value',
|
||||||
'#value' => $domain->getDomainId(),
|
'#value' => $domain->getDomainId(),
|
||||||
);
|
];
|
||||||
$form['hostname'] = array(
|
$form['hostname'] = [
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => $this->t('Hostname'),
|
'#title' => $this->t('Hostname'),
|
||||||
'#size' => 40,
|
'#size' => 40,
|
||||||
'#maxlength' => 80,
|
'#maxlength' => 80,
|
||||||
'#default_value' => $domain->getCanonical(),
|
'#default_value' => $domain->getCanonical(),
|
||||||
'#description' => $this->t('The canonical hostname, using the full <em>subdomain.example.com</em> format. Leave off the http:// and the trailing slash and do not include any paths.<br />If this domain uses a custom http(s) port, you should specify it here, e.g.: <em>subdomain.example.com:1234</em><br />The hostname may contain only lowercase alphanumeric characters, dots, dashes, and a colon (if using alternative ports).'),
|
'#description' => $this->t('The canonical hostname, using the full <em>subdomain.example.com</em> format. Leave off the http:// and the trailing slash and do not include any paths.<br />If this domain uses a custom http(s) port, you should specify it here, e.g.: <em>subdomain.example.com:1234</em><br />The hostname may contain only lowercase alphanumeric characters, dots, dashes, and a colon (if using alternative ports).'),
|
||||||
);
|
];
|
||||||
$form['id'] = array(
|
$form['id'] = [
|
||||||
'#type' => 'machine_name',
|
'#type' => 'machine_name',
|
||||||
'#default_value' => !empty($domain->id()) ? $domain->id() : '',
|
'#default_value' => !empty($domain->id()) ? $domain->id() : '',
|
||||||
'#disabled' => !empty($domain->id()),
|
'#disabled' => !empty($domain->id()),
|
||||||
'#machine_name' => array(
|
'#machine_name' => [
|
||||||
'source' => array('hostname'),
|
'source' => ['hostname'],
|
||||||
'exists' => array($this->domainStorage, 'load'),
|
'exists' => [$this->domainStorage, 'load'],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$form['name'] = array(
|
$form['name'] = [
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => $this->t('Name'),
|
'#title' => $this->t('Name'),
|
||||||
'#size' => 40,
|
'#size' => 40,
|
||||||
'#maxlength' => 80,
|
'#maxlength' => 80,
|
||||||
'#default_value' => $domain->label(),
|
'#default_value' => $domain->label(),
|
||||||
'#description' => $this->t('The human-readable name is shown in domain lists and may be used as the title tag.'),
|
'#description' => $this->t('The human-readable name is shown in domain lists and may be used as the title tag.'),
|
||||||
);
|
];
|
||||||
// Do not use the :// suffix when storing data.
|
// Do not use the :// suffix when storing data.
|
||||||
$add_suffix = FALSE;
|
$add_suffix = FALSE;
|
||||||
$form['scheme'] = array(
|
$form['scheme'] = [
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => $this->t('Domain URL scheme'),
|
'#title' => $this->t('Domain URL scheme'),
|
||||||
'#options' => array('http' => 'http://', 'https' => 'https://', 'variable' => 'Variable'),
|
'#options' => [
|
||||||
|
'http' => 'http://',
|
||||||
|
'https' => 'https://',
|
||||||
|
'variable' => 'Variable',
|
||||||
|
],
|
||||||
'#default_value' => $domain->getRawScheme(),
|
'#default_value' => $domain->getRawScheme(),
|
||||||
'#description' => $this->t('This URL scheme will be used when writing links and redirects to this domain and its resources. Selecting <strong>Variable</strong> will inherit the current scheme of the web request.'),
|
'#description' => $this->t('This URL scheme will be used when writing links and redirects to this domain and its resources. Selecting <strong>Variable</strong> will inherit the current scheme of the web request.'),
|
||||||
);
|
];
|
||||||
$form['status'] = array(
|
$form['status'] = [
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => $this->t('Domain status'),
|
'#title' => $this->t('Domain status'),
|
||||||
'#options' => array(1 => $this->t('Active'), 0 => $this->t('Inactive')),
|
'#options' => [1 => $this->t('Active'), 0 => $this->t('Inactive')],
|
||||||
'#default_value' => (int) $domain->status(),
|
'#default_value' => (int) $domain->status(),
|
||||||
'#description' => $this->t('"Inactive" domains are only accessible to user roles with that assigned permission.'),
|
'#description' => $this->t('"Inactive" domains are only accessible to user roles with that assigned permission.'),
|
||||||
);
|
];
|
||||||
$form['weight'] = array(
|
$form['weight'] = [
|
||||||
'#type' => 'weight',
|
'#type' => 'weight',
|
||||||
'#title' => $this->t('Weight'),
|
'#title' => $this->t('Weight'),
|
||||||
'#delta' => $count_existing + 1,
|
'#delta' => $count_existing + 1,
|
||||||
'#default_value' => $domain->getWeight(),
|
'#default_value' => $domain->getWeight(),
|
||||||
'#description' => $this->t('The sort order for this record. Lower values display first.'),
|
'#description' => $this->t('The sort order for this record. Lower values display first.'),
|
||||||
);
|
];
|
||||||
$form['is_default'] = array(
|
$form['is_default'] = [
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => $this->t('Default domain'),
|
'#title' => $this->t('Default domain'),
|
||||||
'#default_value' => $domain->isDefault(),
|
'#default_value' => $domain->isDefault(),
|
||||||
'#description' => $this->t('If a URL request fails to match a domain record, the settings for this domain will be used. Only one domain can be default.'),
|
'#description' => $this->t('If a URL request fails to match a domain record, the settings for this domain will be used. Only one domain can be default.'),
|
||||||
);
|
];
|
||||||
$form['validate_url'] = array(
|
$form['validate_url'] = [
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => $this->t('Test server response'),
|
'#title' => $this->t('Test server response'),
|
||||||
'#default_value' => TRUE,
|
'#default_value' => TRUE,
|
||||||
'#description' => $this->t('Validate that url of the host is accessible to Drupal before saving.'),
|
'#description' => $this->t('Validate that url of the host is accessible to Drupal before saving.'),
|
||||||
);
|
];
|
||||||
$required = $this->validator->getRequiredFields();
|
$required = $this->validator->getRequiredFields();
|
||||||
foreach ($form as $key => $element) {
|
foreach ($form as $key => $element) {
|
||||||
if (in_array($key, $required)) {
|
if (in_array($key, $required)) {
|
||||||
@@ -182,7 +184,8 @@ class DomainForm extends EntityForm {
|
|||||||
// Do not use domain loader because it may change hostname.
|
// Do not use domain loader because it may change hostname.
|
||||||
$existing = $this->domainStorage->loadByProperties(['hostname' => $hostname]);
|
$existing = $this->domainStorage->loadByProperties(['hostname' => $hostname]);
|
||||||
$existing = reset($existing);
|
$existing = reset($existing);
|
||||||
// If we have already registered a hostname, make sure we don't create a duplicate.
|
// If we have already registered a hostname, make sure we don't create a
|
||||||
|
// duplicate.
|
||||||
// We cannot check id() here, as the machine name is editable.
|
// We cannot check id() here, as the machine name is editable.
|
||||||
if ($existing && $existing->getDomainId() != $entity->getDomainId()) {
|
if ($existing && $existing->getDomainId() != $entity->getDomainId()) {
|
||||||
$form_state->setErrorByName('hostname', $this->t('The hostname is already registered.'));
|
$form_state->setErrorByName('hostname', $this->t('The hostname is already registered.'));
|
||||||
@@ -207,10 +210,10 @@ class DomainForm extends EntityForm {
|
|||||||
public function save(array $form, FormStateInterface $form_state) {
|
public function save(array $form, FormStateInterface $form_state) {
|
||||||
$status = parent::save($form, $form_state);
|
$status = parent::save($form, $form_state);
|
||||||
if ($status == SAVED_NEW) {
|
if ($status == SAVED_NEW) {
|
||||||
drupal_set_message($this->t('Domain record created.'));
|
\Drupal::messenger()->addMessage($this->t('Domain record created.'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message($this->t('Domain record updated.'));
|
\Drupal::messenger()->addMessage($this->t('Domain record updated.'));
|
||||||
}
|
}
|
||||||
$form_state->setRedirect('domain.admin');
|
$form_state->setRedirect('domain.admin');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,10 +213,8 @@ interface DomainInterface extends ConfigEntityInterface {
|
|||||||
/**
|
/**
|
||||||
* Find the port used for the domain.
|
* Find the port used for the domain.
|
||||||
*
|
*
|
||||||
* @param \Drupal\domain\DomainInterface $domain
|
* @return string
|
||||||
* A domain entity.
|
* An optional port string (e.g. ':8080') or an empty string;
|
||||||
*
|
|
||||||
* @return An optional port string (e.g. ':8080') or an empty string;
|
|
||||||
*/
|
*/
|
||||||
public function getPort();
|
public function getPort();
|
||||||
|
|
||||||
@@ -226,7 +224,7 @@ interface DomainInterface extends ConfigEntityInterface {
|
|||||||
public function createDomainId();
|
public function createDomainId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the canonical (registered) hostname for the domaim.
|
* Retrieves the canonical (registered) hostname for the domain.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* A hostname string.
|
* A hostname string.
|
||||||
@@ -234,7 +232,7 @@ interface DomainInterface extends ConfigEntityInterface {
|
|||||||
public function getCanonical();
|
public function getCanonical();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the canonical (registered) hostname for the domaim.
|
* Sets the canonical (registered) hostname for the domain.
|
||||||
*/
|
*/
|
||||||
public function setCanonical($hostname = NULL);
|
public function setCanonical($hostname = NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,12 @@ use Drupal\Core\Config\Entity\DraggableListBuilder;
|
|||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
|
||||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\Render\Element;
|
use Drupal\Core\Render\Element;
|
||||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Core\Url;
|
use Drupal\Core\Url;
|
||||||
use Drupal\domain\DomainAccessControlHandler;
|
|
||||||
use Drupal\domain\DomainStorageInterface;
|
|
||||||
use Drupal\domain\DomainElementManager;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,11 +66,25 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
*/
|
*/
|
||||||
protected $domainStorage;
|
protected $domainStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The domain field element manager.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainElementManagerInterface
|
||||||
|
*/
|
||||||
|
protected $domainElementManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The User storage handler.
|
||||||
|
*
|
||||||
|
* @var \Drupal\user\UserStorageInterface
|
||||||
|
*/
|
||||||
|
protected $userStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of entities to list per page.
|
* The number of entities to list per page.
|
||||||
*
|
*
|
||||||
* DraggableListBuilder sets this to FALSE, which cancels any pagination. Restore the
|
* DraggableListBuilder sets this to FALSE, which cancels any pagination.
|
||||||
* default value from EntityListBuilder.
|
* Restore the default value from EntityListBuilder.
|
||||||
*
|
*
|
||||||
* @var int|false
|
* @var int|false
|
||||||
*/
|
*/
|
||||||
@@ -96,7 +106,7 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new EntityListBuilder object.
|
* Constructs a new DomainListBuilder object.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
* The entity type definition.
|
* The entity type definition.
|
||||||
@@ -104,16 +114,16 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
* The domain storage class.
|
* The domain storage class.
|
||||||
* @param \Drupal\Core\Session\AccountInterface $account
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
* The active user account.
|
* The active user account.
|
||||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $destination
|
* @param \Drupal\Core\Routing\RedirectDestinationInterface $destination_handler
|
||||||
* The redirect destination helper.
|
* The redirect destination helper.
|
||||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||||
* The module handler.
|
* The module handler.
|
||||||
* @param \Drupal\domain\DomainElementManager $domain_element_manager
|
* @param \Drupal\domain\DomainElementManagerInterface $domain_element_manager
|
||||||
* The domain field element manager.
|
* The domain field element manager.
|
||||||
*/
|
*/
|
||||||
public function __construct(EntityTypeInterface $entity_type, DomainStorageInterface $domain_storage, AccountInterface $account, RedirectDestinationInterface $destination_handler, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, DomainElementManager $domain_element_manager) {
|
public function __construct(EntityTypeInterface $entity_type, DomainStorageInterface $domain_storage, AccountInterface $account, RedirectDestinationInterface $destination_handler, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, DomainElementManagerInterface $domain_element_manager) {
|
||||||
parent::__construct($entity_type, $domain_storage);
|
parent::__construct($entity_type, $domain_storage);
|
||||||
$this->entityTypeId = $entity_type->id();
|
$this->entityTypeId = $entity_type->id();
|
||||||
$this->domainStorage = $domain_storage;
|
$this->domainStorage = $domain_storage;
|
||||||
@@ -152,35 +162,35 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
$super_admin = $this->currentUser->hasPermission('administer domains');
|
$super_admin = $this->currentUser->hasPermission('administer domains');
|
||||||
if ($super_admin || $this->currentUser->hasPermission('access inactive domains')) {
|
if ($super_admin || $this->currentUser->hasPermission('access inactive domains')) {
|
||||||
if ($entity->status() && !$default) {
|
if ($entity->status() && !$default) {
|
||||||
$operations['disable'] = array(
|
$operations['disable'] = [
|
||||||
'title' => $this->t('Disable'),
|
'title' => $this->t('Disable'),
|
||||||
'url' => Url::fromRoute('domain.inline_action', array('op' => 'disable', 'domain' => $id)),
|
'url' => Url::fromRoute('domain.inline_action', ['op' => 'disable', 'domain' => $id]),
|
||||||
'weight' => 50,
|
'weight' => 50,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
elseif (!$default) {
|
elseif (!$default) {
|
||||||
$operations['enable'] = array(
|
$operations['enable'] = [
|
||||||
'title' => $this->t('Enable'),
|
'title' => $this->t('Enable'),
|
||||||
'url' => Url::fromRoute('domain.inline_action', array('op' => 'enable', 'domain' => $id)),
|
'url' => Url::fromRoute('domain.inline_action', ['op' => 'enable', 'domain' => $id]),
|
||||||
'weight' => 40,
|
'weight' => 40,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$default && $super_admin) {
|
if (!$default && $super_admin) {
|
||||||
$operations['default'] = array(
|
$operations['default'] = [
|
||||||
'title' => $this->t('Make default'),
|
'title' => $this->t('Make default'),
|
||||||
'url' => Url::fromRoute('domain.inline_action', array('op' => 'default', 'domain' => $id)),
|
'url' => Url::fromRoute('domain.inline_action', ['op' => 'default', 'domain' => $id]),
|
||||||
'weight' => 30,
|
'weight' => 30,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
if (!$default && $this->accessHandler->checkAccess($entity, 'delete')->isAllowed()) {
|
if (!$default && $this->accessHandler->checkAccess($entity, 'delete')->isAllowed()) {
|
||||||
$operations['delete'] = array(
|
$operations['delete'] = [
|
||||||
'title' => $this->t('Delete'),
|
'title' => $this->t('Delete'),
|
||||||
'url' => Url::fromRoute('entity.domain.delete_form', array('domain' => $id)),
|
'url' => Url::fromRoute('entity.domain.delete_form', ['domain' => $id]),
|
||||||
'weight' => 20,
|
'weight' => 20,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$operations += $this->moduleHandler->invokeAll('domain_operations', array($entity, $this->currentUser));
|
$operations += $this->moduleHandler->invokeAll('domain_operations', [$entity, $this->currentUser]);
|
||||||
foreach ($operations as $key => $value) {
|
foreach ($operations as $key => $value) {
|
||||||
if (isset($value['query']['token'])) {
|
if (isset($value['query']['token'])) {
|
||||||
$operations[$key]['query'] += $destination;
|
$operations[$key]['query'] += $destination;
|
||||||
@@ -222,13 +232,13 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$row['label'] = $this->getLabel($entity);
|
$row['label'] = $this->getLabel($entity);
|
||||||
$row['hostname'] = array('#markup' => $entity->getLink());
|
$row['hostname'] = ['#markup' => $entity->getLink()];
|
||||||
if ($entity->isActive()) {
|
if ($entity->isActive()) {
|
||||||
$row['hostname']['#prefix'] = '<strong>';
|
$row['hostname']['#prefix'] = '<strong>';
|
||||||
$row['hostname']['#suffix'] = '</strong>';
|
$row['hostname']['#suffix'] = '</strong>';
|
||||||
}
|
}
|
||||||
$row['status'] = array('#markup' => $entity->status() ? $this->t('Active') : $this->t('Inactive'));
|
$row['status'] = ['#markup' => $entity->status() ? $this->t('Active') : $this->t('Inactive')];
|
||||||
$row['is_default'] = array('#markup' => ($entity->isDefault() ? $this->t('Yes') : $this->t('No')));
|
$row['is_default'] = ['#markup' => ($entity->isDefault() ? $this->t('Yes') : $this->t('No'))];
|
||||||
$row += parent::buildRow($entity);
|
$row += parent::buildRow($entity);
|
||||||
|
|
||||||
if (!$this->currentUser->hasPermission('administer domains')) {
|
if (!$this->currentUser->hasPermission('administer domains')) {
|
||||||
@@ -280,7 +290,6 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal sort method for form weights.
|
* Internal sort method for form weights.
|
||||||
*/
|
*/
|
||||||
@@ -294,8 +303,8 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* Builds the entity listing as a form with pagination. This method overrides both
|
* Builds the entity listing as a form with pagination. This method overrides
|
||||||
* Drupal\Core\Config\Entity\DraggableListBuilder::render() and
|
* both Drupal\Core\Config\Entity\DraggableListBuilder::render() and
|
||||||
* Drupal\Core\Entity\EntityListBuilder::render().
|
* Drupal\Core\Entity\EntityListBuilder::render().
|
||||||
*/
|
*/
|
||||||
public function render() {
|
public function render() {
|
||||||
@@ -304,9 +313,9 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
|
|
||||||
// Only add the pager if a limit is specified.
|
// Only add the pager if a limit is specified.
|
||||||
if ($this->limit) {
|
if ($this->limit) {
|
||||||
$form['pager'] = array(
|
$form['pager'] = [
|
||||||
'#type' => 'pager',
|
'#type' => 'pager',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
@@ -314,8 +323,8 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* Loads entity IDs using a pager sorted by the entity weight. The default behavior when
|
* Loads entity IDs using a pager sorted by the entity weight. The default
|
||||||
* using a limit is to sort by id.
|
* behavior when using a limit is to sort by id.
|
||||||
*
|
*
|
||||||
* We also have to limit by assigned domains of the active user.
|
* We also have to limit by assigned domains of the active user.
|
||||||
*
|
*
|
||||||
@@ -328,10 +337,10 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
$query = $this->getStorage()->getQuery()
|
$query = $this->getStorage()->getQuery()
|
||||||
->sort($this->entityType->getKey('weight'));
|
->sort($this->entityType->getKey('weight'));
|
||||||
|
|
||||||
// If the user cannot administer domains, we must filter the query further by
|
// If the user cannot administer domains, we must filter the query further
|
||||||
// assigned IDs. We don't have to check permissions here, because that is handled by
|
// by assigned IDs. We don't have to check permissions here, because that is
|
||||||
// the route system and buildRow(). There are two permissions that allow users to view
|
// handled by the route system and buildRow(). There are two permissions
|
||||||
// the entire list.
|
// that allow users to view the entire list.
|
||||||
if (!$this->currentUser->hasPermission('administer domains') && !$this->currentUser->hasPermission('view domain list')) {
|
if (!$this->currentUser->hasPermission('administer domains') && !$this->currentUser->hasPermission('view domain list')) {
|
||||||
$user = $this->userStorage->load($this->currentUser->id());
|
$user = $this->userStorage->load($this->currentUser->id());
|
||||||
$allowed = $this->domainElementManager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
$allowed = $this->domainElementManager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
||||||
@@ -344,4 +353,5 @@ class DomainListBuilder extends DraggableListBuilder {
|
|||||||
}
|
}
|
||||||
return $query->execute();
|
return $query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Drupal\Core\Config\TypedConfigManagerInterface;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads Domain records.
|
* Loads Domain records.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* This class will be removed before the 8.1.0 release.
|
* This class will be removed before the 8.1.0 release.
|
||||||
* Use DomainStorage instead, loaded through the EntityTypeManager.
|
* Use DomainStorage instead, loaded through the EntityTypeManager.
|
||||||
@@ -49,7 +50,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
*/
|
*/
|
||||||
public function loadSchema() {
|
public function loadSchema() {
|
||||||
$fields = $this->typedConfig->getDefinition('domain.record.*');
|
$fields = $this->typedConfig->getDefinition('domain.record.*');
|
||||||
return isset($fields['mapping']) ? $fields['mapping'] : array();
|
return isset($fields['mapping']) ? $fields['mapping'] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +59,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
public function load($id, $reset = FALSE) {
|
public function load($id, $reset = FALSE) {
|
||||||
$controller = $this->getStorage();
|
$controller = $this->getStorage();
|
||||||
if ($reset) {
|
if ($reset) {
|
||||||
$controller->resetCache(array($id));
|
$controller->resetCache([$id]);
|
||||||
}
|
}
|
||||||
return $controller->load($id);
|
return $controller->load($id);
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadDefaultDomain() {
|
public function loadDefaultDomain() {
|
||||||
$result = $this->getStorage()->loadByProperties(array('is_default' => TRUE));
|
$result = $this->getStorage()->loadByProperties(['is_default' => TRUE]);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
return current($result);
|
return current($result);
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
*/
|
*/
|
||||||
public function loadMultipleSorted(array $ids = NULL) {
|
public function loadMultipleSorted(array $ids = NULL) {
|
||||||
$domains = $this->loadMultiple($ids);
|
$domains = $this->loadMultiple($ids);
|
||||||
uasort($domains, array($this, 'sort'));
|
uasort($domains, [$this, 'sort']);
|
||||||
return $domains;
|
return $domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
*/
|
*/
|
||||||
public function loadByHostname($hostname) {
|
public function loadByHostname($hostname) {
|
||||||
$hostname = $this->prepareHostname($hostname);
|
$hostname = $this->prepareHostname($hostname);
|
||||||
$result = $this->getStorage()->loadByProperties(array('hostname' => $hostname));
|
$result = $this->getStorage()->loadByProperties(['hostname' => $hostname]);
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,7 @@ class DomainLoader implements DomainLoaderInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadOptionsList() {
|
public function loadOptionsList() {
|
||||||
$list = array();
|
$list = [];
|
||||||
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
||||||
$list[$id] = $domain->label();
|
$list[$id] = $domain->label();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Drupal\domain;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Supplies loader methods for common domain requests.
|
* Supplies loader methods for common domain requests.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* This interface will be removed before the 8.1.0 release.
|
* This interface will be removed before the 8.1.0 release.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The HTTP_HOST value of the request.
|
* The HTTP_HOST value of the request.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $httpHost;
|
protected $httpHost;
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
|||||||
* The request stack object.
|
* The request stack object.
|
||||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||||
* The module handler.
|
* The module handler.
|
||||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||||
* The config factory.
|
* The config factory.
|
||||||
@@ -103,8 +105,8 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
|||||||
// If a straight load fails, create a base domain for checking. This data
|
// If a straight load fails, create a base domain for checking. This data
|
||||||
// is required for hook_domain_request_alter().
|
// is required for hook_domain_request_alter().
|
||||||
else {
|
else {
|
||||||
$values = array('hostname' => $httpHost);
|
$values = ['hostname' => $httpHost];
|
||||||
/** @var \Drupal\domain\Entity\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
$domain = $this->domainStorage->create($values);
|
$domain = $this->domainStorage->create($values);
|
||||||
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
||||||
}
|
}
|
||||||
@@ -204,8 +206,8 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
// Check for registered alias matches.
|
// Check for registered alias matches.
|
||||||
$values = array('hostname' => $hostname);
|
$values = ['hostname' => $hostname];
|
||||||
/** @var \Drupal\domain\Entity\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
$domain = $this->domainStorage->create($values);
|
$domain = $this->domainStorage->create($values);
|
||||||
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ interface DomainNegotiatorInterface {
|
|||||||
* @param string $hostname
|
* @param string $hostname
|
||||||
* A string representing the hostname of the request (e.g. example.com).
|
* A string representing the hostname of the request (e.g. example.com).
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool
|
||||||
|
* TRUE if a URL's hostname is registered as a valid domain or alias, or
|
||||||
|
* FALSE.
|
||||||
*/
|
*/
|
||||||
public function isRegisteredDomain($hostname);
|
public function isRegisteredDomain($hostname);
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,20 @@
|
|||||||
|
|
||||||
namespace Drupal\domain;
|
namespace Drupal\domain;
|
||||||
|
|
||||||
use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
|
|
||||||
use Drupal\Core\Cache\CacheableResponseInterface;
|
|
||||||
use Drupal\Core\Cache\CacheableResponseTrait;
|
|
||||||
use Drupal\Core\Routing\CacheableSecuredRedirectResponse;
|
use Drupal\Core\Routing\CacheableSecuredRedirectResponse;
|
||||||
use Drupal\Core\Routing\RequestContext;
|
use Drupal\Core\Routing\RequestContext;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Drupal\Component\Utility\UrlHelper;
|
use Drupal\Component\Utility\UrlHelper;
|
||||||
use Drupal\Core\Http\TrustedHostsRequestFactory;
|
|
||||||
use Drupal\Core\Site\Settings;
|
use Drupal\Core\Site\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a redirect response which understands domain URLs are local to the install.
|
* A redirect response which understands domain URLs are local to the install.
|
||||||
*
|
*
|
||||||
* This class can be used in cases where LocalRedirectResponse needs to be domain
|
* This class can be used in cases where LocalRedirectResponse needs to be
|
||||||
* sensitive. The main implementation is in DomainSourceRedirectResponseSubscriber.
|
* domain sensitive. The main implementation is in
|
||||||
|
* DomainSourceRedirectResponseSubscriber.
|
||||||
*
|
*
|
||||||
* This class combines LocalAwareRedirectResponseTrait and UrlHelper methods that
|
* This class combines LocalAwareRedirectResponseTrait and UrlHelper methods
|
||||||
* cannot be overridden safely otherwise.
|
* that cannot be overridden safely otherwise.
|
||||||
*/
|
*/
|
||||||
class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||||
|
|
||||||
@@ -64,6 +59,7 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
|||||||
* Returns the request context.
|
* Returns the request context.
|
||||||
*
|
*
|
||||||
* @return \Drupal\Core\Routing\RequestContext
|
* @return \Drupal\Core\Routing\RequestContext
|
||||||
|
* The request context.
|
||||||
*/
|
*/
|
||||||
protected function getRequestContext() {
|
protected function getRequestContext() {
|
||||||
if (!isset($this->requestContext)) {
|
if (!isset($this->requestContext)) {
|
||||||
@@ -90,16 +86,16 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
|||||||
* Determines if an external URL points to this domain-aware installation.
|
* Determines if an external URL points to this domain-aware installation.
|
||||||
*
|
*
|
||||||
* This method replaces the logic in
|
* This method replaces the logic in
|
||||||
* Drupal\Component\Utility\UrlHelper::externalIsLocal(). Since that class is not
|
* Drupal\Component\Utility\UrlHelper::externalIsLocal(). Since that class is
|
||||||
* directly extendable, we have to replace it.
|
* not directly extendable, we have to replace it.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* A string containing an external URL, such as "http://example.com/foo".
|
* A string containing an external URL, such as "http://example.com/foo".
|
||||||
|
* @param string $base_url
|
||||||
|
* The base URL string to check against, such as "http://example.com/".
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* TRUE if the URL has the same domain and base path.
|
* TRUE if the URL has the same domain and base path.
|
||||||
* @param string $base_url
|
|
||||||
* The base URL string to check against, such as "http://example.com/"
|
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* Exception thrown when $url is not fully qualified.
|
* Exception thrown when $url is not fully qualified.
|
||||||
@@ -155,13 +151,15 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
|||||||
self::$trustedHosts = [];
|
self::$trustedHosts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim and remove port number from host. Host is lowercase as per RFC 952/2181
|
// Trim and remove port number from host. Host is lowercase as per RFC
|
||||||
$host = strtolower(preg_replace('/:\d+$/', '', trim($host)));
|
// 952/2181.
|
||||||
|
$host = mb_strtolower(preg_replace('/:\d+$/', '', trim($host)));
|
||||||
|
|
||||||
// In the original Symfony code, hostname validation runs here. We have removed that
|
// In the original Symfony code, hostname validation runs here. We have
|
||||||
// portion because Domains are already validated on creation.
|
// removed that portion because Domains are already validated on creation.
|
||||||
if (count(self::$trustedHostPatterns) > 0) {
|
if (count(self::$trustedHostPatterns) > 0) {
|
||||||
// To avoid host header injection attacks, you should provide a list of trusted host patterns
|
// To avoid host header injection attacks, you should provide a list of
|
||||||
|
// trusted host patterns.
|
||||||
if (in_array($host, self::$trustedHosts)) {
|
if (in_array($host, self::$trustedHosts)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -173,8 +171,9 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// In cases where trusted_host_patterns are not set, allow all. This is flagged as a
|
// In cases where trusted_host_patterns are not set, allow all. This is
|
||||||
// security issue by Drupal core in the Reports UI.
|
// flagged as a security issue by Drupal core in the Reports UI.
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ namespace Drupal\domain;
|
|||||||
|
|
||||||
use Drupal\Component\Uuid\UuidInterface;
|
use Drupal\Component\Uuid\UuidInterface;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
use Drupal\Core\Language\LanguageManagerInterface;
|
use Drupal\Core\Language\LanguageManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||||
use Drupal\domain\DomainStorageInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads Domain records.
|
* Loads Domain records.
|
||||||
@@ -66,7 +64,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
*/
|
*/
|
||||||
public function loadSchema() {
|
public function loadSchema() {
|
||||||
$fields = $this->typedConfig->getDefinition('domain.record.*');
|
$fields = $this->typedConfig->getDefinition('domain.record.*');
|
||||||
return isset($fields['mapping']) ? $fields['mapping'] : array();
|
return isset($fields['mapping']) ? $fields['mapping'] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,20 +82,19 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadDefaultDomain() {
|
public function loadDefaultDomain() {
|
||||||
$result = $this->loadByProperties(array('is_default' => TRUE));
|
$result = $this->loadByProperties(['is_default' => TRUE]);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
return current($result);
|
return current($result);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadMultipleSorted(array $ids = NULL) {
|
public function loadMultipleSorted(array $ids = NULL) {
|
||||||
$domains = $this->loadMultiple($ids);
|
$domains = $this->loadMultiple($ids);
|
||||||
uasort($domains, array($this, 'sort'));
|
uasort($domains, [$this, 'sort']);
|
||||||
return $domains;
|
return $domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +103,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
*/
|
*/
|
||||||
public function loadByHostname($hostname) {
|
public function loadByHostname($hostname) {
|
||||||
$hostname = $this->prepareHostname($hostname);
|
$hostname = $this->prepareHostname($hostname);
|
||||||
$result = $this->loadByProperties(array('hostname' => $hostname));
|
$result = $this->loadByProperties(['hostname' => $hostname]);
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -117,7 +114,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadOptionsList() {
|
public function loadOptionsList() {
|
||||||
$list = array();
|
$list = [];
|
||||||
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
||||||
$list[$id] = $domain->label();
|
$list[$id] = $domain->label();
|
||||||
}
|
}
|
||||||
@@ -153,12 +150,12 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
$values['hostname'] = $this->createHostname();
|
$values['hostname'] = $this->createHostname();
|
||||||
$values['name'] = \Drupal::config('system.site')->get('name');
|
$values['name'] = \Drupal::config('system.site')->get('name');
|
||||||
}
|
}
|
||||||
$values += array(
|
$values += [
|
||||||
'scheme' => $this->getDefaultScheme(),
|
'scheme' => $this->getDefaultScheme(),
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'weight' => count($domains) + 1,
|
'weight' => count($domains) + 1,
|
||||||
'is_default' => (int) empty($default),
|
'is_default' => (int) empty($default),
|
||||||
);
|
];
|
||||||
$domain = parent::create($values);
|
$domain = parent::create($values);
|
||||||
|
|
||||||
return $domain;
|
return $domain;
|
||||||
@@ -186,7 +183,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getDefaultScheme() {
|
public function getDefaultScheme() {
|
||||||
// Use the foundation request if possible/
|
// Use the foundation request if possible.
|
||||||
$request = \Drupal::request();
|
$request = \Drupal::request();
|
||||||
if (!empty($request)) {
|
if (!empty($request)) {
|
||||||
$scheme = $request->getScheme();
|
$scheme = $request->getScheme();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ interface DomainStorageInterface extends ConfigEntityStorageInterface {
|
|||||||
/**
|
/**
|
||||||
* Returns the id of the default domain.
|
* Returns the id of the default domain.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int|bool
|
||||||
* The id of the default domain or FALSE if none is set.
|
* The id of the default domain or FALSE if none is set.
|
||||||
*/
|
*/
|
||||||
public function loadDefaultId();
|
public function loadDefaultId();
|
||||||
@@ -116,7 +116,7 @@ interface DomainStorageInterface extends ConfigEntityStorageInterface {
|
|||||||
*
|
*
|
||||||
* This function helps us account for variable schemes across environments.
|
* This function helps us account for variable schemes across environments.
|
||||||
*
|
*
|
||||||
* @return $scheme
|
* @return string
|
||||||
* A string representation of s scheme (http|https).
|
* A string representation of s scheme (http|https).
|
||||||
*/
|
*/
|
||||||
public function getDefaultScheme();
|
public function getDefaultScheme();
|
||||||
|
|||||||
@@ -7,15 +7,11 @@ use Drupal\Core\Render\BubbleableMetadata;
|
|||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles requests for token creation.
|
* Token handler for Domain.
|
||||||
*
|
*
|
||||||
* TokenAPI still uses procedural code, but we have moved it to a class for
|
* TokenAPI still uses procedural code, but we have moved it to a class for
|
||||||
* easier refactoring.
|
* easier refactoring.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Token handler for Domain.
|
|
||||||
*/
|
|
||||||
class DomainToken {
|
class DomainToken {
|
||||||
|
|
||||||
use StringTranslationTrait;
|
use StringTranslationTrait;
|
||||||
@@ -30,21 +26,21 @@ class DomainToken {
|
|||||||
/**
|
/**
|
||||||
* The Domain storage handler.
|
* The Domain storage handler.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain\DomainStorageInterface $domainStorage
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
*/
|
*/
|
||||||
protected $domainStorage;
|
protected $domainStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Domain negotiator.
|
* The Domain negotiator.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain\DomainNegotiatorInterface $negotiator
|
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||||
*/
|
*/
|
||||||
protected $negotiator;
|
protected $negotiator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DomainToken object.
|
* Constructs a DomainToken object.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||||
* The domain negotiator.
|
* The domain negotiator.
|
||||||
@@ -60,64 +56,64 @@ class DomainToken {
|
|||||||
*/
|
*/
|
||||||
public function getTokenInfo() {
|
public function getTokenInfo() {
|
||||||
// Domain token types.
|
// Domain token types.
|
||||||
$info['types']['domain'] = array(
|
$info['types']['domain'] = [
|
||||||
'name' => $this->t('Domains'),
|
'name' => $this->t('Domains'),
|
||||||
'description' => $this->t('Tokens related to domains.'),
|
'description' => $this->t('Tokens related to domains.'),
|
||||||
'needs-data' => 'domain',
|
'needs-data' => 'domain',
|
||||||
);
|
];
|
||||||
// These two types require the Token contrib module.
|
// These two types require the Token contrib module.
|
||||||
$info['types']['current-domain'] = array(
|
$info['types']['current-domain'] = [
|
||||||
'name' => $this->t('Current domain'),
|
'name' => $this->t('Current domain'),
|
||||||
'description' => $this->t('Tokens related to the current domain.'),
|
'description' => $this->t('Tokens related to the current domain.'),
|
||||||
'type' => 'domain',
|
'type' => 'domain',
|
||||||
);
|
];
|
||||||
$info['types']['default-domain'] = array(
|
$info['types']['default-domain'] = [
|
||||||
'name' => $this->t('Default domain'),
|
'name' => $this->t('Default domain'),
|
||||||
'description' => $this->t('Tokens related to the default domain.'),
|
'description' => $this->t('Tokens related to the default domain.'),
|
||||||
'type' => 'domain',
|
'type' => 'domain',
|
||||||
);
|
];
|
||||||
|
|
||||||
// Domain tokens.
|
// Domain tokens.
|
||||||
$info['tokens']['domain']['id'] = array(
|
$info['tokens']['domain']['id'] = [
|
||||||
'name' => $this->t('Domain id'),
|
'name' => $this->t('Domain id'),
|
||||||
'description' => $this->t('The domain\'s numeric ID.'),
|
'description' => $this->t("The domain's numeric ID."),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['machine-name'] = array(
|
$info['tokens']['domain']['machine-name'] = [
|
||||||
'name' => $this->t('Domain machine name'),
|
'name' => $this->t('Domain machine name'),
|
||||||
'description' => $this->t('The domain machine identifier.'),
|
'description' => $this->t('The domain machine identifier.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['path'] = array(
|
$info['tokens']['domain']['path'] = [
|
||||||
'name' => $this->t('Domain path'),
|
'name' => $this->t('Domain path'),
|
||||||
'description' => $this->t('The base URL for the domain.'),
|
'description' => $this->t('The base URL for the domain.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['name'] = array(
|
$info['tokens']['domain']['name'] = [
|
||||||
'name' => $this->t('Domain name'),
|
'name' => $this->t('Domain name'),
|
||||||
'description' => $this->t('The domain name.'),
|
'description' => $this->t('The domain name.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['url'] = array(
|
$info['tokens']['domain']['url'] = [
|
||||||
'name' => $this->t('Domain URL'),
|
'name' => $this->t('Domain URL'),
|
||||||
'description' => $this->t('The domain\'s URL for the current page request.'),
|
'description' => $this->t("The domain's URL for the current page request."),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['hostname'] = array(
|
$info['tokens']['domain']['hostname'] = [
|
||||||
'name' => $this->t('Domain hostname'),
|
'name' => $this->t('Domain hostname'),
|
||||||
'description' => $this->t('The domain hostname.'),
|
'description' => $this->t('The domain hostname.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['scheme'] = array(
|
$info['tokens']['domain']['scheme'] = [
|
||||||
'name' => $this->t('Domain scheme'),
|
'name' => $this->t('Domain scheme'),
|
||||||
'description' => $this->t('The domain scheme.'),
|
'description' => $this->t('The domain scheme.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['status'] = array(
|
$info['tokens']['domain']['status'] = [
|
||||||
'name' => $this->t('Domain status'),
|
'name' => $this->t('Domain status'),
|
||||||
'description' => $this->t('The domain status.'),
|
'description' => $this->t('The domain status.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['weight'] = array(
|
$info['tokens']['domain']['weight'] = [
|
||||||
'name' => $this->t('Domain weight'),
|
'name' => $this->t('Domain weight'),
|
||||||
'description' => $this->t('The domain weight.'),
|
'description' => $this->t('The domain weight.'),
|
||||||
);
|
];
|
||||||
$info['tokens']['domain']['is_default'] = array(
|
$info['tokens']['domain']['is_default'] = [
|
||||||
'name' => $this->t('Domain default'),
|
'name' => $this->t('Domain default'),
|
||||||
'description' => $this->t('The domain is the default domain.'),
|
'description' => $this->t('The domain is the default domain.'),
|
||||||
);
|
];
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
@@ -126,7 +122,7 @@ class DomainToken {
|
|||||||
* Implements hook_tokens().
|
* Implements hook_tokens().
|
||||||
*/
|
*/
|
||||||
public function getTokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
|
public function getTokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
|
||||||
$replacements = array();
|
$replacements = [];
|
||||||
|
|
||||||
$domain = NULL;
|
$domain = NULL;
|
||||||
|
|
||||||
@@ -140,9 +136,11 @@ class DomainToken {
|
|||||||
$domain = $this->negotiator->getActiveDomain();
|
$domain = $this->negotiator->getActiveDomain();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'current-domain':
|
case 'current-domain':
|
||||||
$domain = $this->negotiator->getActiveDomain();
|
$domain = $this->negotiator->getActiveDomain();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'default-domain':
|
case 'default-domain':
|
||||||
$domain = $this->domainStorage->loadDefaultDomain();
|
$domain = $this->domainStorage->loadDefaultDomain();
|
||||||
break;
|
break;
|
||||||
@@ -168,6 +166,7 @@ class DomainToken {
|
|||||||
* We assume that the token will call an instance of DomainInterface.
|
* We assume that the token will call an instance of DomainInterface.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
* An array of callbacks keyed by the token string.
|
||||||
*/
|
*/
|
||||||
public function getCallbacks() {
|
public function getCallbacks() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use Drupal\Core\Config\ConfigFactoryInterface;
|
|||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
use Drupal\Component\Utility\Unicode;
|
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ class DomainValidator implements DomainValidatorInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function validate($hostname) {
|
public function validate($hostname) {
|
||||||
$error_list = array();
|
$error_list = [];
|
||||||
// Check for at least one dot or the use of 'localhost'.
|
// Check for at least one dot or the use of 'localhost'.
|
||||||
// Note that localhost can specify a port.
|
// Note that localhost can specify a port.
|
||||||
$localhost_check = explode(':', $hostname);
|
$localhost_check = explode(':', $hostname);
|
||||||
@@ -105,7 +104,7 @@ class DomainValidator implements DomainValidatorInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for lower case.
|
// Check for lower case.
|
||||||
if ($hostname != Unicode::strtolower($hostname)) {
|
if ($hostname != mb_strtolower($hostname)) {
|
||||||
$error_list[] = $this->t('Only lower-case characters are allowed.');
|
$error_list[] = $this->t('Only lower-case characters are allowed.');
|
||||||
}
|
}
|
||||||
// Check for 'www' prefix if redirection / handling is
|
// Check for 'www' prefix if redirection / handling is
|
||||||
@@ -148,7 +147,7 @@ class DomainValidator implements DomainValidatorInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getRequiredFields() {
|
public function getRequiredFields() {
|
||||||
return array('hostname', 'name', 'scheme', 'status', 'weight');
|
return ['hostname', 'name', 'scheme', 'status', 'weight'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $is_default;
|
protected $is_default = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The domain record protocol (e.g. http://).
|
* The domain record protocol (e.g. http://).
|
||||||
@@ -146,6 +146,8 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The canonical hostname for the domain.
|
* The canonical hostname for the domain.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $canonical;
|
protected $canonical;
|
||||||
|
|
||||||
@@ -154,15 +156,15 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
*/
|
*/
|
||||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||||
parent::preCreate($storage_controller, $values);
|
parent::preCreate($storage_controller, $values);
|
||||||
$domain_storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$default = $domain_storage->loadDefaultId();
|
$default = $domain_storage->loadDefaultId();
|
||||||
$count = $storage_controller->getQuery()->count()->execute();
|
$count = $storage_controller->getQuery()->count()->execute();
|
||||||
$values += array(
|
$values += [
|
||||||
'scheme' => empty($GLOBALS['is_https']) ? 'http' : 'https',
|
'scheme' => empty($GLOBALS['is_https']) ? 'http' : 'https',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'weight' => $count + 1,
|
'weight' => $count + 1,
|
||||||
'is_default' => (int) empty($default),
|
'is_default' => (int) empty($default),
|
||||||
);
|
];
|
||||||
// Note that we have not created a domain_id, which is only used for
|
// Note that we have not created a domain_id, which is only used for
|
||||||
// node access control and will be added on save.
|
// node access control and will be added on save.
|
||||||
}
|
}
|
||||||
@@ -210,18 +212,18 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
if (!$this->isDefault()) {
|
if (!$this->isDefault()) {
|
||||||
// Swap the current default.
|
// Swap the current default.
|
||||||
/** @var self $default */
|
/** @var self $default */
|
||||||
if ($default = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain()) {
|
if ($default = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain()) {
|
||||||
$default->is_default = 0;
|
$default->is_default = FALSE;
|
||||||
$default->setHostname($default->getCanonical());
|
$default->setHostname($default->getCanonical());
|
||||||
$default->save();
|
$default->save();
|
||||||
}
|
}
|
||||||
// Save the new default.
|
// Save the new default.
|
||||||
$this->is_default = 1;
|
$this->is_default = TRUE;
|
||||||
$this->setHostname($this->getCanonical());
|
$this->setHostname($this->getCanonical());
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message($this->t('The selected domain is already the default.'), 'warning');
|
\Drupal::messenger()->addMessage($this->t('The selected domain is already the default.'), 'warning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +246,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message($this->t('The default domain cannot be disabled.'), 'warning');
|
\Drupal::messenger()->addMessage($this->t('The default domain cannot be disabled.'), 'warning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,14 +258,14 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
$this->{$name} = $value;
|
$this->{$name} = $value;
|
||||||
$this->setHostname($this->getCanonical());
|
$this->setHostname($this->getCanonical());
|
||||||
$this->save();
|
$this->save();
|
||||||
drupal_set_message($this->t('The @key attribute was set to @value for domain @hostname.', array(
|
\Drupal::messenger()->addMessage($this->t('The @key attribute was set to @value for domain @hostname.', [
|
||||||
'@key' => $name,
|
'@key' => $name,
|
||||||
'@value' => $value,
|
'@value' => $value,
|
||||||
'@hostname' => $this->hostname,
|
'@hostname' => $this->hostname,
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message($this->t('The @key attribute does not exist.', array('@key' => $name)));
|
\Drupal::messenger()->addMessage($this->t('The @key attribute does not exist.', ['@key' => $name]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,14 +273,16 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setPath() {
|
public function setPath() {
|
||||||
$this->path = $this->getScheme() . $this->getHostname() . base_path();
|
global $base_path;
|
||||||
|
$this->path = $this->getScheme() . $this->getHostname() . ($base_path ?: '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setUrl() {
|
public function setUrl() {
|
||||||
$uri = \Drupal::request()->getRequestUri();
|
$request = \Drupal::request();
|
||||||
|
$uri = $request ? $request->getRequestUri() : '/';
|
||||||
$this->url = $this->getScheme() . $this->getHostname() . $uri;
|
$this->url = $this->getScheme() . $this->getHostname() . $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,11 +336,11 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
/** @var self $default */
|
/** @var self $default */
|
||||||
$default = $storage->loadDefaultDomain();
|
$default = $storage->loadDefaultDomain();
|
||||||
if (!$default) {
|
if (!$default) {
|
||||||
$this->is_default = 1;
|
$this->is_default = TRUE;
|
||||||
}
|
}
|
||||||
elseif ($this->is_default && $default->getDomainId() != $this->getDomainId()) {
|
elseif ($this->is_default && $default->getDomainId() != $this->getDomainId()) {
|
||||||
// Swap the current default.
|
// Swap the current default.
|
||||||
$default->is_default = 0;
|
$default->is_default = FALSE;
|
||||||
$default->save();
|
$default->save();
|
||||||
}
|
}
|
||||||
// Ensures we have a proper domain_id.
|
// Ensures we have a proper domain_id.
|
||||||
@@ -390,8 +394,9 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
// across environments. Instead, we use the crc32 hash function to create a
|
// across environments. Instead, we use the crc32 hash function to create a
|
||||||
// unique numeric id for each domain. In some systems (Windows?) we have
|
// unique numeric id for each domain. In some systems (Windows?) we have
|
||||||
// reports of crc32 returning a negative number. Issue #2794047.
|
// reports of crc32 returning a negative number. Issue #2794047.
|
||||||
// If we don't use hash(), then crc32() returns different results for 32- and 64-bit
|
// If we don't use hash(), then crc32() returns different results for 32-
|
||||||
// systems. On 32-bit systems, the number returned may also be too large for PHP.
|
// and 64-bit systems. On 32-bit systems, the number returned may also be
|
||||||
|
// too large for PHP.
|
||||||
// See #2908236.
|
// See #2908236.
|
||||||
$id = hash('crc32', $this->id());
|
$id = hash('crc32', $this->id());
|
||||||
$id = abs(hexdec(substr($id, 0, -2)));
|
$id = abs(hexdec(substr($id, 0, -2)));
|
||||||
@@ -401,13 +406,13 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
/**
|
/**
|
||||||
* Creates a unique numeric id for use in the {node_access} table.
|
* Creates a unique numeric id for use in the {node_access} table.
|
||||||
*
|
*
|
||||||
* @param integer $id
|
* @param int $id
|
||||||
* An integer to ue as the numeric id.
|
* An integer to use as the numeric id.
|
||||||
*/
|
*/
|
||||||
public function createNumericId($id) {
|
public function createNumericId($id) {
|
||||||
// Ensure that this value is unique.
|
// Ensure that this value is unique.
|
||||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$result = $storage->loadByProperties(array('domain_id' => $id));
|
$result = $storage->loadByProperties(['domain_id' => $id]);
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
$this->domain_id = $id;
|
$this->domain_id = $id;
|
||||||
}
|
}
|
||||||
@@ -423,7 +428,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
public function getScheme($add_suffix = TRUE) {
|
public function getScheme($add_suffix = TRUE) {
|
||||||
$scheme = $this->scheme;
|
$scheme = $this->scheme;
|
||||||
if ($scheme == 'variable') {
|
if ($scheme == 'variable') {
|
||||||
$scheme = \Drupal::service('entity_type.manager')->getStorage('domain')->getDefaultScheme();
|
$scheme = \Drupal::entityTypeManager()->getStorage('domain')->getDefaultScheme();
|
||||||
}
|
}
|
||||||
elseif ($scheme != 'https') {
|
elseif ($scheme != 'https') {
|
||||||
$scheme = 'http';
|
$scheme = 'http';
|
||||||
@@ -462,7 +467,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getLink($current_path = TRUE) {
|
public function getLink($current_path = TRUE) {
|
||||||
$options = array('absolute' => TRUE, 'https' => $this->isHttps());
|
$options = ['absolute' => TRUE, 'https' => $this->isHttps()];
|
||||||
if ($current_path) {
|
if ($current_path) {
|
||||||
$url = Url::fromUri($this->getUrl(), $options);
|
$url = Url::fromUri($this->getUrl(), $options);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -4,7 +4,6 @@ namespace Drupal\domain\EventSubscriber;
|
|||||||
|
|
||||||
use Drupal\domain\Access\DomainAccessCheck;
|
use Drupal\domain\Access\DomainAccessCheck;
|
||||||
use Drupal\domain\DomainNegotiatorInterface;
|
use Drupal\domain\DomainNegotiatorInterface;
|
||||||
use Drupal\domain\DomainStorageInterface;
|
|
||||||
use Drupal\domain\DomainRedirectResponse;
|
use Drupal\domain\DomainRedirectResponse;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Routing\TrustedRedirectResponse;
|
use Drupal\Core\Routing\TrustedRedirectResponse;
|
||||||
@@ -59,7 +58,7 @@ class DomainSubscriber implements EventSubscriberInterface {
|
|||||||
*
|
*
|
||||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||||
* The domain negotiator service.
|
* The domain negotiator service.
|
||||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
* The entity type manager.
|
* The entity type manager.
|
||||||
* @param \Drupal\domain\Access\DomainAccessCheck $access_check
|
* @param \Drupal\domain\Access\DomainAccessCheck $access_check
|
||||||
* The access check interface.
|
* The access check interface.
|
||||||
@@ -120,7 +119,8 @@ class DomainSubscriber implements EventSubscriberInterface {
|
|||||||
$response = new TrustedRedirectResponse($domain_url, $redirect_status);
|
$response = new TrustedRedirectResponse($domain_url, $redirect_status);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If the redirect is not to a registered hostname, reject the request.
|
// If the redirect is not to a registered hostname, reject the
|
||||||
|
// request.
|
||||||
$response = new Response('The provided host name is not a valid redirect.', 401);
|
$response = new Response('The provided host name is not a valid redirect.', 401);
|
||||||
}
|
}
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
@@ -133,7 +133,7 @@ class DomainSubscriber implements EventSubscriberInterface {
|
|||||||
*/
|
*/
|
||||||
public static function getSubscribedEvents() {
|
public static function getSubscribedEvents() {
|
||||||
// This needs to fire very early in the stack, before accounts are cached.
|
// This needs to fire very early in the stack, before accounts are cached.
|
||||||
$events[KernelEvents::REQUEST][] = array('onKernelRequestDomain', 50);
|
$events[KernelEvents::REQUEST][] = ['onKernelRequestDomain', 50];
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class DomainDeleteForm extends EntityConfirmFormBase {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getQuestion() {
|
public function getQuestion() {
|
||||||
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
|
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,8 +37,8 @@ class DomainDeleteForm extends EntityConfirmFormBase {
|
|||||||
*/
|
*/
|
||||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
$this->entity->delete();
|
$this->entity->delete();
|
||||||
drupal_set_message($this->t('Domain %label has been deleted.', array('%label' => $this->entity->label())));
|
\Drupal::messenger()->addMessage($this->t('Domain %label has been deleted.', ['%label' => $this->entity->label()]));
|
||||||
\Drupal::logger('domain')->notice('Domain %label has been deleted.', array('%label' => $this->entity->label()));
|
\Drupal::logger('domain')->notice('Domain %label has been deleted.', ['%label' => $this->entity->label()]);
|
||||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Settings form for Domain module.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Drupal\domain\Form;
|
namespace Drupal\domain\Form;
|
||||||
|
|
||||||
use Drupal\Core\Form\ConfigFormBase;
|
use Drupal\Core\Form\ConfigFormBase;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DomainSettingsForm.
|
||||||
|
*
|
||||||
|
* @package Drupal\domain\Form
|
||||||
|
*/
|
||||||
class DomainSettingsForm extends ConfigFormBase {
|
class DomainSettingsForm extends ConfigFormBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -29,39 +31,42 @@ class DomainSettingsForm extends ConfigFormBase {
|
|||||||
*/
|
*/
|
||||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
$config = $this->config('domain.settings');
|
$config = $this->config('domain.settings');
|
||||||
$form['allow_non_ascii'] = array(
|
$form['allow_non_ascii'] = [
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => $this->t('Allow non-ASCII characters in domains and aliases'),
|
'#title' => $this->t('Allow non-ASCII characters in domains and aliases'),
|
||||||
'#default_value' => $config->get('allow_non_ascii'),
|
'#default_value' => $config->get('allow_non_ascii'),
|
||||||
'#description' => $this->t('Domains may be registered with international character sets. Note that not all DNS server respect non-ascii characters.'),
|
'#description' => $this->t('Domains may be registered with international character sets. Note that not all DNS server respect non-ascii characters.'),
|
||||||
);
|
];
|
||||||
$form['www_prefix'] = array(
|
$form['www_prefix'] = [
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => $this->t('Ignore www prefix when negotiating domains'),
|
'#title' => $this->t('Ignore www prefix when negotiating domains'),
|
||||||
'#default_value' => $config->get('www_prefix'),
|
'#default_value' => $config->get('www_prefix'),
|
||||||
'#description' => $this->t('Domain negotiation will ignore any www prefixes for all requests.'),
|
'#description' => $this->t('Domain negotiation will ignore any www prefixes for all requests.'),
|
||||||
);
|
];
|
||||||
// Get the usable tokens for this field.
|
// Get the usable tokens for this field.
|
||||||
|
$patterns = [];
|
||||||
foreach (\Drupal::service('domain.token')->getCallbacks() as $key => $callback) {
|
foreach (\Drupal::service('domain.token')->getCallbacks() as $key => $callback) {
|
||||||
$patterns[] = "[domain:$key]";
|
$patterns[] = "[domain:$key]";
|
||||||
}
|
}
|
||||||
$form['css_classes'] = array(
|
$form['css_classes'] = [
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#size' => 80,
|
'#size' => 80,
|
||||||
'#title' => $this->t('Custom CSS classes'),
|
'#title' => $this->t('Custom CSS classes'),
|
||||||
'#default_value' => $config->get('css_classes'),
|
'#default_value' => $config->get('css_classes'),
|
||||||
'#description' => $this->t('Enter any CSS classes that should be added to the <body> tag. Available replacement patterns are: ' . implode(', ', $patterns)),
|
'#description' => $this->t('Enter any CSS classes that should be added to the <body> tag. Available replacement patterns are: @patterns', [
|
||||||
);
|
'@patterns' => implode(', ', $patterns),
|
||||||
$form['login_paths'] = array(
|
]),
|
||||||
|
];
|
||||||
|
$form['login_paths'] = [
|
||||||
'#type' => 'textarea',
|
'#type' => 'textarea',
|
||||||
'#rows' => 5,
|
'#rows' => 5,
|
||||||
'#columns' => 40,
|
'#columns' => 40,
|
||||||
'#title' => $this->t('Paths that should be accessible for inactive domains'),
|
'#title' => $this->t('Paths that should be accessible for inactive domains'),
|
||||||
'#default_value' => $config->get('login_paths', "/user/login\r\n/user/password"),
|
'#default_value' => $config->get('login_paths'),
|
||||||
'#description' => $this->t('Inactive domains are only accessible to users with permission.
|
'#description' => $this->t('Inactive domains are only accessible to users with permission.
|
||||||
Enter any paths that should be accessible, one per line. Normally, only the
|
Enter any paths that should be accessible, one per line. Normally, only the
|
||||||
login path will be allowed.'),
|
login path will be allowed.'),
|
||||||
);
|
];
|
||||||
return parent::buildForm($form, $form_state);
|
return parent::buildForm($form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of settings.
|
* An array of settings.
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public $settings = [];
|
public $settings = [];
|
||||||
|
|
||||||
@@ -48,30 +50,30 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
'#default_value' => !empty($this->configuration['link_options']) ? $this->configuration['link_options'] : $defaults['link_options'],
|
'#default_value' => !empty($this->configuration['link_options']) ? $this->configuration['link_options'] : $defaults['link_options'],
|
||||||
'#description' => $this->t('Determines how links to each domain will be written. Note that some paths may not be accessible on all domains.'),
|
'#description' => $this->t('Determines how links to each domain will be written. Note that some paths may not be accessible on all domains.'),
|
||||||
];
|
];
|
||||||
$options = array(
|
$options = [
|
||||||
'select' => t('JavaScript select list'),
|
'select' => $this->t('JavaScript select list'),
|
||||||
'menus' => t('Menu-style tab links'),
|
'menus' => $this->t('Menu-style tab links'),
|
||||||
'ul' => t('Unordered list of links'),
|
'ul' => $this->t('Unordered list of links'),
|
||||||
);
|
];
|
||||||
$elements['link_theme'] = array(
|
$elements['link_theme'] = [
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => t('Link theme'),
|
'#title' => t('Link theme'),
|
||||||
'#default_value' => !empty($this->configuration['link_theme']) ? $this->configuration['link_theme'] : $defaults['link_theme'],
|
'#default_value' => !empty($this->configuration['link_theme']) ? $this->configuration['link_theme'] : $defaults['link_theme'],
|
||||||
'#options' => $options,
|
'#options' => $options,
|
||||||
'#description' => $this->t('Select how to display the block output.'),
|
'#description' => $this->t('Select how to display the block output.'),
|
||||||
);
|
];
|
||||||
$options = array(
|
$options = [
|
||||||
'name' => t('The domain display name'),
|
'name' => $this->t('The domain display name'),
|
||||||
'hostname' => t('The raw hostname'),
|
'hostname' => $this->t('The raw hostname'),
|
||||||
'url' => t('The domain base URL'),
|
'url' => $this->t('The domain base URL'),
|
||||||
);
|
];
|
||||||
$elements['link_label'] = array(
|
$elements['link_label'] = [
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => t('Link text'),
|
'#title' => $this->t('Link text'),
|
||||||
'#default_value' => !empty($this->configuration['link_label']) ? $this->configuration['link_label'] : $defaults['link_label'],
|
'#default_value' => !empty($this->configuration['link_label']) ? $this->configuration['link_label'] : $defaults['link_label'],
|
||||||
'#options' => $options,
|
'#options' => $options,
|
||||||
'#description' => $this->t('Select the text to display for each link.'),
|
'#description' => $this->t('Select the text to display for each link.'),
|
||||||
);
|
];
|
||||||
return $elements;
|
return $elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
* Overrides \Drupal\block\BlockBase::access().
|
* Overrides \Drupal\block\BlockBase::access().
|
||||||
*/
|
*/
|
||||||
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
||||||
$access = AccessResult::allowedIfHasPermissions($account, array('administer domains', 'use domain nav block'), 'OR');
|
$access = AccessResult::allowedIfHasPermissions($account, ['administer domains', 'use domain nav block'], 'OR');
|
||||||
return $return_as_object ? $access : $access->isAllowed();
|
return $return_as_object ? $access : $access->isAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +103,14 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
public function build() {
|
public function build() {
|
||||||
/** @var \Drupal\domain\DomainInterface $active_domain */
|
/** @var \Drupal\domain\DomainInterface $active_domain */
|
||||||
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||||
$access_handler = \Drupal::service('entity_type.manager')->getAccessControlHandler('domain');
|
$access_handler = \Drupal::entityTypeManager()->getAccessControlHandler('domain');
|
||||||
$account = \Drupal::currentUser();
|
$account = \Drupal::currentUser();
|
||||||
|
|
||||||
// Determine the visible domain list.
|
// Determine the visible domain list.
|
||||||
$items = [];
|
$items = [];
|
||||||
$add_path = ($this->getSetting('link_options') == 'active');
|
$add_path = ($this->getSetting('link_options') == 'active');
|
||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultipleSorted() as $domain) {
|
||||||
// Set the URL.
|
// Set the URL.
|
||||||
$options = ['absolute' => TRUE, 'https' => ($domain->getScheme() == 'https')];
|
$options = ['absolute' => TRUE, 'https' => ($domain->getScheme() == 'https')];
|
||||||
if ($add_path) {
|
if ($add_path) {
|
||||||
@@ -157,8 +159,9 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
switch ($this->getSetting('link_theme')) {
|
switch ($this->getSetting('link_theme')) {
|
||||||
case 'select':
|
case 'select':
|
||||||
$build['#theme'] = 'domain_nav_block';
|
$build['#theme'] = 'domain_nav_block';
|
||||||
$build['items'] = $items;
|
$build['#items'] = $items;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'menus':
|
case 'menus':
|
||||||
// Map the $items params to what menu.html.twig expects.
|
// Map the $items params to what menu.html.twig expects.
|
||||||
$build['#items'] = $items;
|
$build['#items'] = $items;
|
||||||
@@ -166,6 +169,7 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
$build['#sorted'] = TRUE;
|
$build['#sorted'] = TRUE;
|
||||||
$build['#theme'] = 'menu__' . strtr($build['#menu_name'], '-', '_');
|
$build['#theme'] = 'menu__' . strtr($build['#menu_name'], '-', '_');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ul':
|
case 'ul':
|
||||||
default:
|
default:
|
||||||
$build['#theme'] = 'item_list';
|
$build['#theme'] = 'item_list';
|
||||||
@@ -190,11 +194,11 @@ class DomainNavBlock extends DomainBlockBase {
|
|||||||
/**
|
/**
|
||||||
* Gets the configuration for the block, loading defaults if not set.
|
* Gets the configuration for the block, loading defaults if not set.
|
||||||
*
|
*
|
||||||
* @param $key
|
* @param string $key
|
||||||
* The setting key to retrieve, a string
|
* The setting key to retrieve, a string.
|
||||||
*
|
*
|
||||||
* @return
|
* @return string
|
||||||
*. The setting value, a string.
|
* The setting value, a string.
|
||||||
*/
|
*/
|
||||||
public function getSetting($key) {
|
public function getSetting($key) {
|
||||||
if (isset($this->settings[$key])) {
|
if (isset($this->settings[$key])) {
|
||||||
|
|||||||
+22
-23
@@ -5,7 +5,6 @@ namespace Drupal\domain\Plugin\Block;
|
|||||||
use Drupal\Component\Utility\Html;
|
use Drupal\Component\Utility\Html;
|
||||||
use Drupal\Core\Access\AccessResult;
|
use Drupal\Core\Access\AccessResult;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a server information block for a domain request.
|
* Provides a server information block for a domain request.
|
||||||
@@ -21,7 +20,7 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
* Overrides \Drupal\block\BlockBase::access().
|
* Overrides \Drupal\block\BlockBase::access().
|
||||||
*/
|
*/
|
||||||
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
||||||
$access = AccessResult::allowedIfHasPermissions($account, array('administer domains', 'view domain information'), 'OR');
|
$access = AccessResult::allowedIfHasPermissions($account, ['administer domains', 'view domain information'], 'OR');
|
||||||
return $return_as_object ? $access : $access->isAllowed();
|
return $return_as_object ? $access : $access->isAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,25 +31,25 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||||
if (!$domain) {
|
if (!$domain) {
|
||||||
return array(
|
return [
|
||||||
'#markup' => $this->t('No domain record could be loaded.'),
|
'#markup' => $this->t('No domain record could be loaded.'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$header = array($this->t('Server'), $this->t('Value'));
|
$header = [$this->t('Server'), $this->t('Value')];
|
||||||
$rows[] = array(
|
$rows[] = [
|
||||||
$this->t('HTTP_HOST request'),
|
$this->t('HTTP_HOST request'),
|
||||||
Html::escape($_SERVER['HTTP_HOST']),
|
Html::escape($_SERVER['HTTP_HOST']),
|
||||||
);
|
];
|
||||||
// Check the response test.
|
// Check the response test.
|
||||||
$domain->getResponse();
|
$domain->getResponse();
|
||||||
$check = \Drupal::service('entity_type.manager')->getStorage('domain')->loadByHostname($_SERVER['HTTP_HOST']);
|
$check = \Drupal::entityTypeManager()->getStorage('domain')->loadByHostname($_SERVER['HTTP_HOST']);
|
||||||
$match = $this->t('Exact match');
|
$match = $this->t('Exact match');
|
||||||
// This value is not translatable.
|
// This value is not translatable.
|
||||||
$environment = 'default';
|
$environment = 'default';
|
||||||
if (!$check) {
|
if (!$check) {
|
||||||
// Specific check for Domain Alias.
|
// Specific check for Domain Alias.
|
||||||
if (isset($domain->alias)) {
|
if (isset($domain->alias)) {
|
||||||
$match = $this->t('ALIAS: Using alias %id', array('%id' => $domain->alias->getPattern()));
|
$match = $this->t('ALIAS: Using alias %id', ['%id' => $domain->alias->getPattern()]);
|
||||||
// Get the environment.
|
// Get the environment.
|
||||||
$environment = $domain->alias->getEnvironment();
|
$environment = $domain->alias->getEnvironment();
|
||||||
}
|
}
|
||||||
@@ -58,10 +57,10 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
$match = $this->t('FALSE: Using default domain.');
|
$match = $this->t('FALSE: Using default domain.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$rows[] = array(
|
$rows[] = [
|
||||||
$this->t('Domain match'),
|
$this->t('Domain match'),
|
||||||
$match,
|
$match,
|
||||||
);
|
];
|
||||||
$rows[] = [
|
$rows[] = [
|
||||||
$this->t('Environment'),
|
$this->t('Environment'),
|
||||||
$environment,
|
$environment,
|
||||||
@@ -80,10 +79,10 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$www = \Drupal::config('domain.settings')->get('www_prefix');
|
$www = \Drupal::config('domain.settings')->get('www_prefix');
|
||||||
$rows[] = array(
|
$rows[] = [
|
||||||
$this->t('Strip www prefix'),
|
$this->t('Strip www prefix'),
|
||||||
!empty($www) ? $this->t('On') : $this->t('Off'),
|
!empty($www) ? $this->t('On') : $this->t('Off'),
|
||||||
);
|
];
|
||||||
$list = $domain->toArray();
|
$list = $domain->toArray();
|
||||||
ksort($list);
|
ksort($list);
|
||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
@@ -99,16 +98,16 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
elseif ($key == 'status' || $key == 'is_default') {
|
elseif ($key == 'status' || $key == 'is_default') {
|
||||||
$value = empty($value) ? $this->t('FALSE') : $this->t('TRUE');
|
$value = empty($value) ? $this->t('FALSE') : $this->t('TRUE');
|
||||||
}
|
}
|
||||||
$rows[] = array(
|
$rows[] = [
|
||||||
Html::escape($key),
|
Html::escape($key),
|
||||||
!is_array($value) ? Html::escape($value) : $this->printArray($value),
|
!is_array($value) ? Html::escape($value) : $this->printArray($value),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return array(
|
return [
|
||||||
'#theme' => 'table',
|
'#theme' => 'table',
|
||||||
'#rows' => $rows,
|
'#rows' => $rows,
|
||||||
'#header' => $header,
|
'#header' => $header,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,24 +120,24 @@ class DomainServerBlock extends DomainBlockBase {
|
|||||||
* A suitable output string.
|
* A suitable output string.
|
||||||
*/
|
*/
|
||||||
public function printArray(array $array) {
|
public function printArray(array $array) {
|
||||||
$items = array();
|
$items = [];
|
||||||
foreach ($array as $key => $val) {
|
foreach ($array as $key => $val) {
|
||||||
if (!is_array($val)) {
|
if (!is_array($val)) {
|
||||||
$value = Html::escape($val);
|
$value = Html::escape($val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$list = array();
|
$list = [];
|
||||||
foreach ($val as $k => $v) {
|
foreach ($val as $k => $v) {
|
||||||
$list[] = $this->t('@key : @value', array('@key' => $k, '@value' => $v));
|
$list[] = $this->t('@key : @value', ['@key' => $k, '@value' => $v]);
|
||||||
}
|
}
|
||||||
$value = implode('<br />', $list);
|
$value = implode('<br />', $list);
|
||||||
}
|
}
|
||||||
$items[] = $this->t('@key : @value', array('@key' => $key, '@value' => $value));
|
$items[] = $this->t('@key : @value', ['@key' => $key, '@value' => $value]);
|
||||||
}
|
}
|
||||||
$variables['domain_server'] = array(
|
$variables['domain_server'] = [
|
||||||
'#theme' => 'item_list',
|
'#theme' => 'item_list',
|
||||||
'#items' => $items,
|
'#items' => $items,
|
||||||
);
|
];
|
||||||
return render($variables);
|
return render($variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -19,7 +19,7 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
|||||||
* Overrides \Drupal\block\BlockBase::access().
|
* Overrides \Drupal\block\BlockBase::access().
|
||||||
*/
|
*/
|
||||||
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
||||||
$access = AccessResult::allowedIfHasPermissions($account, array('administer domains', 'use domain switcher block'), 'OR');
|
$access = AccessResult::allowedIfHasPermissions($account, ['administer domains', 'use domain switcher block'], 'OR');
|
||||||
return $return_as_object ? $access : $access->isAllowed();
|
return $return_as_object ? $access : $access->isAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
|||||||
public function build() {
|
public function build() {
|
||||||
/** @var \Drupal\domain\DomainInterface $active_domain */
|
/** @var \Drupal\domain\DomainInterface $active_domain */
|
||||||
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||||
$items = array();
|
$items = [];
|
||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultipleSorted() as $domain) {
|
||||||
$string = $domain->getLink();
|
$string = $domain->getLink();
|
||||||
if (!$domain->status()) {
|
if (!$domain->status()) {
|
||||||
$string .= '*';
|
$string .= '*';
|
||||||
@@ -39,12 +39,12 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
|||||||
if ($domain->id() == $active_domain->id()) {
|
if ($domain->id() == $active_domain->id()) {
|
||||||
$string = '<em>' . $string . '</em>';
|
$string = '<em>' . $string . '</em>';
|
||||||
}
|
}
|
||||||
$items[] = array('#markup' => $string);
|
$items[] = ['#markup' => $string];
|
||||||
}
|
}
|
||||||
return array(
|
return [
|
||||||
'#theme' => 'item_list',
|
'#theme' => 'item_list',
|
||||||
'#items' => $items,
|
'#items' => $items,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\domain\Plugin\Block;
|
namespace Drupal\domain\Plugin\Block;
|
||||||
|
|
||||||
use Drupal\Component\Utility\Html;
|
|
||||||
use Drupal\Core\Access\AccessResult;
|
use Drupal\Core\Access\AccessResult;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainInterface;
|
use Drupal\domain\DomainInterface;
|
||||||
@@ -21,7 +20,7 @@ class DomainTokenBlock extends DomainBlockBase {
|
|||||||
* Overrides \Drupal\block\BlockBase::access().
|
* Overrides \Drupal\block\BlockBase::access().
|
||||||
*/
|
*/
|
||||||
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
||||||
$access = AccessResult::allowedIfHasPermissions($account, array('administer domains', 'view domain information'), 'OR');
|
$access = AccessResult::allowedIfHasPermissions($account, ['administer domains', 'view domain information'], 'OR');
|
||||||
return $return_as_object ? $access : $access->isAllowed();
|
return $return_as_object ? $access : $access->isAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,16 +31,16 @@ class DomainTokenBlock extends DomainBlockBase {
|
|||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||||
if (!$domain) {
|
if (!$domain) {
|
||||||
return array(
|
return [
|
||||||
'#markup' => $this->t('No domain record could be loaded.'),
|
'#markup' => $this->t('No domain record could be loaded.'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$header = array($this->t('Token'), $this->t('Value'));
|
$header = [$this->t('Token'), $this->t('Value')];
|
||||||
return array(
|
return [
|
||||||
'#theme' => 'table',
|
'#theme' => 'table',
|
||||||
'#rows' => $this->renderTokens($domain),
|
'#rows' => $this->renderTokens($domain),
|
||||||
'#header' => $header,
|
'#header' => $header,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,11 +48,12 @@ class DomainTokenBlock extends DomainBlockBase {
|
|||||||
*
|
*
|
||||||
* @param \Drupal\domain\DomainInterface $domain
|
* @param \Drupal\domain\DomainInterface $domain
|
||||||
* The active domain request.
|
* The active domain request.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* An array keyed by token name, with value of replacement value.
|
* An array keyed by token name, with value of replacement value.
|
||||||
*/
|
*/
|
||||||
private function renderTokens(DomainInterface $domain) {
|
private function renderTokens(DomainInterface $domain) {
|
||||||
$rows = array();
|
$rows = [];
|
||||||
$token = \Drupal::token();
|
$token = \Drupal::token();
|
||||||
$tokens = $token->getInfo();
|
$tokens = $token->getInfo();
|
||||||
// The 'domain' token is supported by core. The others by Token module,
|
// The 'domain' token is supported by core. The others by Token module,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
* id = "domain",
|
* id = "domain",
|
||||||
* label = @Translation("Domain"),
|
* label = @Translation("Domain"),
|
||||||
* context = {
|
* context = {
|
||||||
* "entity:domain" = @ContextDefinition("entity:domain", label = @Translation("Domain"), required = FALSE)
|
* "entity:domain" = @ContextDefinition("entity:domain", label = @Translation("Domain"), required = TRUE)
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
@@ -61,18 +61,18 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||||
$form['domains'] = array(
|
$form['domains'] = [
|
||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
'#title' => $this->t('When the following domains are active'),
|
'#title' => $this->t('When the following domains are active'),
|
||||||
'#default_value' => $this->configuration['domains'],
|
'#default_value' => $this->configuration['domains'],
|
||||||
'#options' => array_map('\Drupal\Component\Utility\Html::escape', \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList()),
|
'#options' => array_map('\Drupal\Component\Utility\Html::escape', \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList()),
|
||||||
'#description' => $this->t('If you select no domains, the condition will evaluate to TRUE for all requests.'),
|
'#description' => $this->t('If you select no domains, the condition will evaluate to TRUE for all requests.'),
|
||||||
'#attached' => array(
|
'#attached' => [
|
||||||
'library' => array(
|
'library' => [
|
||||||
'domain/drupal.domain',
|
'domain/drupal.domain',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
return parent::buildConfigurationForm($form, $form_state);
|
return parent::buildConfigurationForm($form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function defaultConfiguration() {
|
public function defaultConfiguration() {
|
||||||
return array(
|
return [
|
||||||
'domains' => array(),
|
'domains' => [],
|
||||||
) + parent::defaultConfiguration();
|
] + parent::defaultConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +98,7 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
|||||||
*/
|
*/
|
||||||
public function summary() {
|
public function summary() {
|
||||||
// Use the domain labels. They will be sanitized below.
|
// Use the domain labels. They will be sanitized below.
|
||||||
$domains = array_intersect_key(\Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList(), $this->configuration['domains']);
|
$domains = array_intersect_key(\Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList(), $this->configuration['domains']);
|
||||||
if (count($domains) > 1) {
|
if (count($domains) > 1) {
|
||||||
$domains = implode(', ', $domains);
|
$domains = implode(', ', $domains);
|
||||||
}
|
}
|
||||||
@@ -106,10 +106,10 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
|||||||
$domains = reset($domains);
|
$domains = reset($domains);
|
||||||
}
|
}
|
||||||
if ($this->isNegated()) {
|
if ($this->isNegated()) {
|
||||||
return $this->t('Active domain is not @domains', array('@domains' => $domains));
|
return $this->t('Active domain is not @domains', ['@domains' => $domains]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $this->t('Active domain is @domains', array('@domains' => $domains));
|
return $this->t('Active domain is @domains', ['@domains' => $domains]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\domain\Plugin\EntityReferenceSelection;
|
namespace Drupal\domain\Plugin\EntityReferenceSelection;
|
||||||
|
|
||||||
use Drupal\domain\Plugin\EntityReferenceSelection\DomainSelection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides entity reference selections for the domain entity type.
|
* Provides entity reference selections for the domain entity type.
|
||||||
*
|
*
|
||||||
@@ -31,6 +29,6 @@ class DomainAdminSelection extends DomainSelection {
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $field_type = 'admin';
|
protected $fieldType = 'admin';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -24,7 +24,7 @@ class DomainSelection extends DefaultSelection {
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $field_type = 'editor';
|
protected $fieldType = 'editor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -47,7 +47,7 @@ class DomainSelection extends DefaultSelection {
|
|||||||
if (!empty($info->configuration['entity'])) {
|
if (!empty($info->configuration['entity'])) {
|
||||||
$context['entity_type'] = $info->configuration['entity']->getEntityTypeId();
|
$context['entity_type'] = $info->configuration['entity']->getEntityTypeId();
|
||||||
$context['bundle'] = $info->configuration['entity']->bundle();
|
$context['bundle'] = $info->configuration['entity']->bundle();
|
||||||
$context['field_type'] = $this->field_type;
|
$context['field_type'] = $this->fieldType;
|
||||||
|
|
||||||
// Load the current user.
|
// Load the current user.
|
||||||
$account = User::load($this->currentUser->id());
|
$account = User::load($this->currentUser->id());
|
||||||
@@ -65,48 +65,48 @@ class DomainSelection extends DefaultSelection {
|
|||||||
$selection_handler_settings = $this->configuration['handler_settings'];
|
$selection_handler_settings = $this->configuration['handler_settings'];
|
||||||
|
|
||||||
// Merge-in default values.
|
// Merge-in default values.
|
||||||
$selection_handler_settings += array(
|
$selection_handler_settings += [
|
||||||
// For the 'target_bundles' setting, a NULL value is equivalent to "allow
|
// For the 'target_bundles' setting, a NULL value is equivalent to "allow
|
||||||
// entities from any bundle to be referenced" and an empty array value is
|
// entities from any bundle to be referenced" and an empty array value is
|
||||||
// equivalent to "no entities from any bundle can be referenced".
|
// equivalent to "no entities from any bundle can be referenced".
|
||||||
'target_bundles' => NULL,
|
'target_bundles' => NULL,
|
||||||
'sort' => array(
|
'sort' => [
|
||||||
'field' => 'weight',
|
'field' => 'weight',
|
||||||
'direction' => 'ASC',
|
'direction' => 'ASC',
|
||||||
),
|
],
|
||||||
'auto_create' => FALSE,
|
'auto_create' => FALSE,
|
||||||
'default_selection' => 'current',
|
'default_selection' => 'current',
|
||||||
);
|
];
|
||||||
|
|
||||||
$form['target_bundles'] = array(
|
$form['target_bundles'] = [
|
||||||
'#type' => 'value',
|
'#type' => 'value',
|
||||||
'#value' => NULL,
|
'#value' => NULL,
|
||||||
);
|
];
|
||||||
|
|
||||||
$fields = array(
|
$fields = [
|
||||||
'weight' => $this->t('Weight'),
|
'weight' => $this->t('Weight'),
|
||||||
'label' => $this->t('Name'),
|
'label' => $this->t('Name'),
|
||||||
'hostname' => $this->t('Hostname'),
|
'hostname' => $this->t('Hostname'),
|
||||||
);
|
];
|
||||||
|
|
||||||
$form['sort']['field'] = array(
|
$form['sort']['field'] = [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#title' => $this->t('Sort by'),
|
'#title' => $this->t('Sort by'),
|
||||||
'#options' => $fields,
|
'#options' => $fields,
|
||||||
'#ajax' => FALSE,
|
'#ajax' => FALSE,
|
||||||
'#default_value' => $selection_handler_settings['sort']['field'],
|
'#default_value' => $selection_handler_settings['sort']['field'],
|
||||||
);
|
];
|
||||||
|
|
||||||
$form['sort']['direction'] = array(
|
$form['sort']['direction'] = [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#title' => $this->t('Sort direction'),
|
'#title' => $this->t('Sort direction'),
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
'#options' => array(
|
'#options' => [
|
||||||
'ASC' => $this->t('Ascending'),
|
'ASC' => $this->t('Ascending'),
|
||||||
'DESC' => $this->t('Descending'),
|
'DESC' => $this->t('Descending'),
|
||||||
),
|
],
|
||||||
'#default_value' => $selection_handler_settings['sort']['direction'],
|
'#default_value' => $selection_handler_settings['sort']['direction'],
|
||||||
);
|
];
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ class DomainRecord extends DrupalSqlBase {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getIds() {
|
public function getIds() {
|
||||||
return ['domain_id' => ['type' => 'int']];
|
return ['domain_id' => ['type' => 'integer']];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,12 @@ use Drupal\Core\Cache\Cache;
|
|||||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainNegotiator;
|
use Drupal\domain\DomainNegotiatorInterface;
|
||||||
use Drupal\domain\DomainStorageInterface;
|
use Drupal\domain\DomainStorageInterface;
|
||||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access plugin that provides domain-based access control.
|
* Access plugin that provides domain-based access control.
|
||||||
*
|
*
|
||||||
@@ -52,12 +51,12 @@ class Domain extends AccessPluginBase implements CacheableDependencyInterface {
|
|||||||
* The plugin_id for the plugin instance.
|
* The plugin_id for the plugin instance.
|
||||||
* @param mixed $plugin_definition
|
* @param mixed $plugin_definition
|
||||||
* The plugin implementation definition.
|
* The plugin implementation definition.
|
||||||
* @param DomainStorageInterface $domain_storage
|
* @param \Drupal\domain\DomainStorageInterface $domain_storage
|
||||||
* The domain storage loader.
|
* The domain storage loader.
|
||||||
* @param DomainNegotiator $domain_negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $domain_negotiator
|
||||||
* The domain negotiator.
|
* The domain negotiator.
|
||||||
*/
|
*/
|
||||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, DomainStorageInterface $domain_storage, DomainNegotiator $domain_negotiator) {
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, DomainStorageInterface $domain_storage, DomainNegotiatorInterface $domain_negotiator) {
|
||||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||||
$this->domainStorage = $domain_storage;
|
$this->domainStorage = $domain_storage;
|
||||||
$this->domainNegotiator = $domain_negotiator;
|
$this->domainNegotiator = $domain_negotiator;
|
||||||
@@ -117,7 +116,7 @@ class Domain extends AccessPluginBase implements CacheableDependencyInterface {
|
|||||||
*/
|
*/
|
||||||
protected function defineOptions() {
|
protected function defineOptions() {
|
||||||
$options = parent::defineOptions();
|
$options = parent::defineOptions();
|
||||||
$options['domain'] = array('default' => array());
|
$options['domain'] = ['default' => []];
|
||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
@@ -127,27 +126,27 @@ class Domain extends AccessPluginBase implements CacheableDependencyInterface {
|
|||||||
*/
|
*/
|
||||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||||
parent::buildOptionsForm($form, $form_state);
|
parent::buildOptionsForm($form, $form_state);
|
||||||
$form['domain'] = array(
|
$form['domain'] = [
|
||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
'#title' => $this->t('Domain'),
|
'#title' => $this->t('Domain'),
|
||||||
'#default_value' => $this->options['domain'],
|
'#default_value' => $this->options['domain'],
|
||||||
'#options' => $this->domainStorage->loadOptionsList(),
|
'#options' => $this->domainStorage->loadOptionsList(),
|
||||||
'#description' => $this->t('Only the checked domain(s) will be able to access this display.'),
|
'#description' => $this->t('Only the checked domain(s) will be able to access this display.'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
|
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
|
||||||
$domain = $form_state->getValue(array('access_options', 'domain'));
|
$domain = $form_state->getValue(['access_options', 'domain']);
|
||||||
$domain = array_filter($domain);
|
$domain = array_filter($domain);
|
||||||
|
|
||||||
if (!$domain) {
|
if (!$domain) {
|
||||||
$form_state->setError($form['domain'], $this->t('You must select at least one domain if type is "by domain"'));
|
$form_state->setError($form['domain'], $this->t('You must select at least one domain if type is "by domain"'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$form_state->setValue(array('access_options', 'domain'), $domain);
|
$form_state->setValue(['access_options', 'domain'], $domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,17 +25,19 @@ abstract class DomainTestBase extends WebTestBase {
|
|||||||
/**
|
/**
|
||||||
* Sets a base hostname for running tests.
|
* Sets a base hostname for running tests.
|
||||||
*
|
*
|
||||||
* When creating test domains, try to use $this->base_hostname or the
|
* When creating test domains, try to use $this->baseHostname or the
|
||||||
* domainCreateTestDomains() method.
|
* domainCreateTestDomains() method.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $base_hostname;
|
public $baseHostname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules to enable.
|
* Modules to enable.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'node');
|
public static $modules = ['domain', 'node'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -45,7 +47,7 @@ abstract class DomainTestBase extends WebTestBase {
|
|||||||
|
|
||||||
// Create Basic page and Article node types.
|
// Create Basic page and Article node types.
|
||||||
if ($this->profile != 'standard') {
|
if ($this->profile != 'standard') {
|
||||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the base hostname for domains.
|
// Set the base hostname for domains.
|
||||||
@@ -59,15 +61,16 @@ abstract class DomainTestBase extends WebTestBase {
|
|||||||
* The user account object to check.
|
* The user account object to check.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* TRUE if a given user account is logged in, or FALSE.
|
||||||
*/
|
*/
|
||||||
protected function drupalUserIsLoggedIn($account) {
|
protected function drupalUserIsLoggedIn(UserInterface $account) {
|
||||||
// @TODO: This is a temporary hack for the test login fails when setting $cookie_domain.
|
// @TODO: This is a temporary hack for the test login fails when setting $cookie_domain.
|
||||||
if (!isset($account->session_id)) {
|
if (!isset($account->session_id)) {
|
||||||
return (bool) $account->id();
|
return (bool) $account->id();
|
||||||
}
|
}
|
||||||
// The session ID is hashed before being stored in the database.
|
// The session ID is hashed before being stored in the database.
|
||||||
// @see \Drupal\Core\Session\SessionHandler::read()
|
// @see \Drupal\Core\Session\SessionHandler::read()
|
||||||
return (bool) db_query("SELECT sid FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => Crypt::hashBase64($account->session_id)))->fetchField();
|
return (bool) db_query("SELECT sid FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", [':sid' => Crypt::hashBase64($account->session_id)])->fetchField();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +95,7 @@ abstract class DomainTestBase extends WebTestBase {
|
|||||||
if (isset($this->sessionId)) {
|
if (isset($this->sessionId)) {
|
||||||
$account->session_id = $this->sessionId;
|
$account->session_id = $this->sessionId;
|
||||||
}
|
}
|
||||||
$pass = $this->assert($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', array('%name' => $account->getUsername())), 'User login');
|
$pass = $this->assert($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getUsername()]), 'User login');
|
||||||
if ($pass) {
|
if ($pass) {
|
||||||
$this->loggedInUser = $account;
|
$this->loggedInUser = $account;
|
||||||
$this->container->get('current_user')->setAccount($account);
|
$this->container->get('current_user')->setAccount($account);
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
langcode: en
|
||||||
|
status: true
|
||||||
|
dependencies: { }
|
||||||
|
id: drupal
|
||||||
|
domain_id: 4308242
|
||||||
|
hostname: drupal.org
|
||||||
|
name: 'Drupal.org Domain Test'
|
||||||
|
scheme: http
|
||||||
|
weight: 1
|
||||||
|
is_default: true
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
name: "Domain module config schema tests"
|
||||||
|
description: "Support module for domain config schema testing."
|
||||||
|
type: module
|
||||||
|
package: Testing
|
||||||
|
# version: VERSION
|
||||||
|
# core: 8.x
|
||||||
|
hidden: TRUE
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- domain
|
||||||
|
|
||||||
|
# Information added by Drupal.org packaging script on 2018-11-14
|
||||||
|
version: '8.x-1.0-alpha14+9-dev'
|
||||||
|
core: '8.x'
|
||||||
|
project: 'domain'
|
||||||
|
datestamp: 1542230887
|
||||||
+3
-3
@@ -9,8 +9,8 @@ hidden: TRUE
|
|||||||
dependencies:
|
dependencies:
|
||||||
- domain
|
- domain
|
||||||
|
|
||||||
# Information added by Drupal.org packaging script on 2018-03-08
|
# Information added by Drupal.org packaging script on 2018-11-14
|
||||||
version: '8.x-1.0-alpha13'
|
version: '8.x-1.0-alpha14+9-dev'
|
||||||
core: '8.x'
|
core: '8.x'
|
||||||
project: 'domain'
|
project: 'domain'
|
||||||
datestamp: 1520519900
|
datestamp: 1542230887
|
||||||
|
|||||||
+5
-5
@@ -35,22 +35,22 @@ function domain_test_domain_request_alter(DomainInterface &$domain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_domain_operations
|
* Implements hook_domain_operations().
|
||||||
*/
|
*/
|
||||||
function domain_test_domain_operations(DomainInterface $domain) {
|
function domain_test_domain_operations(DomainInterface $domain) {
|
||||||
$operations = [];
|
$operations = [];
|
||||||
// Add aliases to the list.
|
// Add aliases to the list.
|
||||||
$id = $domain->id();
|
$id = $domain->id();
|
||||||
$operations['domain_test'] = array(
|
$operations['domain_test'] = [
|
||||||
'title' => t('Test'),
|
'title' => t('Test'),
|
||||||
'url' => Url::fromRoute('entity.domain.edit_form', array('domain' => $id)),
|
'url' => Url::fromRoute('entity.domain.edit_form', ['domain' => $id]),
|
||||||
'weight' => 80,
|
'weight' => 80,
|
||||||
);
|
];
|
||||||
return $operations;
|
return $operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_domain_references_alter
|
* Implements hook_domain_references_alter().
|
||||||
*/
|
*/
|
||||||
function domain_test_domain_references_alter($query, $account, $context) {
|
function domain_test_domain_references_alter($query, $account, $context) {
|
||||||
if ($context['entity_type'] == 'node') {
|
if ($context['entity_type'] == 'node') {
|
||||||
|
|||||||
+17
-17
@@ -20,16 +20,22 @@ class DomainConditionTest extends DomainTestBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A test domain.
|
* A test domain.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainInterface
|
||||||
*/
|
*/
|
||||||
protected $test_domain;
|
protected $testDomain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test domain that never matches $test_domain.
|
* A test domain that never matches $test_domain.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainInterface
|
||||||
*/
|
*/
|
||||||
protected $not_domain;
|
protected $notDomain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of all testing domains.
|
* An array of all testing domains.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainInterface[]
|
||||||
*/
|
*/
|
||||||
protected $domains;
|
protected $domains;
|
||||||
|
|
||||||
@@ -46,9 +52,9 @@ class DomainConditionTest extends DomainTestBase {
|
|||||||
$this->domainCreateTestDomains(5);
|
$this->domainCreateTestDomains(5);
|
||||||
|
|
||||||
// Get two sample domains.
|
// Get two sample domains.
|
||||||
$this->domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$this->domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
$this->test_domain = array_shift($this->domains);
|
$this->testDomain = array_shift($this->domains);
|
||||||
$this->not_domain = array_shift($this->domains);
|
$this->notDomain = array_shift($this->domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,29 +63,23 @@ class DomainConditionTest extends DomainTestBase {
|
|||||||
public function testConditions() {
|
public function testConditions() {
|
||||||
// Grab the domain condition and configure it to check against one domain.
|
// Grab the domain condition and configure it to check against one domain.
|
||||||
$condition = $this->manager->createInstance('domain')
|
$condition = $this->manager->createInstance('domain')
|
||||||
->setConfig('domains', array($this->test_domain->id() => $this->test_domain->id()))
|
->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()])
|
||||||
->setContextValue('entity:domain', $this->not_domain);
|
->setContextValue('entity:domain', $this->notDomain);
|
||||||
$this->assertFalse($condition->execute(), 'Domain request condition fails on wrong domain.');
|
$this->assertFalse($condition->execute(), 'Domain request condition fails on wrong domain.');
|
||||||
|
|
||||||
// Grab the domain condition and configure it to check against a null set.
|
|
||||||
$condition = $this->manager->createInstance('domain')
|
|
||||||
->setConfig('domains', array($this->test_domain->id() => $this->test_domain->id()))
|
|
||||||
->setContextValue('entity:domain', NULL);
|
|
||||||
$this->assertFalse($condition->execute(), 'Domain request condition fails when no context present.');
|
|
||||||
|
|
||||||
// Grab the domain condition and configure it to check against itself.
|
// Grab the domain condition and configure it to check against itself.
|
||||||
$condition = $this->manager->createInstance('domain')
|
$condition = $this->manager->createInstance('domain')
|
||||||
->setConfig('domains', array($this->test_domain->id() => $this->test_domain->id()))
|
->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()])
|
||||||
->setContextValue('entity:domain', $this->test_domain);
|
->setContextValue('entity:domain', $this->testDomain);
|
||||||
$this->assertTrue($condition->execute(), 'Domain request condition succeeds on matching domain.');
|
$this->assertTrue($condition->execute(), 'Domain request condition succeeds on matching domain.');
|
||||||
|
|
||||||
// Check for the proper summary.
|
// Check for the proper summary.
|
||||||
// Summaries require an extra space due to negate handling in summary().
|
// Summaries require an extra space due to negate handling in summary().
|
||||||
$this->assertEqual($condition->summary(), 'Active domain is ' . $this->test_domain->label());
|
$this->assertEqual($condition->summary(), 'Active domain is ' . $this->testDomain->label());
|
||||||
|
|
||||||
// Check the negated summary.
|
// Check the negated summary.
|
||||||
$condition->setConfig('negate', TRUE);
|
$condition->setConfig('negate', TRUE);
|
||||||
$this->assertEqual($condition->summary(), 'Active domain is not ' . $this->test_domain->label());
|
$this->assertEqual($condition->summary(), 'Active domain is not ' . $this->testDomain->label());
|
||||||
|
|
||||||
// Check the negated condition.
|
// Check the negated condition.
|
||||||
$this->assertFalse($condition->execute(), 'Domain request condition fails when condition negated.');
|
$this->assertFalse($condition->execute(), 'Domain request condition fails when condition negated.');
|
||||||
|
|||||||
+4
-7
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain record actions.
|
* Tests the domain record actions.
|
||||||
*
|
*
|
||||||
@@ -15,7 +13,7 @@ class DomainActionsTest extends DomainTestBase {
|
|||||||
* Tests bulk actions through the domain overview page.
|
* Tests bulk actions through the domain overview page.
|
||||||
*/
|
*/
|
||||||
public function testDomainActions() {
|
public function testDomainActions() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array('administer domains', 'access administration pages'));
|
$this->admin_user = $this->drupalCreateUser(['administer domains', 'access administration pages']);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
$path = 'admin/config/domain';
|
$path = 'admin/config/domain';
|
||||||
@@ -28,7 +26,7 @@ class DomainActionsTest extends DomainTestBase {
|
|||||||
$this->assertResponse(200);
|
$this->assertResponse(200);
|
||||||
|
|
||||||
// Test the domains.
|
// Test the domains.
|
||||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$domains = $storage->loadMultiple();
|
$domains = $storage->loadMultiple();
|
||||||
$this->assertTrue(count($domains) == 4, 'Four domain records found.');
|
$this->assertTrue(count($domains) == 4, 'Four domain records found.');
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ class DomainActionsTest extends DomainTestBase {
|
|||||||
$this->assertText($name, 'Name found properly.');
|
$this->assertText($name, 'Name found properly.');
|
||||||
}
|
}
|
||||||
// Test the list of actions.
|
// Test the list of actions.
|
||||||
$actions = array('delete', 'disable', 'default');
|
$actions = ['delete', 'disable', 'default'];
|
||||||
foreach ($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$this->assertRaw("/domain/{$action}/", 'Actions found properly.');
|
$this->assertRaw("/domain/{$action}/", 'Actions found properly.');
|
||||||
}
|
}
|
||||||
@@ -68,7 +66,7 @@ class DomainActionsTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test the list of actions.
|
// Test the list of actions.
|
||||||
$actions = array('enable', 'delete', 'disable', 'default');
|
$actions = ['enable', 'delete', 'disable', 'default'];
|
||||||
foreach ($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$this->assertRaw("/domain/{$action}/", 'Actions found properly.');
|
$this->assertRaw("/domain/{$action}/", 'Actions found properly.');
|
||||||
}
|
}
|
||||||
@@ -100,4 +98,3 @@ class DomainActionsTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior for the domain admin field element.
|
* Tests behavior for the domain admin field element.
|
||||||
*
|
*
|
||||||
@@ -16,7 +14,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'field', 'field_ui', 'user');
|
public static $modules = ['domain', 'field', 'field_ui', 'user'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -32,12 +30,12 @@ class DomainAdminElementTest extends DomainTestBase {
|
|||||||
* Basic test setup.
|
* Basic test setup.
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessElement() {
|
public function testDomainAccessElement() {
|
||||||
$admin = $this->drupalCreateUser(array(
|
$admin = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer users',
|
'administer users',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($admin);
|
$this->drupalLogin($admin);
|
||||||
|
|
||||||
$this->drupalGet('admin/people/create');
|
$this->drupalGet('admin/people/create');
|
||||||
@@ -50,7 +48,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
|||||||
$this->fillField('pass[pass2]', 'test');
|
$this->fillField('pass[pass2]', 'test');
|
||||||
|
|
||||||
// We expect to find 5 domain options. We set two as selected.
|
// We expect to find 5 domain options. We set two as selected.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
@@ -73,16 +71,16 @@ class DomainAdminElementTest extends DomainTestBase {
|
|||||||
$this->assert(count($values) == 3, 'User saved with three domain records.');
|
$this->assert(count($values) == 3, 'User saved with three domain records.');
|
||||||
|
|
||||||
// Now login as a user with limited rights.
|
// Now login as a user with limited rights.
|
||||||
$account = $this->drupalCreateUser(array(
|
$account = $this->drupalCreateUser([
|
||||||
'administer users',
|
'administer users',
|
||||||
'assign domain administrators',
|
'assign domain administrators',
|
||||||
));
|
]);
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||||
$tester = $storage->load($account->id());
|
$tester = $storage->load($account->id());
|
||||||
$values = $manager->getFieldValues($tester, DOMAIN_ADMIN_FIELD);
|
$values = $manager->getFieldValues($tester, DOMAIN_ADMIN_FIELD);
|
||||||
$this->assert(count($values) == 2, 'User saved with two domain records.');
|
$this->assert(count($values) == 2, 'User saved with two domain records.');
|
||||||
$storage->resetCache(array($account->id()));
|
$storage->resetCache([$account->id()]);
|
||||||
$this->drupalLogin($account);
|
$this->drupalLogin($account);
|
||||||
|
|
||||||
$this->drupalGet('user/' . $user->id() . '/edit');
|
$this->drupalGet('user/' . $user->id() . '/edit');
|
||||||
@@ -107,7 +105,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
|||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Now, check the user.
|
// Now, check the user.
|
||||||
$storage->resetCache(array($user->id()));
|
$storage->resetCache([$user->id()]);
|
||||||
$user = $storage->load($user->id());
|
$user = $storage->load($user->id());
|
||||||
// Check that two values are set.
|
// Check that two values are set.
|
||||||
$values = $manager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
$values = $manager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
||||||
|
|||||||
+8
-6
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Component\Utility\Html;
|
use Drupal\Component\Utility\Html;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain CSS configuration.
|
* Tests the domain CSS configuration.
|
||||||
@@ -17,11 +16,14 @@ class DomainCSSTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain');
|
public static $modules = ['domain'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
\Drupal::service('theme_handler')->install(array('bartik'));
|
\Drupal::service('theme_handler')->install(['bartik']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +42,7 @@ class DomainCSSTest extends DomainTestBase {
|
|||||||
$config->set('default', 'bartik')->save();
|
$config->set('default', 'bartik')->save();
|
||||||
|
|
||||||
// Test the response of the default home page.
|
// Test the response of the default home page.
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||||
$this->drupalGet($domain->getPath());
|
$this->drupalGet($domain->getPath());
|
||||||
$text = '<body class="' . Html::getClass($domain->id() . '-class');
|
$text = '<body class="' . Html::getClass($domain->id() . '-class');
|
||||||
$this->assertNoRaw($text, 'No custom CSS present.');
|
$this->assertNoRaw($text, 'No custom CSS present.');
|
||||||
@@ -50,7 +52,7 @@ class DomainCSSTest extends DomainTestBase {
|
|||||||
$config->set('css_classes', '[domain:machine-name]-class')->save();
|
$config->set('css_classes', '[domain:machine-name]-class')->save();
|
||||||
|
|
||||||
// Test the response of the default home page.
|
// Test the response of the default home page.
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||||
// The render cache trips up this test. In production, it may be
|
// The render cache trips up this test. In production, it may be
|
||||||
// necessary to add the url.site cache context. See README.md.
|
// necessary to add the url.site cache context. See README.md.
|
||||||
drupal_flush_all_caches();
|
drupal_flush_all_caches();
|
||||||
@@ -63,7 +65,7 @@ class DomainCSSTest extends DomainTestBase {
|
|||||||
$config = $this->config('domain.settings');
|
$config = $this->config('domain.settings');
|
||||||
$config->set('css_classes', '[domain:machine-name]-class [domain:name]-class')->save();
|
$config->set('css_classes', '[domain:machine-name]-class [domain:name]-class')->save();
|
||||||
// Test the response of the default home page.
|
// Test the response of the default home page.
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||||
// The render cache trips up this test. In production, it may be
|
// The render cache trips up this test. In production, it may be
|
||||||
// necessary to add the url.site cache context. See README.md.
|
// necessary to add the url.site cache context. See README.md.
|
||||||
drupal_flush_all_caches();
|
drupal_flush_all_caches();
|
||||||
|
|||||||
+3
-5
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain record response check.
|
* Tests the domain record response check.
|
||||||
*
|
*
|
||||||
@@ -15,10 +13,10 @@ class DomainCheckResponseTest extends DomainTestBase {
|
|||||||
* Tests that a domain responds as expected.
|
* Tests that a domain responds as expected.
|
||||||
*/
|
*/
|
||||||
public function testDomainCheckResponse() {
|
public function testDomainCheckResponse() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array('administer domains', 'create domains'));
|
$this->admin_user = $this->drupalCreateUser(['administer domains', 'create domains']);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
|
|
||||||
// Make a POST request on admin/config/domain/add.
|
// Make a POST request on admin/config/domain/add.
|
||||||
$edit = $this->domainPostValues();
|
$edit = $this->domainPostValues();
|
||||||
@@ -38,7 +36,7 @@ class DomainCheckResponseTest extends DomainTestBase {
|
|||||||
try {
|
try {
|
||||||
$this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
|
$this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (\Exception $e) {
|
||||||
// Ensure no test errors.
|
// Ensure no test errors.
|
||||||
}
|
}
|
||||||
// The domain should not save.
|
// The domain should not save.
|
||||||
|
|||||||
+11
-4
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain record creation API.
|
* Tests the domain record creation API.
|
||||||
*
|
*
|
||||||
@@ -19,10 +17,19 @@ class DomainCreateTest extends DomainTestBase {
|
|||||||
$this->domainTableIsEmpty();
|
$this->domainTableIsEmpty();
|
||||||
|
|
||||||
// Create a new domain programmatically.
|
// Create a new domain programmatically.
|
||||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$domain = $storage->create();
|
$domain = $storage->create();
|
||||||
$domain->set('id', $storage->createMachineName($domain->getHostname()));
|
$domain->set('id', $storage->createMachineName($domain->getHostname()));
|
||||||
foreach (array('id', 'name', 'hostname', 'scheme', 'status', 'weight' , 'is_default') as $key) {
|
$keys = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'hostname',
|
||||||
|
'scheme',
|
||||||
|
'status',
|
||||||
|
'weight',
|
||||||
|
'is_default',
|
||||||
|
];
|
||||||
|
foreach ($keys as $key) {
|
||||||
$property = $domain->get($key);
|
$property = $domain->get($key);
|
||||||
$this->assertTrue(isset($property), 'Property loaded');
|
$this->assertTrue(isset($property), 'Property loaded');
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-19
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain record entity reference field type.
|
* Tests the domain record entity reference field type.
|
||||||
*
|
*
|
||||||
@@ -16,18 +14,18 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'field', 'field_ui');
|
public static $modules = ['domain', 'field', 'field_ui'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create, edit and delete a domain field via the user interface.
|
* Create, edit and delete a domain field via the user interface.
|
||||||
*/
|
*/
|
||||||
public function testDomainField() {
|
public function testDomainField() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Visit the article field administration page.
|
// Visit the article field administration page.
|
||||||
@@ -64,13 +62,13 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
|||||||
* Create content for a domain field.
|
* Create content for a domain field.
|
||||||
*/
|
*/
|
||||||
public function testDomainFieldStorage() {
|
public function testDomainFieldStorage() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Create test domain field.
|
// Create test domain field.
|
||||||
@@ -87,7 +85,7 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
|||||||
$this->assertText('Domain test field', 'Found the domain field instance.');
|
$this->assertText('Domain test field', 'Found the domain field instance.');
|
||||||
|
|
||||||
// We expect to find 5 domain options.
|
// We expect to find 5 domain options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$string = 'value="' . $domain->id() . '"';
|
$string = 'value="' . $domain->id() . '"';
|
||||||
$this->assertRaw($string, 'Found the domain option');
|
$this->assertRaw($string, 'Found the domain option');
|
||||||
@@ -123,29 +121,29 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
|||||||
$label = 'domain';
|
$label = 'domain';
|
||||||
$name = 'field_' . $label;
|
$name = 'field_' . $label;
|
||||||
|
|
||||||
$storage = array(
|
$storage = [
|
||||||
'field_name' => $name,
|
'field_name' => $name,
|
||||||
'entity_type' => 'node',
|
'entity_type' => 'node',
|
||||||
'type' => 'entity_reference',
|
'type' => 'entity_reference',
|
||||||
'cardinality' => -1,
|
'cardinality' => -1,
|
||||||
'settings' => array(
|
'settings' => [
|
||||||
'target_type' => 'domain',
|
'target_type' => 'domain',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$field_storage_config = \Drupal::entityTypeManager()->getStorage('field_storage_config')->create($storage);
|
$field_storage_config = \Drupal::entityTypeManager()->getStorage('field_storage_config')->create($storage);
|
||||||
$field_storage_config->save();
|
$field_storage_config->save();
|
||||||
|
|
||||||
$field = array(
|
$field = [
|
||||||
'field_name' => $name,
|
'field_name' => $name,
|
||||||
'entity_type' => 'node',
|
'entity_type' => 'node',
|
||||||
'label' => 'Domain test field',
|
'label' => 'Domain test field',
|
||||||
'bundle' => 'article',
|
'bundle' => 'article',
|
||||||
'settings' => array(
|
'settings' => [
|
||||||
'handler_settings' => array(
|
'handler_settings' => [
|
||||||
'sort' => array('field' => 'weight', 'direction' => 'ASC'),
|
'sort' => ['field' => 'weight', 'direction' => 'ASC'],
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$field_config = \Drupal::entityTypeManager()->getStorage('field_config')->create($field);
|
$field_config = \Drupal::entityTypeManager()->getStorage('field_config')->create($field);
|
||||||
$field_config->save();
|
$field_config->save();
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain record form interface.
|
* Tests the domain record form interface.
|
||||||
*
|
*
|
||||||
@@ -15,10 +13,10 @@ class DomainFormsTest extends DomainTestBase {
|
|||||||
* Create, edit and delete a domain via the user interface.
|
* Create, edit and delete a domain via the user interface.
|
||||||
*/
|
*/
|
||||||
public function testDomainInterface() {
|
public function testDomainInterface() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array('administer domains', 'create domains'));
|
$this->admin_user = $this->drupalCreateUser(['administer domains', 'create domains']);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
|
|
||||||
// No domains should exist.
|
// No domains should exist.
|
||||||
$this->domainTableIsEmpty();
|
$this->domainTableIsEmpty();
|
||||||
@@ -27,7 +25,12 @@ class DomainFormsTest extends DomainTestBase {
|
|||||||
$this->drupalGet('admin/config/domain');
|
$this->drupalGet('admin/config/domain');
|
||||||
|
|
||||||
// Check for the add message.
|
// Check for the add message.
|
||||||
|
if (substr_count(\Drupal::VERSION, '8.5') > 0) {
|
||||||
$this->assertText('There is no Domain record yet.', 'Text for no domains found.');
|
$this->assertText('There is no Domain record yet.', 'Text for no domains found.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->assertText('There are no domain record entities yet.', 'Text for no domains found.');
|
||||||
|
}
|
||||||
// Visit the add domain administration page.
|
// Visit the add domain administration page.
|
||||||
$this->drupalGet('admin/config/domain/add');
|
$this->drupalGet('admin/config/domain/add');
|
||||||
|
|
||||||
@@ -67,7 +70,7 @@ class DomainFormsTest extends DomainTestBase {
|
|||||||
$this->drupalGet($deleteUrl);
|
$this->drupalGet($deleteUrl);
|
||||||
|
|
||||||
// Delete the record.
|
// Delete the record.
|
||||||
$this->drupalPostForm($deleteUrl, array(), 'Delete');
|
$this->drupalPostForm($deleteUrl, [], 'Delete');
|
||||||
$storage->resetCache([$default_id]);
|
$storage->resetCache([$default_id]);
|
||||||
$domain = $storage->load($default_id);
|
$domain = $storage->load($default_id);
|
||||||
$this->assertTrue(empty($domain), 'Domain record deleted.');
|
$this->assertTrue(empty($domain), 'Domain record deleted.');
|
||||||
|
|||||||
+7
-9
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests domain record HTTP response.
|
* Tests domain record HTTP response.
|
||||||
*
|
*
|
||||||
@@ -21,24 +19,24 @@ class DomainGetResponseTest extends DomainTestBase {
|
|||||||
// Create a new domain programmatically.
|
// Create a new domain programmatically.
|
||||||
$this->domainCreateTestDomains();
|
$this->domainCreateTestDomains();
|
||||||
|
|
||||||
// Check the created domain based on it's known id value.
|
// Check the created domain based on its known id value.
|
||||||
$key = 'example_com';
|
$key = 'example_com';
|
||||||
/** @var \Drupal\domain\Entity\Domain $domain */
|
/** @var \Drupal\domain\Entity\Domain $domain */
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->load($key);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->load($key);
|
||||||
|
|
||||||
// Our testing server should be able to access the test PNG file.
|
// Our testing server should be able to access the test PNG file.
|
||||||
$this->assertTrue($domain->getResponse() == 200, 'Server returned a 200 response.');
|
$this->assert($domain->getResponse() == 200, 'Server returned a 200 response.');
|
||||||
|
|
||||||
// Now create a bad domain.
|
// Now create a bad domain.
|
||||||
$values = array(
|
$values = [
|
||||||
'hostname' => 'foo.bar',
|
'hostname' => 'foo.bar',
|
||||||
'id' => 'foo_bar',
|
'id' => 'foo_bar',
|
||||||
'name' => 'Foo',
|
'name' => 'Foo',
|
||||||
);
|
];
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create($values);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||||
|
|
||||||
$domain->save();
|
$domain->save();
|
||||||
$this->assertTrue($domain->getResponse() == 500, 'Server test returned a 500 response.');
|
$this->assert($domain->getResponse() == 500, 'Server test returned a 500 response.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -4,7 +4,6 @@ namespace Drupal\Tests\domain\Functional;
|
|||||||
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\user\RoleInterface;
|
use Drupal\user\RoleInterface;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the access rules and redirects for inactive domains.
|
* Tests the access rules and redirects for inactive domains.
|
||||||
@@ -18,7 +17,7 @@ class DomainInactiveTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'node', 'views');
|
public static $modules = ['domain', 'node', 'views'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test inactive domain.
|
* Test inactive domain.
|
||||||
@@ -30,7 +29,7 @@ class DomainInactiveTest extends DomainTestBase {
|
|||||||
|
|
||||||
// Create four new domains programmatically.
|
// Create four new domains programmatically.
|
||||||
$this->domainCreateTestDomains(4);
|
$this->domainCreateTestDomains(4);
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
|
|
||||||
// Grab a known domain for testing.
|
// Grab a known domain for testing.
|
||||||
$domain = $domains['two_example_com'];
|
$domain = $domains['two_example_com'];
|
||||||
@@ -40,7 +39,7 @@ class DomainInactiveTest extends DomainTestBase {
|
|||||||
|
|
||||||
// Disable the domain and test for redirect.
|
// Disable the domain and test for redirect.
|
||||||
$domain->disable();
|
$domain->disable();
|
||||||
$default = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain();
|
$default = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain();
|
||||||
// Our postSave() cache tag clear should allow this to work properly.
|
// Our postSave() cache tag clear should allow this to work properly.
|
||||||
$this->drupalGet($domain->getPath());
|
$this->drupalGet($domain->getPath());
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ class DomainInactiveTest extends DomainTestBase {
|
|||||||
$this->assertResponse(200, 'Request to reset password on inactive domain allowed.');
|
$this->assertResponse(200, 'Request to reset password on inactive domain allowed.');
|
||||||
|
|
||||||
// Try to access with the proper permission.
|
// Try to access with the proper permission.
|
||||||
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('access inactive domains'));
|
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access inactive domains']);
|
||||||
// Must flush cache because we did not resave the domain.
|
// Must flush cache because we did not resave the domain.
|
||||||
drupal_flush_all_caches();
|
drupal_flush_all_caches();
|
||||||
$this->assertFalse($domain->status(), 'Tested domain is set to inactive.');
|
$this->assertFalse($domain->status(), 'Tested domain is set to inactive.');
|
||||||
@@ -70,13 +69,14 @@ class DomainInactiveTest extends DomainTestBase {
|
|||||||
// Check against trusted host patterns.
|
// Check against trusted host patterns.
|
||||||
$settings['settings']['trusted_host_patterns'] = (object) [
|
$settings['settings']['trusted_host_patterns'] = (object) [
|
||||||
'value' => ['^' . $this->prepareTrustedHostname($domain->getHostname()) . '$',
|
'value' => ['^' . $this->prepareTrustedHostname($domain->getHostname()) . '$',
|
||||||
'^' . $this->prepareTrustedHostname($domain2->getHostname()) . '$'],
|
'^' . $this->prepareTrustedHostname($domain2->getHostname()) . '$',
|
||||||
|
],
|
||||||
'required' => TRUE,
|
'required' => TRUE,
|
||||||
];
|
];
|
||||||
$this->writeSettings($settings);
|
$this->writeSettings($settings);
|
||||||
|
|
||||||
// Revoke the permission change.
|
// Revoke the permission change.
|
||||||
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access inactive domains'));
|
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access inactive domains']);
|
||||||
|
|
||||||
$domain2->saveDefault();
|
$domain2->saveDefault();
|
||||||
|
|
||||||
|
|||||||
+7
-9
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior for the domain list builder.
|
* Tests behavior for the domain list builder.
|
||||||
*
|
*
|
||||||
@@ -16,7 +14,7 @@ class DomainListBuilderTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'user');
|
public static $modules = ['domain', 'user'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -32,13 +30,13 @@ class DomainListBuilderTest extends DomainTestBase {
|
|||||||
* Basic test setup.
|
* Basic test setup.
|
||||||
*/
|
*/
|
||||||
public function testDomainListBuilder() {
|
public function testDomainListBuilder() {
|
||||||
$admin = $this->drupalCreateUser(array(
|
$admin = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($admin);
|
$this->drupalLogin($admin);
|
||||||
|
|
||||||
$this->drupalGet('admin/config/domain');
|
$this->drupalGet('admin/config/domain');
|
||||||
@@ -64,12 +62,12 @@ class DomainListBuilderTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now login as a user with limited rights.
|
// Now login as a user with limited rights.
|
||||||
$account = $this->drupalCreateUser(array(
|
$account = $this->drupalCreateUser([
|
||||||
'create article content',
|
'create article content',
|
||||||
'edit any article content',
|
'edit any article content',
|
||||||
'edit assigned domains',
|
'edit assigned domains',
|
||||||
'view domain list',
|
'view domain list',
|
||||||
));
|
]);
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||||
@@ -130,12 +128,12 @@ class DomainListBuilderTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now login as a user with more limited rights.
|
// Now login as a user with more limited rights.
|
||||||
$account2 = $this->drupalCreateUser(array(
|
$account2 = $this->drupalCreateUser([
|
||||||
'create article content',
|
'create article content',
|
||||||
'edit any article content',
|
'edit any article content',
|
||||||
'edit assigned domains',
|
'edit assigned domains',
|
||||||
'view assigned domains',
|
'view assigned domains',
|
||||||
));
|
]);
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$this->addDomainsToEntity('user', $account2->id(), $ids, DOMAIN_ADMIN_FIELD);
|
$this->addDomainsToEntity('user', $account2->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||||
|
|||||||
+4
-5
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior for the weight element of the domain list builder.
|
* Tests behavior for the weight element of the domain list builder.
|
||||||
*
|
*
|
||||||
@@ -16,7 +14,7 @@ class DomainListWeightTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'user');
|
public static $modules = ['domain', 'user'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -43,13 +41,13 @@ class DomainListWeightTest extends DomainTestBase {
|
|||||||
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59');
|
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59');
|
||||||
$domains_old = $domains;
|
$domains_old = $domains;
|
||||||
|
|
||||||
$admin = $this->drupalCreateUser(array(
|
$admin = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($admin);
|
$this->drupalLogin($admin);
|
||||||
|
|
||||||
$this->drupalGet('admin/config/domain');
|
$this->drupalGet('admin/config/domain');
|
||||||
@@ -107,4 +105,5 @@ class DomainListWeightTest extends DomainTestBase {
|
|||||||
// The last domain should be test59_example_com.
|
// The last domain should be test59_example_com.
|
||||||
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59' . $domain->id());
|
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59' . $domain->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain navigation block.
|
* Tests the domain navigation block.
|
||||||
@@ -17,7 +16,7 @@ class DomainNavBlockTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'node', 'block');
|
public static $modules = ['domain', 'node', 'block'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test domain navigation block.
|
* Test domain navigation block.
|
||||||
@@ -25,13 +24,13 @@ class DomainNavBlockTest extends DomainTestBase {
|
|||||||
public function testDomainNav() {
|
public function testDomainNav() {
|
||||||
// Create four new domains programmatically.
|
// Create four new domains programmatically.
|
||||||
$this->domainCreateTestDomains(4);
|
$this->domainCreateTestDomains(4);
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
|
|
||||||
// Place the nav block.
|
// Place the nav block.
|
||||||
$block = $this->drupalPlaceBlock('domain_nav_block');
|
$block = $this->drupalPlaceBlock('domain_nav_block');
|
||||||
|
|
||||||
// Let the anon user view the block.
|
// Let the anon user view the block.
|
||||||
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('use domain nav block'));
|
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['use domain nav block']);
|
||||||
|
|
||||||
// Load the homepage. All links should appear.
|
// Load the homepage. All links should appear.
|
||||||
$this->drupalGet('<front>');
|
$this->drupalGet('<front>');
|
||||||
@@ -56,7 +55,7 @@ class DomainNavBlockTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Let the anon user view diabled domains. All links should appear.
|
// Let the anon user view diabled domains. All links should appear.
|
||||||
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('access inactive domains'));
|
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access inactive domains']);
|
||||||
|
|
||||||
// Load the homepage.
|
// Load the homepage.
|
||||||
$this->drupalGet('<front>');
|
$this->drupalGet('<front>');
|
||||||
@@ -94,4 +93,5 @@ class DomainNavBlockTest extends DomainTestBase {
|
|||||||
$this->assertRaw($domain->getPath());
|
$this->assertRaw($domain->getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain negotiation manager.
|
* Tests the domain negotiation manager.
|
||||||
@@ -17,7 +16,7 @@ class DomainNegotiatorTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_test', 'block');
|
public static $modules = ['domain', 'domain_test', 'block'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the handling of an inbound request.
|
* Tests the handling of an inbound request.
|
||||||
@@ -34,10 +33,10 @@ class DomainNegotiatorTest extends DomainTestBase {
|
|||||||
$this->drupalPlaceBlock('domain_server_block');
|
$this->drupalPlaceBlock('domain_server_block');
|
||||||
|
|
||||||
// To get around block access, let the anon user view the block.
|
// To get around block access, let the anon user view the block.
|
||||||
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('view domain information'));
|
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['view domain information']);
|
||||||
|
|
||||||
// Test the response of the default home page.
|
// Test the response of the default home page.
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||||
$this->drupalGet($domain->getPath());
|
$this->drupalGet($domain->getPath());
|
||||||
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-15
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior for hook_domain_references_alter().
|
* Tests behavior for hook_domain_references_alter().
|
||||||
*
|
*
|
||||||
* The module suite ships with two field types -- admin and editor. We want to ensure
|
* The module suite ships with two field types -- admin and editor. We want to
|
||||||
* that these are filtered properly by hook_domain_references_alter().
|
* ensure that these are filtered properly by hook_domain_references_alter().
|
||||||
*
|
*
|
||||||
* @group domain
|
* @group domain
|
||||||
*/
|
*/
|
||||||
@@ -19,7 +17,13 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
public static $modules = [
|
||||||
|
'domain',
|
||||||
|
'domain_access',
|
||||||
|
'field',
|
||||||
|
'field_ui',
|
||||||
|
'user',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -36,13 +40,13 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
*/
|
*/
|
||||||
public function testDomainReferences() {
|
public function testDomainReferences() {
|
||||||
// Create an admin user. This will be user 2.
|
// Create an admin user. This will be user 2.
|
||||||
$admin = $this->drupalCreateUser(array(
|
$admin = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer users',
|
'administer users',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
'assign domain editors',
|
'assign domain editors',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($admin);
|
$this->drupalLogin($admin);
|
||||||
|
|
||||||
$this->drupalGet('admin/people/create');
|
$this->drupalGet('admin/people/create');
|
||||||
@@ -55,7 +59,7 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->fillField('pass[pass2]', 'test');
|
$this->fillField('pass[pass2]', 'test');
|
||||||
|
|
||||||
// We expect to find 5 domain options. We set three as selected.
|
// We expect to find 5 domain options. We set three as selected.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
|
|
||||||
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
||||||
$edit_ids = ['example_com', 'one_example_com'];
|
$edit_ids = ['example_com', 'one_example_com'];
|
||||||
@@ -92,10 +96,10 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
||||||
|
|
||||||
// Now login as a user with limited rights. This is user 4.
|
// Now login as a user with limited rights. This is user 4.
|
||||||
$account = $this->drupalCreateUser(array(
|
$account = $this->drupalCreateUser([
|
||||||
'administer users',
|
'administer users',
|
||||||
'assign domain administrators',
|
'assign domain administrators',
|
||||||
));
|
]);
|
||||||
// Set some domain assignments for this user.
|
// Set some domain assignments for this user.
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||||
@@ -137,7 +141,7 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Now, check the user.
|
// Now, check the user.
|
||||||
$storage->resetCache(array($testuser->id()));
|
$storage->resetCache([$testuser->id()]);
|
||||||
$testuser = $storage->load($testuser->id());
|
$testuser = $storage->load($testuser->id());
|
||||||
// Check that two values are set.
|
// Check that two values are set.
|
||||||
$values = $manager->getFieldValues($testuser, DOMAIN_ADMIN_FIELD);
|
$values = $manager->getFieldValues($testuser, DOMAIN_ADMIN_FIELD);
|
||||||
@@ -147,11 +151,11 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
||||||
|
|
||||||
// Now login as a user with different limited rights. This is user 5.
|
// Now login as a user with different limited rights. This is user 5.
|
||||||
$new_account = $this->drupalCreateUser(array(
|
$new_account = $this->drupalCreateUser([
|
||||||
'administer users',
|
'administer users',
|
||||||
'assign domain administrators',
|
'assign domain administrators',
|
||||||
'assign domain editors',
|
'assign domain editors',
|
||||||
));
|
]);
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$new_ids = ['one_example_com', 'four_example_com'];
|
$new_ids = ['one_example_com', 'four_example_com'];
|
||||||
$this->addDomainsToEntity('user', $new_account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
$this->addDomainsToEntity('user', $new_account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||||
@@ -164,7 +168,7 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
$this->assert(count($values) == 2, 'User saved with two domain access records.');
|
||||||
|
|
||||||
// Now edit the user as someone with limited rights.
|
// Now edit the user as someone with limited rights.
|
||||||
$storage->resetCache(array($new_admin->id()));
|
$storage->resetCache([$new_admin->id()]);
|
||||||
$this->drupalLogin($new_account);
|
$this->drupalLogin($new_account);
|
||||||
|
|
||||||
$this->drupalGet('user/' . $testuser->id() . '/edit');
|
$this->drupalGet('user/' . $testuser->id() . '/edit');
|
||||||
@@ -203,7 +207,7 @@ class DomainReferencesTest extends DomainTestBase {
|
|||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Now, check the user.
|
// Now, check the user.
|
||||||
$storage->resetCache(array($testuser->id()));
|
$storage->resetCache([$testuser->id()]);
|
||||||
$testuser = $storage->load($testuser->id());
|
$testuser = $storage->load($testuser->id());
|
||||||
// Check that two values are set.
|
// Check that two values are set.
|
||||||
$values = $manager->getFieldValues($testuser, DOMAIN_ADMIN_FIELD);
|
$values = $manager->getFieldValues($testuser, DOMAIN_ADMIN_FIELD);
|
||||||
|
|||||||
+32
-18
@@ -8,6 +8,11 @@ use Drupal\Tests\BrowserTestBase;
|
|||||||
use Drupal\domain\DomainInterface;
|
use Drupal\domain\DomainInterface;
|
||||||
use Drupal\Tests\domain\Traits\DomainTestTrait;
|
use Drupal\Tests\domain\Traits\DomainTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DomainTestBase.
|
||||||
|
*
|
||||||
|
* @package Drupal\Tests\domain\Functional
|
||||||
|
*/
|
||||||
abstract class DomainTestBase extends BrowserTestBase {
|
abstract class DomainTestBase extends BrowserTestBase {
|
||||||
|
|
||||||
use DomainTestTrait;
|
use DomainTestTrait;
|
||||||
@@ -15,17 +20,19 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
/**
|
/**
|
||||||
* Sets a base hostname for running tests.
|
* Sets a base hostname for running tests.
|
||||||
*
|
*
|
||||||
* When creating test domains, try to use $this->base_hostname or the
|
* When creating test domains, try to use $this->baseHostname or the
|
||||||
* domainCreateTestDomains() method.
|
* domainCreateTestDomains() method.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $base_hostname;
|
public $baseHostname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules to enable.
|
* Modules to enable.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'node');
|
public static $modules = ['domain', 'node'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use the standard profile for testing.
|
* We use the standard profile for testing.
|
||||||
@@ -41,12 +48,13 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// Set the base hostname for domains.
|
// Set the base hostname for domains.
|
||||||
$this->base_hostname = \Drupal::service('entity_type.manager')->getStorage('domain')->createHostname();
|
$this->baseHostname = \Drupal::entityTypeManager()->getStorage('domain')->createHostname();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods below are brazenly copied from Rules module. They are all
|
* The methods below are brazenly copied from Rules module.
|
||||||
* helper methods that make writing tests a bit easier.
|
*
|
||||||
|
* They are all helper methods that make writing tests a bit easier.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,8 +76,8 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
* @param string $locator
|
* @param string $locator
|
||||||
* Link id, title, text or image alt.
|
* Link id, title, text or image alt.
|
||||||
*
|
*
|
||||||
* @return \Behat\Mink\Element\NodeElement|null
|
* @return bool
|
||||||
* The link node element.
|
* TRUE if link is absent, or FALSE.
|
||||||
*/
|
*/
|
||||||
public function findNoLink($locator) {
|
public function findNoLink($locator) {
|
||||||
return empty($this->getSession()->getPage()->hasLink($locator));
|
return empty($this->getSession()->getPage()->hasLink($locator));
|
||||||
@@ -132,9 +140,10 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
/**
|
/**
|
||||||
* Checks checkbox with specified locator.
|
* Checks checkbox with specified locator.
|
||||||
*
|
*
|
||||||
* @param string $locator input id, name or label
|
* @param string $locator
|
||||||
|
* An input id, name or label.
|
||||||
*
|
*
|
||||||
* @throws ElementNotFoundException
|
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
public function checkField($locator) {
|
public function checkField($locator) {
|
||||||
$this->getSession()->getPage()->checkField($locator);
|
$this->getSession()->getPage()->checkField($locator);
|
||||||
@@ -143,9 +152,10 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
/**
|
/**
|
||||||
* Unchecks checkbox with specified locator.
|
* Unchecks checkbox with specified locator.
|
||||||
*
|
*
|
||||||
* @param string $locator input id, name or label
|
* @param string $locator
|
||||||
|
* An input id, name or label.
|
||||||
*
|
*
|
||||||
* @throws ElementNotFoundException
|
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
public function uncheckField($locator) {
|
public function uncheckField($locator) {
|
||||||
$this->getSession()->getPage()->uncheckField($locator);
|
$this->getSession()->getPage()->uncheckField($locator);
|
||||||
@@ -154,15 +164,18 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
/**
|
/**
|
||||||
* Selects option from select field with specified locator.
|
* Selects option from select field with specified locator.
|
||||||
*
|
*
|
||||||
* @param string $locator input id, name or label
|
* @param string $locator
|
||||||
* @param string $value option value
|
* An input id, name or label.
|
||||||
* @param Boolean $multiple select multiple options
|
* @param string $value
|
||||||
|
* The option value.
|
||||||
|
* @param bool $multiple
|
||||||
|
* Whether to select multiple options.
|
||||||
*
|
*
|
||||||
* @throws ElementNotFoundException
|
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||||
*
|
*
|
||||||
* @see NodeElement::selectOption
|
* @see NodeElement::selectOption
|
||||||
*/
|
*/
|
||||||
public function selectFieldOption($locator, $value, $multiple = false) {
|
public function selectFieldOption($locator, $value, $multiple = FALSE) {
|
||||||
$this->getSession()->getPage()->selectFieldOption($locator, $value, $multiple);
|
$this->getSession()->getPage()->selectFieldOption($locator, $value, $multiple);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +186,7 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
* The user account object to check.
|
* The user account object to check.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* TRUE if a given user account is logged in, or FALSE.
|
||||||
*/
|
*/
|
||||||
protected function drupalUserIsLoggedIn(AccountInterface $account) {
|
protected function drupalUserIsLoggedIn(AccountInterface $account) {
|
||||||
// @TODO: This is a temporary hack for the test login fails when setting $cookie_domain.
|
// @TODO: This is a temporary hack for the test login fails when setting $cookie_domain.
|
||||||
@@ -181,7 +195,7 @@ abstract class DomainTestBase extends BrowserTestBase {
|
|||||||
}
|
}
|
||||||
// The session ID is hashed before being stored in the database.
|
// The session ID is hashed before being stored in the database.
|
||||||
// @see \Drupal\Core\Session\SessionHandler::read()
|
// @see \Drupal\Core\Session\SessionHandler::read()
|
||||||
return (bool) db_query("SELECT sid FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => Crypt::hashBase64($account->session_id)))->fetchField();
|
return (bool) db_query("SELECT sid FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", [':sid' => Crypt::hashBase64($account->session_id)])->fetchField();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-4
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain token handler.
|
* Tests the domain token handler.
|
||||||
@@ -17,7 +16,7 @@ class DomainTokenTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'block');
|
public static $modules = ['domain', 'block'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the handling of an inbound request.
|
* Tests the handling of an inbound request.
|
||||||
@@ -34,10 +33,10 @@ class DomainTokenTest extends DomainTestBase {
|
|||||||
$this->drupalPlaceBlock('domain_token_block');
|
$this->drupalPlaceBlock('domain_token_block');
|
||||||
|
|
||||||
// To get around block access, let the anon user view the block.
|
// To get around block access, let the anon user view the block.
|
||||||
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('view domain information'));
|
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['view domain information']);
|
||||||
|
|
||||||
// Test the response of the default home page.
|
// Test the response of the default home page.
|
||||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||||
$this->drupalGet($domain->getPath());
|
$this->drupalGet($domain->getPath());
|
||||||
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
||||||
$this->assertRaw('<th>Token</th>', 'Token values printed.');
|
$this->assertRaw('<th>Token</th>', 'Token values printed.');
|
||||||
|
|||||||
+21
-13
@@ -3,7 +3,6 @@
|
|||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Core\Config\ConfigValueException;
|
use Drupal\Core\Config\ConfigValueException;
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests domain record validation.
|
* Tests domain record validation.
|
||||||
@@ -19,7 +18,7 @@ class DomainValidatorTest extends DomainTestBase {
|
|||||||
// No domains should exist.
|
// No domains should exist.
|
||||||
$this->domainTableIsEmpty();
|
$this->domainTableIsEmpty();
|
||||||
$validator = \Drupal::service('domain.validator');
|
$validator = \Drupal::service('domain.validator');
|
||||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
|
|
||||||
// Create a domain.
|
// Create a domain.
|
||||||
$this->domainCreateTestDomains(1, 'foo.com');
|
$this->domainCreateTestDomains(1, 'foo.com');
|
||||||
@@ -33,15 +32,22 @@ class DomainValidatorTest extends DomainTestBase {
|
|||||||
$hostnames = [
|
$hostnames = [
|
||||||
'localhost' => 1,
|
'localhost' => 1,
|
||||||
'example.com' => 1,
|
'example.com' => 1,
|
||||||
'www.example.com' => 1, // see www-prefix test, below.
|
// See www-prefix test, below.
|
||||||
|
'www.example.com' => 1,
|
||||||
'one.example.com' => 1,
|
'one.example.com' => 1,
|
||||||
'example.com:8080' => 1,
|
'example.com:8080' => 1,
|
||||||
'example.com::8080' => 0, // only one colon.
|
// Only one colon.
|
||||||
'example.com:abc' => 0, // no letters after a colon.
|
'example.com::8080' => 0,
|
||||||
'.example.com' => 0, // cannot begin with a dot.
|
// No letters after a colon.
|
||||||
'example.com.' => 0, // cannot end with a dot.
|
'example.com:abc' => 0,
|
||||||
'EXAMPLE.com' => 0, // lowercase only.
|
// Cannot begin with a dot.
|
||||||
'éxample.com' => 0, // ascii-only.
|
'.example.com' => 0,
|
||||||
|
// Cannot end with a dot.
|
||||||
|
'example.com.' => 0,
|
||||||
|
// Lowercase only.
|
||||||
|
'EXAMPLE.com' => 0,
|
||||||
|
// ascii-only.
|
||||||
|
'éxample.com' => 0,
|
||||||
];
|
];
|
||||||
foreach ($hostnames as $hostname => $valid) {
|
foreach ($hostnames as $hostname => $valid) {
|
||||||
$errors = $validator->validate($hostname);
|
$errors = $validator->validate($hostname);
|
||||||
@@ -69,13 +75,15 @@ class DomainValidatorTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
// Test the two configurable options.
|
// Test the two configurable options.
|
||||||
$config = $this->config('domain.settings');
|
$config = $this->config('domain.settings');
|
||||||
$config->set('www_prefix', true);
|
$config->set('www_prefix', TRUE);
|
||||||
$config->set('allow_non_ascii', true);
|
$config->set('allow_non_ascii', TRUE);
|
||||||
$config->save();
|
$config->save();
|
||||||
// Valid hostnames to test. Valid is the boolean value.
|
// Valid hostnames to test. Valid is the boolean value.
|
||||||
$hostnames = [
|
$hostnames = [
|
||||||
'www.example.com' => 0, // no www-prefix allowed
|
// No www-prefix allowed.
|
||||||
'éxample.com' => 1, // ascii-only allowed.
|
'www.example.com' => 0,
|
||||||
|
// ascii-only allowed.
|
||||||
|
'éxample.com' => 1,
|
||||||
];
|
];
|
||||||
foreach ($hostnames as $hostname => $valid) {
|
foreach ($hostnames as $hostname => $valid) {
|
||||||
$errors = $validator->validate($hostname);
|
$errors = $validator->validate($hostname);
|
||||||
|
|||||||
+6
-6
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Functional;
|
namespace Drupal\Tests\domain\Functional;
|
||||||
|
|
||||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the domain access plugin for Views.
|
* Tests the domain access plugin for Views.
|
||||||
*
|
*
|
||||||
@@ -16,11 +14,13 @@ class DomainViewsAccessTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'node', 'views', 'block');
|
public static $modules = ['domain', 'node', 'views', 'block'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disabled config schema checking.
|
* Disabled config schema checking.
|
||||||
*
|
*
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
* @TODO: https://github.com/agentrickard/domain/issues/200
|
* @TODO: https://github.com/agentrickard/domain/issues/200
|
||||||
*/
|
*/
|
||||||
protected $strictConfigSchema = FALSE;
|
protected $strictConfigSchema = FALSE;
|
||||||
@@ -31,13 +31,13 @@ class DomainViewsAccessTest extends DomainTestBase {
|
|||||||
public function testInactiveDomain() {
|
public function testInactiveDomain() {
|
||||||
// Create five new domains programmatically.
|
// Create five new domains programmatically.
|
||||||
$this->domainCreateTestDomains(5);
|
$this->domainCreateTestDomains(5);
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
// Enable the views.
|
// Enable the views.
|
||||||
$this->enableViewsTestModule();
|
$this->enableViewsTestModule();
|
||||||
// Create a user. To test the area output was more difficult, so we just
|
// Create a user. To test the area output was more difficult, so we just
|
||||||
// configured two views. The page shows the first, admin, user, and the
|
// configured two views. The page shows the first, admin, user, and the
|
||||||
// block will show this new user name.
|
// block will show this new user name.
|
||||||
$this->user = $this->drupalCreateUser(array('administer domains', 'create domains'));
|
$this->user = $this->drupalCreateUser(['administer domains', 'create domains']);
|
||||||
// Place the view block.
|
// Place the view block.
|
||||||
$this->drupalPlaceBlock('views_block:domain_views_access-block_1');
|
$this->drupalPlaceBlock('views_block:domain_views_access-block_1');
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class DomainViewsAccessTest extends DomainTestBase {
|
|||||||
* using it, it cannot be enabled normally.
|
* using it, it cannot be enabled normally.
|
||||||
*/
|
*/
|
||||||
protected function enableViewsTestModule() {
|
protected function enableViewsTestModule() {
|
||||||
\Drupal::service('module_installer')->install(array('domain_test'));
|
\Drupal::service('module_installer')->install(['domain_test']);
|
||||||
$this->resetAll();
|
$this->resetAll();
|
||||||
$this->rebuildContainer();
|
$this->rebuildContainer();
|
||||||
$this->container->get('module_handler')->reload();
|
$this->container->get('module_handler')->reload();
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\domain\Kernel;
|
||||||
|
|
||||||
|
use Drupal\KernelTests\KernelTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests domain config elements.
|
||||||
|
*
|
||||||
|
* @group domain
|
||||||
|
*/
|
||||||
|
class DomainConfigTest extends KernelTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = ['domain', 'domain_config_schema_test'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setup.
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->installEntitySchema('domain');
|
||||||
|
// Install the test domain record & views config.
|
||||||
|
$this->installConfig('domain_config_schema_test');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy test method to ensure config gets installed.
|
||||||
|
*/
|
||||||
|
public function testRun() {
|
||||||
|
$this->assertTrue(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,8 +9,8 @@ use Drupal\Tests\domain\Traits\DomainTestTrait;
|
|||||||
/**
|
/**
|
||||||
* Tests domain hooks documented in domain.api.php.
|
* Tests domain hooks documented in domain.api.php.
|
||||||
*
|
*
|
||||||
* Note that the other hooks are covered by functional tests, since they involve UI
|
* Note that the other hooks are covered by functional tests, since they involve
|
||||||
* elements.
|
* UI elements.
|
||||||
*
|
*
|
||||||
* @see DomainReferencesTest
|
* @see DomainReferencesTest
|
||||||
* @see DomainListBuilderTes
|
* @see DomainListBuilderTes
|
||||||
@@ -27,25 +27,33 @@ class DomainHookTest extends KernelTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_test', 'user', 'node');
|
public static $modules = ['domain', 'domain_test', 'user', 'node'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Domain id key.
|
* Domain id key.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $key = 'example_com';
|
public $key = 'example_com';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Domain storage handler service.
|
* The Domain storage handler service.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
*/
|
*/
|
||||||
public $domainStorage;
|
public $domainStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current user service.
|
* The current user service.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Session\AccountInterface
|
||||||
*/
|
*/
|
||||||
public $currentUser;
|
public $currentUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mondule handler service.
|
* The module handler service.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||||
*/
|
*/
|
||||||
public $moduleHandler;
|
public $moduleHandler;
|
||||||
|
|
||||||
@@ -59,7 +67,7 @@ class DomainHookTest extends KernelTestBase {
|
|||||||
$this->domainCreateTestDomains();
|
$this->domainCreateTestDomains();
|
||||||
|
|
||||||
// Get the services.
|
// Get the services.
|
||||||
$this->domainStorage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$this->domainStorage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
$this->currentUser = \Drupal::service('current_user');
|
$this->currentUser = \Drupal::service('current_user');
|
||||||
$this->moduleHandler = \Drupal::service('module_handler');
|
$this->moduleHandler = \Drupal::service('module_handler');
|
||||||
}
|
}
|
||||||
@@ -74,8 +82,8 @@ class DomainHookTest extends KernelTestBase {
|
|||||||
// Internal hooks.
|
// Internal hooks.
|
||||||
$path = $domain->getPath();
|
$path = $domain->getPath();
|
||||||
$url = $domain->getUrl();
|
$url = $domain->getUrl();
|
||||||
$this->assertTrue(isset($path), new FormattableMarkup('The path property was set to %path by hook_entity_load.', array('%path' => $path)));
|
$this->assertTrue(isset($path), new FormattableMarkup('The path property was set to %path by hook_entity_load.', ['%path' => $path]));
|
||||||
$this->assertTrue(isset($url), new FormattableMarkup('The url property was set to %url by hook_entity_load.', array('%url' => $url)));
|
$this->assertTrue(isset($url), new FormattableMarkup('The url property was set to %url by hook_entity_load.', ['%url' => $url]));
|
||||||
|
|
||||||
// External hooks.
|
// External hooks.
|
||||||
$this->assertTrue($domain->foo == 'bar', 'The foo property was set to <em>bar</em> by hook_domain_load.');
|
$this->assertTrue($domain->foo == 'bar', 'The foo property was set to <em>bar</em> by hook_domain_load.');
|
||||||
@@ -102,7 +110,7 @@ class DomainHookTest extends KernelTestBase {
|
|||||||
public function testHookDomainRequestAlter() {
|
public function testHookDomainRequestAlter() {
|
||||||
// Set the request.
|
// Set the request.
|
||||||
$negotiator = \Drupal::service('domain.negotiator');
|
$negotiator = \Drupal::service('domain.negotiator');
|
||||||
$negotiator->setRequestDomain($this->base_hostname);
|
$negotiator->setRequestDomain($this->baseHostname);
|
||||||
|
|
||||||
// Check that the property was added by our hook.
|
// Check that the property was added by our hook.
|
||||||
$domain = $negotiator->getActiveDomain();
|
$domain = $negotiator->getActiveDomain();
|
||||||
@@ -116,7 +124,7 @@ class DomainHookTest extends KernelTestBase {
|
|||||||
$domain = $this->domainStorage->load($this->key);
|
$domain = $this->domainStorage->load($this->key);
|
||||||
|
|
||||||
// Set the request.
|
// Set the request.
|
||||||
$operations = $this->moduleHandler->invokeAll('domain_operations', array($domain, $this->currentUser));
|
$operations = $this->moduleHandler->invokeAll('domain_operations', [$domain, $this->currentUser]);
|
||||||
|
|
||||||
// Test that our operations were added by the hook.
|
// Test that our operations were added by the hook.
|
||||||
$this->assertTrue(isset($operations['domain_test']), 'Domain test operation loaded.');
|
$this->assertTrue(isset($operations['domain_test']), 'Domain test operation loaded.');
|
||||||
|
|||||||
+6
-2
@@ -19,15 +19,19 @@ class DomainVariableSchemeTest extends KernelTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain');
|
public static $modules = ['domain'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Domain id key.
|
* Domain id key.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $key = 'example_com';
|
public $key = 'example_com';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Domain storage handler service.
|
* The Domain storage handler service.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
*/
|
*/
|
||||||
public $domainStorage;
|
public $domainStorage;
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ class DomainVariableSchemeTest extends KernelTestBase {
|
|||||||
$this->domainCreateTestDomains();
|
$this->domainCreateTestDomains();
|
||||||
|
|
||||||
// Get the services.
|
// Get the services.
|
||||||
$this->domainStorage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
$this->domainStorage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+36
-26
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Drupal\Tests\domain\Traits;
|
namespace Drupal\Tests\domain\Traits;
|
||||||
|
|
||||||
use Drupal\domain\DomainInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains helper classes for tests to set up various configuration.
|
* Contains helper classes for tests to set up various configuration.
|
||||||
*/
|
*/
|
||||||
@@ -22,21 +20,33 @@ trait DomainTestTrait {
|
|||||||
*
|
*
|
||||||
* @param int $count
|
* @param int $count
|
||||||
* The number of domains to create.
|
* The number of domains to create.
|
||||||
* @param string|NULL $base_hostname
|
* @param string|null $base_hostname
|
||||||
* The root domain to use for domain creation (e.g. example.com).
|
* The root domain to use for domain creation (e.g. example.com).
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* An optional list of subdomains to apply instead of the default set.
|
* An optional list of subdomains to apply instead of the default set.
|
||||||
*/
|
*/
|
||||||
public function domainCreateTestDomains($count = 1, $base_hostname = NULL, $list = array()) {
|
public function domainCreateTestDomains($count = 1, $base_hostname = NULL, array $list = []) {
|
||||||
$original_domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$original_domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
if (empty($base_hostname)) {
|
if (empty($base_hostname)) {
|
||||||
$base_hostname = $this->base_hostname;
|
$base_hostname = $this->baseHostname;
|
||||||
}
|
}
|
||||||
// Note: these domains are rigged to work on my test server.
|
// Note: these domains are rigged to work on my test server.
|
||||||
// For proper testing, yours should be set up similarly, but you can pass a
|
// For proper testing, yours should be set up similarly, but you can pass a
|
||||||
// $list array to change the default.
|
// $list array to change the default.
|
||||||
if (empty($list)) {
|
if (empty($list)) {
|
||||||
$list = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten');
|
$list = [
|
||||||
|
'',
|
||||||
|
'one',
|
||||||
|
'two',
|
||||||
|
'three',
|
||||||
|
'four',
|
||||||
|
'five',
|
||||||
|
'six',
|
||||||
|
'seven',
|
||||||
|
'eight',
|
||||||
|
'nine',
|
||||||
|
'ten',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if ($i === 0) {
|
if ($i === 0) {
|
||||||
@@ -56,15 +66,15 @@ trait DomainTestTrait {
|
|||||||
$name = 'Test ' . $i;
|
$name = 'Test ' . $i;
|
||||||
}
|
}
|
||||||
// Create a new domain programmatically.
|
// Create a new domain programmatically.
|
||||||
$values = array(
|
$values = [
|
||||||
'hostname' => $hostname,
|
'hostname' => $hostname,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'id' => \Drupal::service('entity_type.manager')->getStorage('domain')->createMachineName($machine_name),
|
'id' => \Drupal::entityTypeManager()->getStorage('domain')->createMachineName($machine_name),
|
||||||
);
|
];
|
||||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||||
$domain->save();
|
$domain->save();
|
||||||
}
|
}
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,8 +84,8 @@ trait DomainTestTrait {
|
|||||||
* The entity type being acted upon.
|
* The entity type being acted upon.
|
||||||
* @param int $entity_id
|
* @param int $entity_id
|
||||||
* The entity id.
|
* The entity id.
|
||||||
* @param array $ids
|
* @param array|string $ids
|
||||||
* An array of ids to add.
|
* An id or array of ids to add.
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* The name of the domain field used to attach to the entity.
|
* The name of the domain field used to attach to the entity.
|
||||||
*/
|
*/
|
||||||
@@ -93,8 +103,8 @@ trait DomainTestTrait {
|
|||||||
* An array of domain entities.
|
* An array of domain entities.
|
||||||
*/
|
*/
|
||||||
public function getDomains() {
|
public function getDomains() {
|
||||||
\Drupal::service('entity_type.manager')->getStorage('domain')->resetCache();
|
\Drupal::entityTypeManager()->getStorage('domain')->resetCache();
|
||||||
return \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
return \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,21 +114,21 @@ trait DomainTestTrait {
|
|||||||
* An array of domain entities.
|
* An array of domain entities.
|
||||||
*/
|
*/
|
||||||
public function getDomainsSorted() {
|
public function getDomainsSorted() {
|
||||||
\Drupal::service('entity_type.manager')->getStorage('domain')->resetCache();
|
\Drupal::entityTypeManager()->getStorage('domain')->resetCache();
|
||||||
return \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted();
|
return \Drupal::entityTypeManager()->getStorage('domain')->loadMultipleSorted();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a domain hostname to a trusted host pattern.
|
* Converts a domain hostname to a trusted host pattern.
|
||||||
*
|
*
|
||||||
* @param $hostname
|
* @param string $hostname
|
||||||
* A hostname string.
|
* A hostname string.
|
||||||
*
|
*
|
||||||
* @return
|
* @return string
|
||||||
* A regex-safe hostname, without delimiters.
|
* A regex-safe hostname, without delimiters.
|
||||||
*/
|
*/
|
||||||
public function prepareTrustedHostname($hostname) {
|
public function prepareTrustedHostname($hostname) {
|
||||||
$hostname = strtolower(preg_replace('/:\d+$/', '', trim($hostname)));
|
$hostname = mb_strtolower(preg_replace('/:\d+$/', '', trim($hostname)));
|
||||||
return preg_quote($hostname);
|
return preg_quote($hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,16 +136,16 @@ trait DomainTestTrait {
|
|||||||
* Set the base hostname for this test.
|
* Set the base hostname for this test.
|
||||||
*/
|
*/
|
||||||
public function setBaseHostname() {
|
public function setBaseHostname() {
|
||||||
$this->base_hostname = \Drupal::service('entity_type.manager')->getStorage('domain')->createHostname();
|
$this->baseHostname = \Drupal::entityTypeManager()->getStorage('domain')->createHostname();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reusable test function for checking initial / empty table status.
|
* Reusable test function for checking initial / empty table status.
|
||||||
*/
|
*/
|
||||||
public function domainTableIsEmpty() {
|
public function domainTableIsEmpty() {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||||
$this->assertTrue(empty($domains), 'No domains have been created.');
|
$this->assertTrue(empty($domains), 'No domains have been created.');
|
||||||
$default_id = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultId();
|
$default_id = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultId();
|
||||||
$this->assertTrue(empty($default_id), 'No default domain has been set.');
|
$this->assertTrue(empty($default_id), 'No default domain has been set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,15 +153,15 @@ trait DomainTestTrait {
|
|||||||
* Creates domain record for use with POST request tests.
|
* Creates domain record for use with POST request tests.
|
||||||
*/
|
*/
|
||||||
public function domainPostValues() {
|
public function domainPostValues() {
|
||||||
$edit = array();
|
$edit = [];
|
||||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create();
|
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create();
|
||||||
$required = \Drupal::service('domain.validator')->getRequiredFields();
|
$required = \Drupal::service('domain.validator')->getRequiredFields();
|
||||||
foreach ($required as $key) {
|
foreach ($required as $key) {
|
||||||
$edit[$key] = $domain->get($key);
|
$edit[$key] = $domain->get($key);
|
||||||
}
|
}
|
||||||
// URL validation has issues on Travis, so only do it when requested.
|
// URL validation has issues on Travis, so only do it when requested.
|
||||||
$edit['validate_url'] = 0;
|
$edit['validate_url'] = 0;
|
||||||
$edit['id'] = \Drupal::service('entity_type.manager')->getStorage('domain')->createMachineName($edit['hostname']);
|
$edit['id'] = \Drupal::entityTypeManager()->getStorage('domain')->createMachineName($edit['hostname']);
|
||||||
return $edit;
|
return $edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
@@ -5,6 +5,9 @@ domain_access.settings:
|
|||||||
node_advanced_tab:
|
node_advanced_tab:
|
||||||
type: boolean
|
type: boolean
|
||||||
label: 'Move domain access field to a tab in the advanced settings on nodes.'
|
label: 'Move domain access field to a tab in the advanced settings on nodes.'
|
||||||
|
node_advanced_tab_open:
|
||||||
|
type: boolean
|
||||||
|
label: 'Open the Domain Access details by default.'
|
||||||
action.configuration.domain_access_all_action:
|
action.configuration.domain_access_all_action:
|
||||||
type: action_configuration_default
|
type: action_configuration_default
|
||||||
label: 'Assign content to all affiliates'
|
label: 'Assign content to all affiliates'
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package: Domain
|
|||||||
# version: VERSION
|
# version: VERSION
|
||||||
# core: 8.x
|
# core: 8.x
|
||||||
dependencies:
|
dependencies:
|
||||||
- domain
|
- drupal:node
|
||||||
- node
|
- domain:domain
|
||||||
|
|
||||||
# Information added by Drupal.org packaging script on 2018-03-08
|
# Information added by Drupal.org packaging script on 2018-11-14
|
||||||
version: '8.x-1.0-alpha13'
|
version: '8.x-1.0-alpha14+9-dev'
|
||||||
core: '8.x'
|
core: '8.x'
|
||||||
project: 'domain'
|
project: 'domain'
|
||||||
datestamp: 1520519900
|
datestamp: 1542230887
|
||||||
|
|||||||
@@ -29,8 +29,18 @@ function domain_access_install() {
|
|||||||
domain_access_confirm_fields($entity_type, $bundle);
|
domain_access_confirm_fields($entity_type, $bundle);
|
||||||
}
|
}
|
||||||
// Install our actions.
|
// Install our actions.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
domain_access_domain_insert($domain);
|
domain_access_domain_insert($domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the setting to open the domain access fieldset.
|
||||||
|
*/
|
||||||
|
function domain_access_update_8001() {
|
||||||
|
$config_factory = \Drupal::configFactory();
|
||||||
|
$config = $config_factory->getEditable('domain_access.settings');
|
||||||
|
$config->set('node_advanced_tab_open', 0);
|
||||||
|
$config->save(TRUE);
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use Drupal\Core\Access\AccessResult;
|
|||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Core\Form\FormState;
|
use Drupal\Core\Form\FormState;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the node access control field.
|
* The name of the node access control field.
|
||||||
@@ -28,12 +27,12 @@ const DOMAIN_ACCESS_ALL_FIELD = 'field_domain_all_affiliates';
|
|||||||
* Implements hook_node_grants().
|
* Implements hook_node_grants().
|
||||||
*/
|
*/
|
||||||
function domain_access_node_grants(AccountInterface $account, $op) {
|
function domain_access_node_grants(AccountInterface $account, $op) {
|
||||||
$grants = array();
|
$grants = [];
|
||||||
/** @var \Drupal\domain\Entity\Domain $active */
|
/** @var \Drupal\domain\Entity\Domain $active */
|
||||||
$active = \Drupal::service('domain.negotiator')->getActiveDomain();
|
$active = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||||
|
|
||||||
if (empty($active)) {
|
if (empty($active)) {
|
||||||
$active = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain();
|
$active = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
// No domains means no permissions.
|
// No domains means no permissions.
|
||||||
@@ -74,7 +73,7 @@ function domain_access_node_grants(AccountInterface $account, $op) {
|
|||||||
* Implements hook_node_access_records().
|
* Implements hook_node_access_records().
|
||||||
*/
|
*/
|
||||||
function domain_access_node_access_records(NodeInterface $node) {
|
function domain_access_node_access_records(NodeInterface $node) {
|
||||||
$grants = array();
|
$grants = [];
|
||||||
// Create grants for each translation of the node. See the report at
|
// Create grants for each translation of the node. See the report at
|
||||||
// https://www.drupal.org/node/2825419 for the logic here. Note that right
|
// https://www.drupal.org/node/2825419 for the logic here. Note that right
|
||||||
// now, grants may not be the same for all languages.
|
// now, grants may not be the same for all languages.
|
||||||
@@ -89,39 +88,39 @@ function domain_access_node_access_records(NodeInterface $node) {
|
|||||||
}
|
}
|
||||||
foreach ($domains as $id => $domainId) {
|
foreach ($domains as $id => $domainId) {
|
||||||
/** @var \Drupal\domain\DomainInterface $domain */
|
/** @var \Drupal\domain\DomainInterface $domain */
|
||||||
if ($domain = \Drupal::service('entity_type.manager')->getStorage('domain')->load($id)) {
|
if ($domain = \Drupal::entityTypeManager()->getStorage('domain')->load($id)) {
|
||||||
$grants[] = array(
|
$grants[] = [
|
||||||
'realm' => ($translation->isPublished()) ? 'domain_id' : 'domain_unpublished',
|
'realm' => ($translation->isPublished()) ? 'domain_id' : 'domain_unpublished',
|
||||||
'gid' => $domain->getDomainId(),
|
'gid' => $domain->getDomainId(),
|
||||||
'grant_view' => 1,
|
'grant_view' => 1,
|
||||||
'grant_update' => 1,
|
'grant_update' => 1,
|
||||||
'grant_delete' => 1,
|
'grant_delete' => 1,
|
||||||
'langcode' => $langcode,
|
'langcode' => $langcode,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set the domain_site grant.
|
// Set the domain_site grant.
|
||||||
if (!empty($translation->get(DOMAIN_ACCESS_ALL_FIELD)->value) && $translation->isPublished()) {
|
if (!empty($translation->get(DOMAIN_ACCESS_ALL_FIELD)->value) && $translation->isPublished()) {
|
||||||
$grants[] = array(
|
$grants[] = [
|
||||||
'realm' => 'domain_site',
|
'realm' => 'domain_site',
|
||||||
'gid' => 0,
|
'gid' => 0,
|
||||||
'grant_view' => 1,
|
'grant_view' => 1,
|
||||||
'grant_update' => 0,
|
'grant_update' => 0,
|
||||||
'grant_delete' => 0,
|
'grant_delete' => 0,
|
||||||
'langcode' => $langcode,
|
'langcode' => $langcode,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
// Because of language translation, we must save a record for each language.
|
// Because of language translation, we must save a record for each language.
|
||||||
// even if that record adds no permissions, as this one does.
|
// even if that record adds no permissions, as this one does.
|
||||||
else {
|
else {
|
||||||
$grants[] = array(
|
$grants[] = [
|
||||||
'realm' => 'domain_site',
|
'realm' => 'domain_site',
|
||||||
'gid' => 1,
|
'gid' => 1,
|
||||||
'grant_view' => 0,
|
'grant_view' => 0,
|
||||||
'grant_update' => 0,
|
'grant_update' => 0,
|
||||||
'grant_delete' => 0,
|
'grant_delete' => 0,
|
||||||
'langcode' => $langcode,
|
'langcode' => $langcode,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $grants;
|
return $grants;
|
||||||
@@ -167,7 +166,7 @@ function domain_access_presave_generate(EntityInterface $entity) {
|
|||||||
if (isset($entity->devel_generate['domain_access'])) {
|
if (isset($entity->devel_generate['domain_access'])) {
|
||||||
$selection = array_filter($entity->devel_generate['domain_access']);
|
$selection = array_filter($entity->devel_generate['domain_access']);
|
||||||
if (isset($selection['random-selection'])) {
|
if (isset($selection['random-selection'])) {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
$values[DOMAIN_ACCESS_FIELD] = array_rand($domains, ceil(rand(1, count($domains))));
|
$values[DOMAIN_ACCESS_FIELD] = array_rand($domains, ceil(rand(1, count($domains))));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -199,8 +198,8 @@ function domain_access_form_devel_generate_form_content_alter(&$form, &$form_sta
|
|||||||
// Add our element to the Devel generate form.
|
// Add our element to the Devel generate form.
|
||||||
$form['submit']['#weight'] = 10;
|
$form['submit']['#weight'] = 10;
|
||||||
$list = ['random-selection' => t('Random selection')];
|
$list = ['random-selection' => t('Random selection')];
|
||||||
$list += \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList();
|
$list += \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList();
|
||||||
$form['domain_access'] = array(
|
$form['domain_access'] = [
|
||||||
'#title' => t('Domains'),
|
'#title' => t('Domains'),
|
||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
'#options' => $list,
|
'#options' => $list,
|
||||||
@@ -209,8 +208,8 @@ function domain_access_form_devel_generate_form_content_alter(&$form, &$form_sta
|
|||||||
'#size' => count($list) > 5 ? 5 : count($list),
|
'#size' => count($list) > 5 ? 5 : count($list),
|
||||||
'#default_value' => ['random-selection'],
|
'#default_value' => ['random-selection'],
|
||||||
'#description' => t('Sets the domains for created nodes. Random selection overrides other choices.'),
|
'#description' => t('Sets the domains for created nodes. Random selection overrides other choices.'),
|
||||||
);
|
];
|
||||||
$form['domain_all'] = array(
|
$form['domain_all'] = [
|
||||||
'#title' => t('Send to all affiliates'),
|
'#title' => t('Send to all affiliates'),
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#options' => [
|
'#options' => [
|
||||||
@@ -221,7 +220,7 @@ function domain_access_form_devel_generate_form_content_alter(&$form, &$form_sta
|
|||||||
'#default_value' => 'random-selection',
|
'#default_value' => 'random-selection',
|
||||||
'#weight' => 3,
|
'#weight' => 3,
|
||||||
'#description' => t('Sets visibility across all affiliates.'),
|
'#description' => t('Sets visibility across all affiliates.'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,21 +245,22 @@ function domain_access_form_node_form_alter(&$form, FormState $form_state, $form
|
|||||||
empty($form[DOMAIN_ACCESS_FIELD]['#group']) &&
|
empty($form[DOMAIN_ACCESS_FIELD]['#group']) &&
|
||||||
empty($form[DOMAIN_ACCESS_ALL_FIELD]['#group'])
|
empty($form[DOMAIN_ACCESS_ALL_FIELD]['#group'])
|
||||||
) {
|
) {
|
||||||
// Move to the tabs on the entity form
|
// Move to the tabs on the entity form.
|
||||||
$form[DOMAIN_ACCESS_FIELD]['#group'] = 'domain';
|
$form[DOMAIN_ACCESS_FIELD]['#group'] = 'domain';
|
||||||
$form[DOMAIN_ACCESS_ALL_FIELD]['#group'] = 'domain';
|
$form[DOMAIN_ACCESS_ALL_FIELD]['#group'] = 'domain';
|
||||||
$form['domain'] = [
|
$form['domain'] = [
|
||||||
'#type' => 'details',
|
'#type' => 'details',
|
||||||
|
'#open' => (bool) \Drupal::config('domain_access.settings')->get('node_advanced_tab_open'),
|
||||||
'#title' => t('Domain settings'),
|
'#title' => t('Domain settings'),
|
||||||
'#group' => 'advanced',
|
'#group' => 'advanced',
|
||||||
'#attributes' => [
|
'#attributes' => [
|
||||||
'class' => ['node-form-options']
|
'class' => ['node-form-options'],
|
||||||
],
|
],
|
||||||
'#attached' => [
|
'#attached' => [
|
||||||
'library' => ['node/drupal.node'],
|
'library' => ['node/drupal.node'],
|
||||||
],
|
],
|
||||||
'#weight' => 100,
|
'#weight' => 100,
|
||||||
'#optional' => TRUE
|
'#optional' => TRUE,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
// Add the options hidden from the user silently to the form.
|
// Add the options hidden from the user silently to the form.
|
||||||
@@ -480,6 +480,19 @@ function domain_access_node_type_insert(EntityInterface $entity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_ENTITY_TYPE_insert().
|
||||||
|
*
|
||||||
|
* In some cases, form display modes are not set when the node type is created.
|
||||||
|
* be sure to update our field definitions on creation of form_display for
|
||||||
|
* node types.
|
||||||
|
*/
|
||||||
|
function domain_access_entity_form_display_insert(EntityInterface $entity) {
|
||||||
|
if (!$entity->isSyncing() && $entity->getTargetEntityTypeId() == 'node' && $bundle = $entity->getTargetBundle()) {
|
||||||
|
domain_access_confirm_fields('node', $bundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates our fields for an entity bundle.
|
* Creates our fields for an entity bundle.
|
||||||
*
|
*
|
||||||
@@ -499,12 +512,13 @@ function domain_access_node_type_insert(EntityInterface $entity) {
|
|||||||
* This function is here for convenience during installation. It is not really
|
* This function is here for convenience during installation. It is not really
|
||||||
* an API function. Modules wishing to add fields to non-node entities must
|
* an API function. Modules wishing to add fields to non-node entities must
|
||||||
* provide their own field storage. See the field storage YML sample in
|
* provide their own field storage. See the field storage YML sample in
|
||||||
* tests/modules/domain_access_test for an example of field storage definitions.
|
* tests/modules/domain_access_test for an example of field storage
|
||||||
|
* definitions.
|
||||||
*
|
*
|
||||||
* @see domain_access_node_type_insert()
|
* @see domain_access_node_type_insert()
|
||||||
* @see domain_access_install()
|
* @see domain_access_install()
|
||||||
*/
|
*/
|
||||||
function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
function domain_access_confirm_fields($entity_type, $bundle, array $text = []) {
|
||||||
// We have reports that importing config causes this function to fail.
|
// We have reports that importing config causes this function to fail.
|
||||||
try {
|
try {
|
||||||
$text['node'] = [
|
$text['node'] = [
|
||||||
@@ -522,7 +536,7 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
|||||||
|
|
||||||
$field_storage = \Drupal::entityTypeManager()->getStorage('field_config');
|
$field_storage = \Drupal::entityTypeManager()->getStorage('field_config');
|
||||||
if (!$field = $field_storage->load($id)) {
|
if (!$field = $field_storage->load($id)) {
|
||||||
$field = array(
|
$field = [
|
||||||
'field_name' => DOMAIN_ACCESS_FIELD,
|
'field_name' => DOMAIN_ACCESS_FIELD,
|
||||||
'entity_type' => $entity_type,
|
'entity_type' => $entity_type,
|
||||||
'label' => 'Domain Access',
|
'label' => 'Domain Access',
|
||||||
@@ -531,7 +545,7 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
|||||||
'required' => $entity_type !== 'user',
|
'required' => $entity_type !== 'user',
|
||||||
'description' => 'Select the affiliate domain(s) for this ' . $text[$entity_type]['name'],
|
'description' => 'Select the affiliate domain(s) for this ' . $text[$entity_type]['name'],
|
||||||
'default_value_callback' => 'Drupal\domain_access\DomainAccessManager::getDefaultValue',
|
'default_value_callback' => 'Drupal\domain_access\DomainAccessManager::getDefaultValue',
|
||||||
'settings' => array(
|
'settings' => [
|
||||||
'handler' => 'default:domain',
|
'handler' => 'default:domain',
|
||||||
// Handler_settings are deprecated but seem to be necessary here.
|
// Handler_settings are deprecated but seem to be necessary here.
|
||||||
'handler_settings' => [
|
'handler_settings' => [
|
||||||
@@ -540,22 +554,22 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
|||||||
],
|
],
|
||||||
'target_bundles' => NULL,
|
'target_bundles' => NULL,
|
||||||
'sort' => ['field' => 'weight', 'direction' => 'ASC'],
|
'sort' => ['field' => 'weight', 'direction' => 'ASC'],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$field_config = $field_storage->create($field);
|
$field_config = $field_storage->create($field);
|
||||||
$field_config->save();
|
$field_config->save();
|
||||||
}
|
}
|
||||||
// Assign the all affiliates field.
|
// Assign the all affiliates field.
|
||||||
$id = $entity_type . '.' . $bundle . '.' . DOMAIN_ACCESS_ALL_FIELD;
|
$id = $entity_type . '.' . $bundle . '.' . DOMAIN_ACCESS_ALL_FIELD;
|
||||||
if (!$field = $field_storage->load($id)) {
|
if (!$field = $field_storage->load($id)) {
|
||||||
$field = array(
|
$field = [
|
||||||
'field_name' => DOMAIN_ACCESS_ALL_FIELD,
|
'field_name' => DOMAIN_ACCESS_ALL_FIELD,
|
||||||
'entity_type' => $entity_type,
|
'entity_type' => $entity_type,
|
||||||
'label' => $text[$entity_type]['label'],
|
'label' => $text[$entity_type]['label'],
|
||||||
'bundle' => $bundle,
|
'bundle' => $bundle,
|
||||||
'required' => FALSE,
|
'required' => FALSE,
|
||||||
'description' => $text[$entity_type]['description'],
|
'description' => $text[$entity_type]['description'],
|
||||||
);
|
];
|
||||||
$field_config = $field_storage->create($field);
|
$field_config = $field_storage->create($field);
|
||||||
$field_config->save();
|
$field_config->save();
|
||||||
}
|
}
|
||||||
@@ -586,16 +600,16 @@ function domain_access_views_data_alter(array &$data) {
|
|||||||
$data[$table][DOMAIN_ACCESS_FIELD . '_target_id']['argument']['id'] = 'domain_access_argument';
|
$data[$table][DOMAIN_ACCESS_FIELD . '_target_id']['argument']['id'] = 'domain_access_argument';
|
||||||
|
|
||||||
// Current domain filter.
|
// Current domain filter.
|
||||||
$data[$table]['current_all'] = array(
|
$data[$table]['current_all'] = [
|
||||||
'title' => t('Current domain'),
|
'title' => t('Current domain'),
|
||||||
'group' => t('Domain'),
|
'group' => t('Domain'),
|
||||||
'filter' => array(
|
'filter' => [
|
||||||
'field' => DOMAIN_ACCESS_FIELD . '_target_id',
|
'field' => DOMAIN_ACCESS_FIELD . '_target_id',
|
||||||
'id' => 'domain_access_current_all_filter',
|
'id' => 'domain_access_current_all_filter',
|
||||||
'title' => t('Available on current domain'),
|
'title' => t('Available on current domain'),
|
||||||
'help' => t('Filters out nodes not available on current domain (published to current domain or all affiliates).'),
|
'help' => t('Filters out nodes not available on current domain (published to current domain or all affiliates).'),
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
// Since domains are not stored in the database, relationships cannot be used.
|
// Since domains are not stored in the database, relationships cannot be used.
|
||||||
unset($data[$table][DOMAIN_ACCESS_FIELD]['relationship']);
|
unset($data[$table][DOMAIN_ACCESS_FIELD]['relationship']);
|
||||||
|
|
||||||
@@ -622,57 +636,57 @@ function domain_access_domain_insert($entity) {
|
|||||||
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
||||||
if (!$controller->load($id)) {
|
if (!$controller->load($id)) {
|
||||||
/** @var \Drupal\system\Entity\Action $action */
|
/** @var \Drupal\system\Entity\Action $action */
|
||||||
$action = $controller->create(array(
|
$action = $controller->create([
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'type' => 'node',
|
'type' => 'node',
|
||||||
'label' => t('Add selected content to the @label domain', array('@label' => $entity->label())),
|
'label' => t('Add selected content to the @label domain', ['@label' => $entity->label()]),
|
||||||
'configuration' => array(
|
'configuration' => [
|
||||||
'domain_id' => $entity->id(),
|
'domain_id' => $entity->id(),
|
||||||
),
|
],
|
||||||
'plugin' => 'domain_access_add_action',
|
'plugin' => 'domain_access_add_action',
|
||||||
));
|
]);
|
||||||
$action->trustData()->save();
|
$action->trustData()->save();
|
||||||
}
|
}
|
||||||
$remove_id = 'domain_access_remove_action.' . $entity->id();
|
$remove_id = 'domain_access_remove_action.' . $entity->id();
|
||||||
if (!$controller->load($remove_id)) {
|
if (!$controller->load($remove_id)) {
|
||||||
/** @var \Drupal\system\Entity\Action $action */
|
/** @var \Drupal\system\Entity\Action $action */
|
||||||
$action = $controller->create(array(
|
$action = $controller->create([
|
||||||
'id' => $remove_id,
|
'id' => $remove_id,
|
||||||
'type' => 'node',
|
'type' => 'node',
|
||||||
'label' => t('Remove selected content from the @label domain', array('@label' => $entity->label())),
|
'label' => t('Remove selected content from the @label domain', ['@label' => $entity->label()]),
|
||||||
'configuration' => array(
|
'configuration' => [
|
||||||
'domain_id' => $entity->id(),
|
'domain_id' => $entity->id(),
|
||||||
),
|
],
|
||||||
'plugin' => 'domain_access_remove_action',
|
'plugin' => 'domain_access_remove_action',
|
||||||
));
|
]);
|
||||||
$action->trustData()->save();
|
$action->trustData()->save();
|
||||||
}
|
}
|
||||||
$id = 'domain_access_add_editor_action.' . $entity->id();
|
$id = 'domain_access_add_editor_action.' . $entity->id();
|
||||||
if (!$controller->load($id)) {
|
if (!$controller->load($id)) {
|
||||||
/** @var \Drupal\system\Entity\Action $action */
|
/** @var \Drupal\system\Entity\Action $action */
|
||||||
$action = $controller->create(array(
|
$action = $controller->create([
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'label' => t('Add editors to the @label domain', array('@label' => $entity->label())),
|
'label' => t('Add editors to the @label domain', ['@label' => $entity->label()]),
|
||||||
'configuration' => array(
|
'configuration' => [
|
||||||
'domain_id' => $entity->id(),
|
'domain_id' => $entity->id(),
|
||||||
),
|
],
|
||||||
'plugin' => 'domain_access_add_editor_action',
|
'plugin' => 'domain_access_add_editor_action',
|
||||||
));
|
]);
|
||||||
$action->trustData()->save();
|
$action->trustData()->save();
|
||||||
}
|
}
|
||||||
$remove_id = 'domain_access_remove_editor_action.' . $entity->id();
|
$remove_id = 'domain_access_remove_editor_action.' . $entity->id();
|
||||||
if (!$controller->load($remove_id)) {
|
if (!$controller->load($remove_id)) {
|
||||||
/** @var \Drupal\system\Entity\Action $action */
|
/** @var \Drupal\system\Entity\Action $action */
|
||||||
$action = $controller->create(array(
|
$action = $controller->create([
|
||||||
'id' => $remove_id,
|
'id' => $remove_id,
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'label' => t('Remove editors from the @label domain', array('@label' => $entity->label())),
|
'label' => t('Remove editors from the @label domain', ['@label' => $entity->label()]),
|
||||||
'configuration' => array(
|
'configuration' => [
|
||||||
'domain_id' => $entity->id(),
|
'domain_id' => $entity->id(),
|
||||||
),
|
],
|
||||||
'plugin' => 'domain_access_remove_editor_action',
|
'plugin' => 'domain_access_remove_editor_action',
|
||||||
));
|
]);
|
||||||
$action->trustData()->save();
|
$action->trustData()->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -682,12 +696,12 @@ function domain_access_domain_insert($entity) {
|
|||||||
*/
|
*/
|
||||||
function domain_access_domain_delete(EntityInterface $entity) {
|
function domain_access_domain_delete(EntityInterface $entity) {
|
||||||
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
||||||
$actions = $controller->loadMultiple(array(
|
$actions = $controller->loadMultiple([
|
||||||
'domain_access_add_action.' . $entity->id(),
|
'domain_access_add_action.' . $entity->id(),
|
||||||
'domain_access_remove_action.' . $entity->id(),
|
'domain_access_remove_action.' . $entity->id(),
|
||||||
'domain_access_add_editor_action.' . $entity->id(),
|
'domain_access_add_editor_action.' . $entity->id(),
|
||||||
'domain_access_remove_editor_action.' . $entity->id(),
|
'domain_access_remove_editor_action.' . $entity->id(),
|
||||||
));
|
]);
|
||||||
foreach ($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$action->delete();
|
$action->delete();
|
||||||
}
|
}
|
||||||
@@ -700,7 +714,7 @@ function domain_access_domain_delete(EntityInterface $entity) {
|
|||||||
* default values properly. Note that here we just care if the form saves an
|
* default values properly. Note that here we just care if the form saves an
|
||||||
* entity. We then pass that entity to a helper function.
|
* entity. We then pass that entity to a helper function.
|
||||||
*
|
*
|
||||||
* @see domain_access_default_form_values().
|
* @see domain_access_default_form_values()
|
||||||
*/
|
*/
|
||||||
function domain_access_form_alter(&$form, &$form_state, $form_id) {
|
function domain_access_form_alter(&$form, &$form_state, $form_id) {
|
||||||
if ($object = $form_state->getFormObject() && !empty($object) && is_callable([$object, 'getEntity']) && $entity = $object->getEntity()) {
|
if ($object = $form_state->getFormObject() && !empty($object) && is_callable([$object, 'getEntity']) && $entity = $object->getEntity()) {
|
||||||
@@ -714,7 +728,7 @@ function domain_access_form_alter(&$form, &$form_state, $form_id) {
|
|||||||
* This function is a workaround for a core bug. When the domain access field
|
* This function is a workaround for a core bug. When the domain access field
|
||||||
* is not accessible to some users, the existing values are not preserved.
|
* is not accessible to some users, the existing values are not preserved.
|
||||||
*
|
*
|
||||||
* @see domain_access_entity_field_access().
|
* @see domain_access_entity_field_access()
|
||||||
*/
|
*/
|
||||||
function domain_access_default_form_values(&$form, &$form_state, $entity) {
|
function domain_access_default_form_values(&$form, &$form_state, $entity) {
|
||||||
// Set domain access default value when the user does not have access
|
// Set domain access default value when the user does not have access
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
domain_access.manager:
|
domain_access.manager:
|
||||||
class: Drupal\domain_access\DomainAccessManager
|
class: Drupal\domain_access\DomainAccessManager
|
||||||
arguments: ['@domain.negotiator']
|
arguments: ['@domain.negotiator', '@module_handler', '@entity_type.manager']
|
||||||
access_check.domain_access_views:
|
access_check.domain_access_views:
|
||||||
class: Drupal\domain_access\Access\DomainAccessViewsAccess
|
class: Drupal\domain_access\Access\DomainAccessViewsAccess
|
||||||
arguments: ['@entity_type.manager', '@domain_access.manager']
|
arguments: ['@entity_type.manager', '@domain_access.manager']
|
||||||
|
|||||||
+8
-4
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Drupal\domain_access\Access;
|
namespace Drupal\domain_access\Access;
|
||||||
|
|
||||||
use Drupal\Core\Access\AccessCheckInterface;
|
use Drupal\Core\Access\AccessCheckInterface;
|
||||||
@@ -6,10 +7,13 @@ use Drupal\Core\Access\AccessResult;
|
|||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Drupal\domain\DomainInterface;
|
|
||||||
use Drupal\domain_access\DomainAccessManagerInterface;
|
use Drupal\domain_access\DomainAccessManagerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DomainAccessViewsAccess.
|
||||||
|
*
|
||||||
|
* @package Drupal\domain_access\Access
|
||||||
|
*/
|
||||||
class DomainAccessViewsAccess implements AccessCheckInterface {
|
class DomainAccessViewsAccess implements AccessCheckInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,7 +33,7 @@ class DomainAccessViewsAccess implements AccessCheckInterface {
|
|||||||
/**
|
/**
|
||||||
* The Domain storage handler.
|
* The Domain storage handler.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain\DomainStorageInterface $domainStorage
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
*/
|
*/
|
||||||
protected $domainStorage;
|
protected $domainStorage;
|
||||||
|
|
||||||
@@ -43,7 +47,7 @@ class DomainAccessViewsAccess implements AccessCheckInterface {
|
|||||||
/**
|
/**
|
||||||
* The Domain access manager.
|
* The Domain access manager.
|
||||||
*
|
*
|
||||||
* @var \Drupal\domain_access\DomainAccessManagerInterface $manager
|
* @var \Drupal\domain_access\DomainAccessManagerInterface
|
||||||
*/
|
*/
|
||||||
protected $manager;
|
protected $manager;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Drupal\domain_access;
|
namespace Drupal\domain_access;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||||
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainInterface;
|
use Drupal\domain\DomainInterface;
|
||||||
use Drupal\domain\DomainNegotiatorInterface;
|
use Drupal\domain\DomainNegotiatorInterface;
|
||||||
@@ -19,24 +19,54 @@ use Drupal\domain\DomainNegotiatorInterface;
|
|||||||
class DomainAccessManager implements DomainAccessManagerInterface {
|
class DomainAccessManager implements DomainAccessManagerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The domain negotiator.
|
||||||
|
*
|
||||||
* @var \Drupal\domain\DomainNegotiatorInterface
|
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||||
*/
|
*/
|
||||||
protected $negotiator;
|
protected $negotiator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Drupal module handler.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||||
|
*/
|
||||||
|
protected $moduleHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entity type manager.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
|
*/
|
||||||
|
protected $entityTypeManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The domain storage.
|
||||||
|
*
|
||||||
|
* @var \Drupal\domain\DomainStorageInterface
|
||||||
|
*/
|
||||||
|
protected $domainStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DomainAccessManager object.
|
* Constructs a DomainAccessManager object.
|
||||||
*
|
*
|
||||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||||
* The domain negotiator.
|
* The domain negotiator.
|
||||||
|
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||||
|
* The Drupal module handler.
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
|
* The entity type manager.
|
||||||
*/
|
*/
|
||||||
public function __construct(DomainNegotiatorInterface $negotiator) {
|
public function __construct(DomainNegotiatorInterface $negotiator, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
|
||||||
$this->negotiator = $negotiator;
|
$this->negotiator = $negotiator;
|
||||||
|
$this->moduleHandler = $module_handler;
|
||||||
|
$this->entityTypeManager = $entity_type_manager;
|
||||||
|
$this->domainStorage = $entity_type_manager->getStorage('domain');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function getAccessValues(EntityInterface $entity, $field_name = DOMAIN_ACCESS_FIELD) {
|
public static function getAccessValues(FieldableEntityInterface $entity, $field_name = DOMAIN_ACCESS_FIELD) {
|
||||||
// @TODO: static cache.
|
// @TODO: static cache.
|
||||||
$list = [];
|
$list = [];
|
||||||
// @TODO In tests, $entity is returning NULL.
|
// @TODO In tests, $entity is returning NULL.
|
||||||
@@ -59,16 +89,16 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function getAllValue(EntityInterface $entity) {
|
public static function getAllValue(FieldableEntityInterface $entity) {
|
||||||
return $entity->hasField(DOMAIN_ACCESS_ALL_FIELD) ? $entity->get(DOMAIN_ACCESS_ALL_FIELD)->value : NULL;
|
return $entity->hasField(DOMAIN_ACCESS_ALL_FIELD) ? $entity->get(DOMAIN_ACCESS_ALL_FIELD)->value : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function checkEntityAccess(EntityInterface $entity, AccountInterface $account) {
|
public function checkEntityAccess(FieldableEntityInterface $entity, AccountInterface $account) {
|
||||||
$entity_domains = $this->getAccessValues($entity);
|
$entity_domains = $this->getAccessValues($entity);
|
||||||
$user = \Drupal::entityTypeManager()->getStorage('user')->load($account->id());
|
$user = \Drupal::entityTypeManager()->getStorage('user')->load($account->id());
|
||||||
if (!empty($this->getAllValue($user)) && !empty($entity_domains)) {
|
if (!empty($this->getAllValue($user)) && !empty($entity_domains)) {
|
||||||
@@ -79,7 +109,7 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function getDefaultValue(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
public static function getDefaultValue(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
|
||||||
$item = [];
|
$item = [];
|
||||||
@@ -100,7 +130,7 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function hasDomainPermissions(AccountInterface $account, DomainInterface $domain, array $permissions, $conjunction = 'AND') {
|
public function hasDomainPermissions(AccountInterface $account, DomainInterface $domain, array $permissions, $conjunction = 'AND') {
|
||||||
// Assume no access.
|
// Assume no access.
|
||||||
@@ -137,4 +167,37 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
|||||||
return $access;
|
return $access;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContentUrls(FieldableEntityInterface $entity) {
|
||||||
|
$list = [];
|
||||||
|
$processed = FALSE;
|
||||||
|
$domains = $this->getAccessValues($entity);
|
||||||
|
if ($this->moduleHandler->moduleExists('domain_source')) {
|
||||||
|
$source = domain_source_get($entity);
|
||||||
|
if (isset($domains[$source])) {
|
||||||
|
unset($domains['source']);
|
||||||
|
}
|
||||||
|
if (!empty($source)) {
|
||||||
|
$list[] = $source;
|
||||||
|
}
|
||||||
|
$processed = TRUE;
|
||||||
|
}
|
||||||
|
$list = array_merge($list, array_keys($domains));
|
||||||
|
$domains = $this->domainStorage->loadMultiple($list);
|
||||||
|
$urls = [];
|
||||||
|
foreach ($domains as $domain) {
|
||||||
|
$options['domain_target_id'] = $domain->id();
|
||||||
|
$url = $entity->toUrl('canonical', $options);
|
||||||
|
if ($processed) {
|
||||||
|
$urls[$domain->id()] = $url->toString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$urls[$domain->id()] = trim($domain->getPath(), '/') . $url->toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-11
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
namespace Drupal\domain_access;
|
namespace Drupal\domain_access;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\domain\DomainInterface;
|
use Drupal\domain\DomainInterface;
|
||||||
|
|
||||||
@@ -17,7 +15,7 @@ interface DomainAccessManagerInterface {
|
|||||||
/**
|
/**
|
||||||
* Get the domain access field values from an entity.
|
* Get the domain access field values from an entity.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||||
* The entity to retrieve field data from.
|
* The entity to retrieve field data from.
|
||||||
* @param string $field_name
|
* @param string $field_name
|
||||||
* The name of the field that holds our data.
|
* The name of the field that holds our data.
|
||||||
@@ -25,23 +23,23 @@ interface DomainAccessManagerInterface {
|
|||||||
* @return array
|
* @return array
|
||||||
* The domain access field values.
|
* The domain access field values.
|
||||||
*/
|
*/
|
||||||
public static function getAccessValues(EntityInterface $entity, $field_name = DOMAIN_ACCESS_FIELD);
|
public static function getAccessValues(FieldableEntityInterface $entity, $field_name = DOMAIN_ACCESS_FIELD);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the all affiliates field values from an entity.
|
* Get the all affiliates field values from an entity.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||||
* The entity to retrieve field data from.
|
* The entity to retrieve field data from.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* Returns TRUE if the entity is sent to all affiliates.
|
* Returns TRUE if the entity is sent to all affiliates.
|
||||||
*/
|
*/
|
||||||
public static function getAllValue(EntityInterface $entity);
|
public static function getAllValue(FieldableEntityInterface $entity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the entity values against a user's account assignments.
|
* Compare the entity values against a user's account assignments.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||||
* The entity being checked for access.
|
* The entity being checked for access.
|
||||||
* @param \Drupal\Core\Session\AccountInterface $account
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
* The account of the user performing the action.
|
* The account of the user performing the action.
|
||||||
@@ -49,7 +47,7 @@ interface DomainAccessManagerInterface {
|
|||||||
* @return bool
|
* @return bool
|
||||||
* Returns TRUE if the user has access to the domain.
|
* Returns TRUE if the user has access to the domain.
|
||||||
*/
|
*/
|
||||||
public function checkEntityAccess(EntityInterface $entity, AccountInterface $account);
|
public function checkEntityAccess(FieldableEntityInterface $entity, AccountInterface $account);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default field value for an entity.
|
* Get the default field value for an entity.
|
||||||
@@ -67,14 +65,14 @@ interface DomainAccessManagerInterface {
|
|||||||
/**
|
/**
|
||||||
* Checks that a user belongs to the domain and has a set of permissions.
|
* Checks that a user belongs to the domain and has a set of permissions.
|
||||||
*
|
*
|
||||||
* @param AccountInterface $account
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
* The user account.
|
* The user account.
|
||||||
* @param DomainInterface $domain
|
* @param \Drupal\domain\DomainInterface $domain
|
||||||
* The domain being checked.
|
* The domain being checked.
|
||||||
* @param array $permissions
|
* @param array $permissions
|
||||||
* The relevant permissions to check.
|
* The relevant permissions to check.
|
||||||
* @param string $conjunction
|
* @param string $conjunction
|
||||||
*. The conunction AND|OR to use when checking permssions.
|
* The conjunction AND|OR to use when checking permissions.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* Returns TRUE if the user is assigned to the domain and has the necessary
|
* Returns TRUE if the user is assigned to the domain and has the necessary
|
||||||
@@ -82,4 +80,16 @@ interface DomainAccessManagerInterface {
|
|||||||
*/
|
*/
|
||||||
public function hasDomainPermissions(AccountInterface $account, DomainInterface $domain, array $permissions, $conjunction = 'AND');
|
public function hasDomainPermissions(AccountInterface $account, DomainInterface $domain, array $permissions, $conjunction = 'AND');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all possible URLs pointing to an entity.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||||
|
* The entity to retrieve field data from.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An array of absolute URLs keyed by domain_id, with an known canonical id
|
||||||
|
* as the first element of the array.
|
||||||
|
*/
|
||||||
|
public function getContentUrls(FieldableEntityInterface $entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -16,35 +16,35 @@ class DomainAccessPermissions {
|
|||||||
* Define permissions.
|
* Define permissions.
|
||||||
*/
|
*/
|
||||||
public function permissions() {
|
public function permissions() {
|
||||||
$permissions = array(
|
$permissions = [
|
||||||
'assign domain editors' => array(
|
'assign domain editors' => [
|
||||||
'title' => $this->t('Assign additional editors to assigned domains'),
|
'title' => $this->t('Assign additional editors to assigned domains'),
|
||||||
'restrict access' => TRUE,
|
'restrict access' => TRUE,
|
||||||
),
|
],
|
||||||
'assign editors to any domain' => array(
|
'assign editors to any domain' => [
|
||||||
'title' => $this->t('Assign additional editors to any domains'),
|
'title' => $this->t('Assign additional editors to any domains'),
|
||||||
'restrict access' => TRUE,
|
'restrict access' => TRUE,
|
||||||
),
|
],
|
||||||
'publish to any domain' => array(
|
'publish to any domain' => [
|
||||||
'title' => $this->t('Publish to any domain'),
|
'title' => $this->t('Publish to any domain'),
|
||||||
),
|
],
|
||||||
'publish to any assigned domain' => array(
|
'publish to any assigned domain' => [
|
||||||
'title' => $this->t('Publish content to any assigned domain'),
|
'title' => $this->t('Publish content to any assigned domain'),
|
||||||
),
|
],
|
||||||
'create domain content' => array(
|
'create domain content' => [
|
||||||
'title' => $this->t('Create any content on assigned domains'),
|
'title' => $this->t('Create any content on assigned domains'),
|
||||||
),
|
],
|
||||||
'edit domain content' => array(
|
'edit domain content' => [
|
||||||
'title' => $this->t('Edit any content on assigned domains'),
|
'title' => $this->t('Edit any content on assigned domains'),
|
||||||
),
|
],
|
||||||
'delete domain content' => array(
|
'delete domain content' => [
|
||||||
'title' => $this->t('Delete any content on assigned domains'),
|
'title' => $this->t('Delete any content on assigned domains'),
|
||||||
),
|
],
|
||||||
'view unpublished domain content' => array(
|
'view unpublished domain content' => [
|
||||||
'title' => $this->t('View unpublished content on assigned domains'),
|
'title' => $this->t('View unpublished content on assigned domains'),
|
||||||
'restrict access' => TRUE,
|
'restrict access' => TRUE,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
// Generate standard node permissions for all applicable node types.
|
// Generate standard node permissions for all applicable node types.
|
||||||
foreach (NodeType::loadMultiple() as $type) {
|
foreach (NodeType::loadMultiple() as $type) {
|
||||||
@@ -59,7 +59,7 @@ class DomainAccessPermissions {
|
|||||||
*
|
*
|
||||||
* Shamelessly lifted from node_list_permissions().
|
* Shamelessly lifted from node_list_permissions().
|
||||||
*
|
*
|
||||||
* @param NodeType $type
|
* @param \Drupal\node\Entity\NodeType $type
|
||||||
* The node type object.
|
* The node type object.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
@@ -68,17 +68,17 @@ class DomainAccessPermissions {
|
|||||||
private function nodePermissions(NodeType $type) {
|
private function nodePermissions(NodeType $type) {
|
||||||
// Build standard list of node permissions for this type.
|
// Build standard list of node permissions for this type.
|
||||||
$id = $type->id();
|
$id = $type->id();
|
||||||
$perms = array(
|
$perms = [
|
||||||
"create $id content on assigned domains" => array(
|
"create $id content on assigned domains" => [
|
||||||
'title' => $this->t('%type_name: Create new content on assigned domains', array('%type_name' => $type->label())),
|
'title' => $this->t('%type_name: Create new content on assigned domains', ['%type_name' => $type->label()]),
|
||||||
),
|
],
|
||||||
"update $id content on assigned domains" => array(
|
"update $id content on assigned domains" => [
|
||||||
'title' => $this->t('%type_name: Edit any content on assigned domains', array('%type_name' => $type->label())),
|
'title' => $this->t('%type_name: Edit any content on assigned domains', ['%type_name' => $type->label()]),
|
||||||
),
|
],
|
||||||
"delete $id content on assigned domains" => array(
|
"delete $id content on assigned domains" => [
|
||||||
'title' => $this->t('%type_name: Delete any content on assigned domains', array('%type_name' => $type->label())),
|
'title' => $this->t('%type_name: Delete any content on assigned domains', ['%type_name' => $type->label()]),
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
return $perms;
|
return $perms;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-8
@@ -1,15 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Settings form for Domain Access.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Drupal\domain_access\Form;
|
namespace Drupal\domain_access\Form;
|
||||||
|
|
||||||
use Drupal\Core\Form\ConfigFormBase;
|
use Drupal\Core\Form\ConfigFormBase;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DomainAccessSettingsForm.
|
||||||
|
*
|
||||||
|
* @package Drupal\domain_access\Form
|
||||||
|
*/
|
||||||
class DomainAccessSettingsForm extends ConfigFormBase {
|
class DomainAccessSettingsForm extends ConfigFormBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -29,12 +31,23 @@ class DomainAccessSettingsForm extends ConfigFormBase {
|
|||||||
*/
|
*/
|
||||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
$config = $this->config('domain_access.settings');
|
$config = $this->config('domain_access.settings');
|
||||||
$form['node_advanced_tab'] = array(
|
$form['node_advanced_tab'] = [
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => $this->t('Move Domain Access fields to advanced node settings.'),
|
'#title' => $this->t('Move Domain Access fields to advanced node settings.'),
|
||||||
'#default_value' => $config->get('node_advanced_tab'),
|
'#default_value' => $config->get('node_advanced_tab'),
|
||||||
'#description' => $this->t('When checked the Domain Access fields will be shown as a tab in the advanced settings on node edit form. However, if you have placed the fields in a field group already, they will not be moved.'),
|
'#description' => $this->t('When checked the Domain Access fields will be shown as a tab in the advanced settings on node edit form. However, if you have placed the fields in a field group already, they will not be moved.'),
|
||||||
);
|
];
|
||||||
|
$form['node_advanced_tab_open'] = [
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => $this->t('Open the Domain Access details.'),
|
||||||
|
'#description' => $this->t('Set the details tab to be open by default.'),
|
||||||
|
'#default_value' => $config->get('node_advanced_tab_open'),
|
||||||
|
'#states' => [
|
||||||
|
'visible' => [
|
||||||
|
':input[name="node_advanced_tab"]' => ['checked' => TRUE],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
return parent::buildForm($form, $form_state);
|
return parent::buildForm($form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,11 +56,11 @@ class DomainAccessSettingsForm extends ConfigFormBase {
|
|||||||
*/
|
*/
|
||||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
$this->config('domain_access.settings')
|
$this->config('domain_access.settings')
|
||||||
->set('node_advanced_tab', $form_state->getValue('node_advanced_tab'))
|
->set('node_advanced_tab', (bool) $form_state->getValue('node_advanced_tab'))
|
||||||
|
->set('node_advanced_tab_open', (bool) $form_state->getValue('node_advanced_tab_open'))
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
parent::submitForm($form, $form_state);
|
parent::submitForm($form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -48,23 +48,23 @@ abstract class DomainAccessActionBase extends ConfigurableActionBase implements
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function defaultConfiguration() {
|
public function defaultConfiguration() {
|
||||||
return array(
|
return [
|
||||||
'domain_id' => '',
|
'domain_id' => '',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList();
|
||||||
$form['domain_id'] = array(
|
$form['domain_id'] = [
|
||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
'#title' => t('Domain'),
|
'#title' => t('Domain'),
|
||||||
'#options' => $domains,
|
'#options' => $domains,
|
||||||
'#default_value' => $this->configuration['id'],
|
'#default_value' => $this->configuration['id'],
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
);
|
];
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -4,17 +4,14 @@ namespace Drupal\domain_access\Plugin\views\access;
|
|||||||
|
|
||||||
use Drupal\Core\Cache\Cache;
|
use Drupal\Core\Cache\Cache;
|
||||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Drupal\domain\DomainInterface;
|
|
||||||
use Drupal\domain\DomainStorageInterface;
|
use Drupal\domain\DomainStorageInterface;
|
||||||
use Drupal\domain_access\DomainAccessManagerInterface;
|
use Drupal\domain_access\DomainAccessManagerInterface;
|
||||||
use Drupal\user\UserStorageInterface;
|
use Drupal\user\UserStorageInterface;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access plugin that provides domain-editing access control.
|
* Access plugin that provides domain-editing access control.
|
||||||
*
|
*
|
||||||
@@ -33,11 +30,15 @@ class DomainAccessContent extends AccessPluginBase implements CacheableDependenc
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the permission to use when checking access.
|
* Sets the permission to use when checking access.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $permission = 'publish to any assigned domain';
|
protected $permission = 'publish to any assigned domain';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the permission to use when checking all access.
|
* Sets the permission to use when checking all access.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $allPermission = 'publish to any domain';
|
protected $allPermission = 'publish to any domain';
|
||||||
|
|
||||||
@@ -71,11 +72,11 @@ class DomainAccessContent extends AccessPluginBase implements CacheableDependenc
|
|||||||
* The plugin_id for the plugin instance.
|
* The plugin_id for the plugin instance.
|
||||||
* @param mixed $plugin_definition
|
* @param mixed $plugin_definition
|
||||||
* The plugin implementation definition.
|
* The plugin implementation definition.
|
||||||
* @param DomainStorageInterface $domain_storage
|
* @param \Drupal\domain\DomainStorageInterface $domain_storage
|
||||||
* The domain storage service.
|
* The domain storage service.
|
||||||
* @param UserStorageInterface $user_storage
|
* @param \Drupal\user\UserStorageInterface $user_storage
|
||||||
* The user storage service.
|
* The user storage service.
|
||||||
* @param DomainAccessManagerInterface $manager
|
* @param \Drupal\domain_access\DomainAccessManagerInterface $manager
|
||||||
* The domain access manager service.
|
* The domain access manager service.
|
||||||
*/
|
*/
|
||||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, DomainStorageInterface $domain_storage, UserStorageInterface $user_storage, DomainAccessManagerInterface $manager) {
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, DomainStorageInterface $domain_storage, UserStorageInterface $user_storage, DomainAccessManagerInterface $manager) {
|
||||||
|
|||||||
+4
@@ -15,11 +15,15 @@ class DomainAccessEditor extends DomainAccessContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the permission to use when checking access.
|
* Sets the permission to use when checking access.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $permission = 'assign domain editors';
|
protected $permission = 'assign domain editors';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the permission to use when checking all access.
|
* Sets the permission to use when checking all access.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $allPermission = 'assign editors to any domain';
|
protected $allPermission = 'assign editors to any domain';
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ class DomainAccessArgument extends StringArgument {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function title() {
|
public function title() {
|
||||||
if ($domain = \Drupal::service('entity_type.manager')->getStorage('domain')->load($this->argument)) {
|
if ($domain = \Drupal::entityTypeManager()->getStorage('domain')->load($this->argument)) {
|
||||||
return $domain->label();
|
return $domain->label();
|
||||||
}
|
}
|
||||||
return parent::title();
|
return parent::title();
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ class DomainAccessField extends Field {
|
|||||||
$item['rendered']['#type'] = 'markup';
|
$item['rendered']['#type'] = 'markup';
|
||||||
$item['rendered']['#markup'] = '<a href="' . $domain->buildUrl($url) . '">' . $domain->label() . '</a>';
|
$item['rendered']['#markup'] = '<a href="' . $domain->buildUrl($url) . '">' . $domain->label() . '</a>';
|
||||||
}
|
}
|
||||||
uasort($items, array($this, 'sort'));
|
uasort($items, [$this, 'sort']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
|
|||||||
+2
-2
@@ -27,14 +27,14 @@ class DomainAccessCurrentAllFilter extends BooleanOperator {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getValueOptions() {
|
public function getValueOptions() {
|
||||||
$this->valueOptions = array(1 => $this->t('Yes'), 0 => $this->t('No'));
|
$this->valueOptions = [1 => $this->t('Yes'), 0 => $this->t('No')];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function operators() {
|
protected function operators() {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ class DomainAccessFilter extends InOperator {
|
|||||||
// @TODO: filter this list.
|
// @TODO: filter this list.
|
||||||
if (!isset($this->valueOptions)) {
|
if (!isset($this->valueOptions)) {
|
||||||
$this->valueTitle = $this->t('Domains');
|
$this->valueTitle = $this->t('Domains');
|
||||||
$this->valueOptions = \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList();
|
$this->valueOptions = \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList();
|
||||||
}
|
}
|
||||||
return $this->valueOptions;
|
return $this->valueOptions;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -11,8 +11,8 @@ dependencies:
|
|||||||
- domain_access
|
- domain_access
|
||||||
- taxonomy
|
- taxonomy
|
||||||
|
|
||||||
# Information added by Drupal.org packaging script on 2018-03-08
|
# Information added by Drupal.org packaging script on 2018-11-14
|
||||||
version: '8.x-1.0-alpha13'
|
version: '8.x-1.0-alpha14+9-dev'
|
||||||
core: '8.x'
|
core: '8.x'
|
||||||
project: 'domain'
|
project: 'domain'
|
||||||
datestamp: 1520519900
|
datestamp: 1542230887
|
||||||
|
|||||||
+6
-6
@@ -16,19 +16,19 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui');
|
public static $modules = ['domain', 'domain_access', 'field', 'field_ui'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the module installed its field correctly.
|
* Tests that the module installed its field correctly.
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessAllField() {
|
public function testDomainAccessAllField() {
|
||||||
$label = 'Send to all affiliates';
|
$label = 'Send to all affiliates';
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Visit the article field administration page.
|
// Visit the article field administration page.
|
||||||
@@ -51,14 +51,14 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
|||||||
*/
|
*/
|
||||||
public function testDomainAccessAllFieldStorage() {
|
public function testDomainAccessAllFieldStorage() {
|
||||||
$label = 'Send to all affiliates';
|
$label = 'Send to all affiliates';
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
'publish to any domain',
|
'publish to any domain',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Create 5 domains.
|
// Create 5 domains.
|
||||||
@@ -72,7 +72,7 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
|||||||
$this->assertText($label, 'Found the domain field instance.');
|
$this->assertText($label, 'Found the domain field instance.');
|
||||||
|
|
||||||
// We expect to find 5 domain options.
|
// We expect to find 5 domain options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$string = 'value="' . $domain->id() . '"';
|
$string = 'value="' . $domain->id() . '"';
|
||||||
$this->assertRaw($string, 'Found the domain option.');
|
$this->assertRaw($string, 'Found the domain option.');
|
||||||
|
|||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\domain_access\Functional;
|
||||||
|
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior for getting all URLs for an entity.
|
||||||
|
*
|
||||||
|
* @group domain_access
|
||||||
|
*/
|
||||||
|
class DomainAccessContentUrlsTest extends DomainTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = ['domain', 'domain_access', 'field', 'node', 'user'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
// Create 4 domains.
|
||||||
|
DomainTestBase::domainCreateTestDomains(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests domain source URLs.
|
||||||
|
*/
|
||||||
|
public function testDomainContentUrls() {
|
||||||
|
// Create a node, assigned to a source domain.
|
||||||
|
$id = 'one_example_com';
|
||||||
|
|
||||||
|
$nodes_values = [
|
||||||
|
'type' => 'page',
|
||||||
|
'title' => 'foo',
|
||||||
|
DOMAIN_ACCESS_FIELD => [
|
||||||
|
'example_com',
|
||||||
|
'one_example_com',
|
||||||
|
'two_example_com',
|
||||||
|
],
|
||||||
|
DOMAIN_ACCESS_ALL_FIELD => 0,
|
||||||
|
];
|
||||||
|
$node = $this->createNode($nodes_values);
|
||||||
|
|
||||||
|
// Variables for our tests.
|
||||||
|
$path = 'node/1';
|
||||||
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
|
$route_name = 'entity.node.canonical';
|
||||||
|
$route_parameters = ['node' => 1];
|
||||||
|
$uri = 'entity:' . $path;
|
||||||
|
$uri_path = '/' . $path;
|
||||||
|
$expected = $uri_path;
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
// Get the link using Url::fromRoute().
|
||||||
|
$url = URL::fromRoute($route_name, $route_parameters, $options)->toString();
|
||||||
|
$this->assertTrue($url == $expected, 'fromRoute');
|
||||||
|
|
||||||
|
// Get the link using Url::fromUserInput()
|
||||||
|
$url = URL::fromUserInput($uri_path, $options)->toString();
|
||||||
|
$this->assertTrue($url == $expected, 'fromUserInput');
|
||||||
|
|
||||||
|
// Get the link using Url::fromUri()
|
||||||
|
$url = URL::fromUri($uri, $options)->toString();
|
||||||
|
$this->assertTrue($url == $expected, 'fromUri');
|
||||||
|
|
||||||
|
// Get the path processor service.
|
||||||
|
$paths = \Drupal::service('domain_access.manager');
|
||||||
|
$urls = $paths->getContentUrls($node);
|
||||||
|
$expected = [
|
||||||
|
'example_com' => $domains['example_com']->getPath() . 'node/1',
|
||||||
|
$id => $domains[$id]->getPath() . 'node/1',
|
||||||
|
'two_example_com' => $domains['two_example_com']->getPath() . 'node/1',
|
||||||
|
];
|
||||||
|
$this->assertTrue($expected == $urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
-5
@@ -18,20 +18,20 @@ class DomainAccessDefaultValueTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui');
|
public static $modules = ['domain', 'domain_access', 'field', 'field_ui'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the usage of DomainAccessManager::getDefaultValue().
|
* Test the usage of DomainAccessManager::getDefaultValue().
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessDefaultValue() {
|
public function testDomainAccessDefaultValue() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
'publish to any domain',
|
'publish to any domain',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Create 5 domains.
|
// Create 5 domains.
|
||||||
@@ -68,10 +68,10 @@ class DomainAccessDefaultValueTest extends DomainTestBase {
|
|||||||
$this->drupalLogout();
|
$this->drupalLogout();
|
||||||
|
|
||||||
// Create a limited value user.
|
// Create a limited value user.
|
||||||
$this->test_user = $this->drupalCreateUser(array(
|
$this->test_user = $this->drupalCreateUser([
|
||||||
'create article content',
|
'create article content',
|
||||||
'edit any article content',
|
'edit any article content',
|
||||||
));
|
]);
|
||||||
|
|
||||||
// Login and try to edit the created node.
|
// Login and try to edit the created node.
|
||||||
$this->drupalLogin($this->test_user);
|
$this->drupalLogin($this->test_user);
|
||||||
|
|||||||
+31
-10
@@ -16,7 +16,13 @@ class DomainAccessElementTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
public static $modules = [
|
||||||
|
'domain',
|
||||||
|
'domain_access',
|
||||||
|
'field',
|
||||||
|
'field_ui',
|
||||||
|
'user',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -29,27 +35,36 @@ class DomainAccessElementTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic test setup.
|
* Test runner.
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessElement() {
|
public function testDomainAccessElement() {
|
||||||
$admin = $this->drupalCreateUser(array(
|
$this->runInstalledTest('article');
|
||||||
|
$node_type = $this->createContentType(['type' => 'test']);
|
||||||
|
$this->runInstalledTest('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic test setup.
|
||||||
|
*/
|
||||||
|
public function runInstalledTest($node_type) {
|
||||||
|
$admin = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
'publish to any domain',
|
'publish to any domain',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($admin);
|
$this->drupalLogin($admin);
|
||||||
|
|
||||||
$this->drupalGet('node/add/article');
|
$this->drupalGet('node/add/' . $node_type);
|
||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Set the title, so the node can be saved.
|
// Set the title, so the node can be saved.
|
||||||
$this->fillField('title[0][value]', 'Test node');
|
$this->fillField('title[0][value]', 'Test node');
|
||||||
|
|
||||||
// We expect to find 5 domain options. We set two as selected.
|
// We expect to find 5 domain options. We set two as selected.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
@@ -70,8 +85,10 @@ class DomainAccessElementTest extends DomainTestBase {
|
|||||||
$this->pressButton('edit-submit');
|
$this->pressButton('edit-submit');
|
||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
|
// Get node data. Note that we create one new node for each test case.
|
||||||
$storage = \Drupal::entityTypeManager()->getStorage('node');
|
$storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||||
$node = $storage->load(1);
|
$nid = $node_type == 'article' ? 1 : 2;
|
||||||
|
$node = $storage->load($nid);
|
||||||
// Check that two values are set.
|
// Check that two values are set.
|
||||||
$manager = \Drupal::service('domain_access.manager');
|
$manager = \Drupal::service('domain_access.manager');
|
||||||
$values = $manager->getAccessValues($node);
|
$values = $manager->getAccessValues($node);
|
||||||
@@ -80,7 +97,11 @@ class DomainAccessElementTest extends DomainTestBase {
|
|||||||
$this->assert($value == 1, 'Node saved to all affiliates.');
|
$this->assert($value == 1, 'Node saved to all affiliates.');
|
||||||
|
|
||||||
// Now login as a user with limited rights.
|
// Now login as a user with limited rights.
|
||||||
$account = $this->drupalCreateUser(array('create article content', 'edit any article content', 'publish to any assigned domain'));
|
$account = $this->drupalCreateUser([
|
||||||
|
'create ' . $node_type . ' content',
|
||||||
|
'edit any ' . $node_type . ' content',
|
||||||
|
'publish to any assigned domain',
|
||||||
|
]);
|
||||||
$ids = ['example_com', 'one_example_com'];
|
$ids = ['example_com', 'one_example_com'];
|
||||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ACCESS_FIELD);
|
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ACCESS_FIELD);
|
||||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||||
@@ -118,8 +139,8 @@ class DomainAccessElementTest extends DomainTestBase {
|
|||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Now, check the node.
|
// Now, check the node.
|
||||||
$storage->resetCache(array($node->id()));
|
$storage->resetCache([$node->id()]);
|
||||||
$node = $storage->load(1);
|
$node = $storage->load($node->id());
|
||||||
// Check that two values are set.
|
// Check that two values are set.
|
||||||
$values = $manager->getAccessValues($node);
|
$values = $manager->getAccessValues($node);
|
||||||
$this->assert(count($values) == 2, 'Node saved with two domain records.');
|
$this->assert(count($values) == 2, 'Node saved with two domain records.');
|
||||||
|
|||||||
+13
-5
@@ -17,7 +17,15 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'domain_access_test', 'field', 'field_ui', 'user', 'taxonomy');
|
public static $modules = [
|
||||||
|
'domain',
|
||||||
|
'domain_access',
|
||||||
|
'domain_access_test',
|
||||||
|
'field',
|
||||||
|
'field_ui',
|
||||||
|
'user',
|
||||||
|
'taxonomy',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -35,13 +43,13 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
|||||||
public function testDomainAccessEntityFields() {
|
public function testDomainAccessEntityFields() {
|
||||||
$label = 'Send to all affiliates';
|
$label = 'Send to all affiliates';
|
||||||
// Create a vocabulary.
|
// Create a vocabulary.
|
||||||
$vocabulary = entity_create('taxonomy_vocabulary', array(
|
$vocabulary = entity_create('taxonomy_vocabulary', [
|
||||||
'name' => 'Domain vocabulary',
|
'name' => 'Domain vocabulary',
|
||||||
'description' => 'Test taxonomy for Domain Access',
|
'description' => 'Test taxonomy for Domain Access',
|
||||||
'vid' => 'domain_access',
|
'vid' => 'domain_access',
|
||||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||||
'weight' => 100,
|
'weight' => 100,
|
||||||
));
|
]);
|
||||||
$vocabulary->save();
|
$vocabulary->save();
|
||||||
$text['taxonomy_term'] = [
|
$text['taxonomy_term'] = [
|
||||||
'name' => 'term',
|
'name' => 'term',
|
||||||
@@ -49,7 +57,7 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
|||||||
'description' => 'Make this term available on all domains.',
|
'description' => 'Make this term available on all domains.',
|
||||||
];
|
];
|
||||||
domain_access_confirm_fields('taxonomy_term', 'domain_access', $text);
|
domain_access_confirm_fields('taxonomy_term', 'domain_access', $text);
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
@@ -59,7 +67,7 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
|||||||
'administer taxonomy',
|
'administer taxonomy',
|
||||||
'administer taxonomy_term fields',
|
'administer taxonomy_term fields',
|
||||||
'administer taxonomy_term form display',
|
'administer taxonomy_term form display',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
$this->drupalGet('admin/structure/taxonomy/manage/domain_access/overview/fields');
|
$this->drupalGet('admin/structure/taxonomy/manage/domain_access/overview/fields');
|
||||||
$this->assertResponse(200, 'Manage fields page accessed.');
|
$this->assertResponse(200, 'Manage fields page accessed.');
|
||||||
|
|||||||
+6
-6
@@ -16,18 +16,18 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui');
|
public static $modules = ['domain', 'domain_access', 'field', 'field_ui'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the module installed its field correctly.
|
* Tests that the module installed its field correctly.
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessNodeField() {
|
public function testDomainAccessNodeField() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Visit the article field administration page.
|
// Visit the article field administration page.
|
||||||
@@ -49,14 +49,14 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
|||||||
* Tests the storage of the domain access field.
|
* Tests the storage of the domain access field.
|
||||||
*/
|
*/
|
||||||
public function testDomainAccessFieldStorage() {
|
public function testDomainAccessFieldStorage() {
|
||||||
$this->admin_user = $this->drupalCreateUser(array(
|
$this->admin_user = $this->drupalCreateUser([
|
||||||
'bypass node access',
|
'bypass node access',
|
||||||
'administer content types',
|
'administer content types',
|
||||||
'administer node fields',
|
'administer node fields',
|
||||||
'administer node display',
|
'administer node display',
|
||||||
'administer domains',
|
'administer domains',
|
||||||
'publish to any domain',
|
'publish to any domain',
|
||||||
));
|
]);
|
||||||
$this->drupalLogin($this->admin_user);
|
$this->drupalLogin($this->admin_user);
|
||||||
|
|
||||||
// Create 5 domains.
|
// Create 5 domains.
|
||||||
@@ -70,7 +70,7 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
|||||||
$this->assertText('Domain Access', 'Found the domain field instance.');
|
$this->assertText('Domain Access', 'Found the domain field instance.');
|
||||||
|
|
||||||
// We expect to find 5 domain options.
|
// We expect to find 5 domain options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$string = 'value="' . $domain->id() . '"';
|
$string = 'value="' . $domain->id() . '"';
|
||||||
$this->assertRaw($string, 'Found the domain option.');
|
$this->assertRaw($string, 'Found the domain option.');
|
||||||
|
|||||||
+18
-12
@@ -17,7 +17,13 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
public static $modules = [
|
||||||
|
'domain',
|
||||||
|
'domain_access',
|
||||||
|
'field',
|
||||||
|
'field_ui',
|
||||||
|
'user',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -44,7 +50,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
$this->assertResponse(200, 'Article creation found.');
|
$this->assertResponse(200, 'Article creation found.');
|
||||||
|
|
||||||
// Check for the form options.
|
// Check for the form options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$this->assertText($domain->label(), 'Domain form item found.');
|
$this->assertText($domain->label(), 'Domain form item found.');
|
||||||
}
|
}
|
||||||
@@ -72,7 +78,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
$this->assertNoText($label, 'All affiliates field not found.');
|
$this->assertNoText($label, 'All affiliates field not found.');
|
||||||
|
|
||||||
// Test a user who can access no domain settings.
|
// Test a user who can access no domain settings.
|
||||||
$user3 = $this->drupalCreateUser(array('create article content'));
|
$user3 = $this->drupalCreateUser(['create article content']);
|
||||||
$this->drupalLogin($user3);
|
$this->drupalLogin($user3);
|
||||||
|
|
||||||
// Visit the article creation page.
|
// Visit the article creation page.
|
||||||
@@ -89,7 +95,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
// The domain/domain affiliates fields are not accessible to this user.
|
// The domain/domain affiliates fields are not accessible to this user.
|
||||||
// The save will fail with an EntityStorageException until
|
// The save will fail with an EntityStorageException until
|
||||||
// https://www.drupal.org/node/2609252 is fixed.
|
// https://www.drupal.org/node/2609252 is fixed.
|
||||||
$edit = array();
|
$edit = [];
|
||||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||||
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
||||||
@@ -99,7 +105,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
$this->assertTrue($node, 'Node found in database.');
|
$this->assertTrue($node, 'Node found in database.');
|
||||||
|
|
||||||
// Test a user who can assign users to domains.
|
// Test a user who can assign users to domains.
|
||||||
$user4 = $this->drupalCreateUser(array('administer users', 'assign editors to any domain'));
|
$user4 = $this->drupalCreateUser(['administer users', 'assign editors to any domain']);
|
||||||
$this->drupalLogin($user4);
|
$this->drupalLogin($user4);
|
||||||
|
|
||||||
// Visit the account creation page.
|
// Visit the account creation page.
|
||||||
@@ -112,7 +118,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test a user who can assign users to some domains.
|
// Test a user who can assign users to some domains.
|
||||||
$user5 = $this->drupalCreateUser(array('administer users', 'assign domain editors'));
|
$user5 = $this->drupalCreateUser(['administer users', 'assign domain editors']);
|
||||||
$active_domain = array_rand($domains, 1);
|
$active_domain = array_rand($domains, 1);
|
||||||
$this->addDomainsToEntity('user', $user5->id(), $active_domain, DOMAIN_ACCESS_FIELD);
|
$this->addDomainsToEntity('user', $user5->id(), $active_domain, DOMAIN_ACCESS_FIELD);
|
||||||
$this->drupalLogin($user5);
|
$this->drupalLogin($user5);
|
||||||
@@ -132,7 +138,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test a user who can access no domain settings.
|
// Test a user who can access no domain settings.
|
||||||
$user6 = $this->drupalCreateUser(array('administer users'));
|
$user6 = $this->drupalCreateUser(['administer users']);
|
||||||
$this->drupalLogin($user6);
|
$this->drupalLogin($user6);
|
||||||
|
|
||||||
// Visit the account creation page.
|
// Visit the account creation page.
|
||||||
@@ -145,7 +151,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test a user who can access all domain settings.
|
// Test a user who can access all domain settings.
|
||||||
$user7 = $this->drupalCreateUser(array('bypass node access', 'publish to any domain'));
|
$user7 = $this->drupalCreateUser(['bypass node access', 'publish to any domain']);
|
||||||
$this->drupalLogin($user7);
|
$this->drupalLogin($user7);
|
||||||
|
|
||||||
// Create a new content type and test that the fields are created.
|
// Create a new content type and test that the fields are created.
|
||||||
@@ -162,20 +168,20 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
$this->assertResponse(200, $type->id() . ' creation found.');
|
$this->assertResponse(200, $type->id() . ' creation found.');
|
||||||
|
|
||||||
// Check for the form options.
|
// Check for the form options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$this->assertText($domain->label(), 'Domain form item found.');
|
$this->assertText($domain->label(), 'Domain form item found.');
|
||||||
}
|
}
|
||||||
$this->assertText($label, 'All affiliates field found.');
|
$this->assertText($label, 'All affiliates field found.');
|
||||||
|
|
||||||
// Test user without access to affiliates field editing their user page.
|
// Test user without access to affiliates field editing their user page.
|
||||||
$user8 = $this->drupalCreateUser(array('change own username'));
|
$user8 = $this->drupalCreateUser(['change own username']);
|
||||||
$this->drupalLogin($user8);
|
$this->drupalLogin($user8);
|
||||||
|
|
||||||
$user_edit_page = 'user/' . $user8->id() . '/edit';
|
$user_edit_page = 'user/' . $user8->id() . '/edit';
|
||||||
$this->drupalGet($user_edit_page);
|
$this->drupalGet($user_edit_page);
|
||||||
// Check for the form options.
|
// Check for the form options.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$this->assertNoText($domain->label(), 'Domain form item not found.');
|
$this->assertNoText($domain->label(), 'Domain form item not found.');
|
||||||
}
|
}
|
||||||
@@ -183,7 +189,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
|||||||
$this->assertNoText($label, 'All affiliates field not found.');
|
$this->assertNoText($label, 'All affiliates field not found.');
|
||||||
|
|
||||||
// Change own username.
|
// Change own username.
|
||||||
$edit = array();
|
$edit = [];
|
||||||
$edit['name'] = $this->randomMachineName();
|
$edit['name'] = $this->randomMachineName();
|
||||||
|
|
||||||
$this->drupalPostForm($user_edit_page, $edit, t('Save'));
|
$this->drupalPostForm($user_edit_page, $edit, t('Save'));
|
||||||
|
|||||||
+9
-9
@@ -15,7 +15,7 @@ class DomainAccessGrantsTest extends DomainTestBase {
|
|||||||
/**
|
/**
|
||||||
* The Entity access handler.
|
* The Entity access handler.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface $accessHandler
|
* @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface
|
||||||
*/
|
*/
|
||||||
protected $accessHandler;
|
protected $accessHandler;
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ class DomainAccessGrantsTest extends DomainTestBase {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('domain', 'domain_access', 'field', 'node');
|
public static $modules = ['domain', 'domain_access', 'field', 'node'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -45,14 +45,14 @@ class DomainAccessGrantsTest extends DomainTestBase {
|
|||||||
// Create 5 domains.
|
// Create 5 domains.
|
||||||
$this->domainCreateTestDomains(5);
|
$this->domainCreateTestDomains(5);
|
||||||
// Assign a node to a random domain.
|
// Assign a node to a random domain.
|
||||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||||
$active_domain = array_rand($domains, 1);
|
$active_domain = array_rand($domains, 1);
|
||||||
$domain = $domains[$active_domain];
|
$domain = $domains[$active_domain];
|
||||||
// Create an article node.
|
// Create an article node.
|
||||||
$node1 = $this->drupalCreateNode(array(
|
$node1 = $this->drupalCreateNode([
|
||||||
'type' => 'article',
|
'type' => 'article',
|
||||||
DOMAIN_ACCESS_FIELD => array($domain->id()),
|
DOMAIN_ACCESS_FIELD => [$domain->id()],
|
||||||
));
|
]);
|
||||||
$this->assertTrue($node_storage->load($node1->id()), 'Article node created.');
|
$this->assertTrue($node_storage->load($node1->id()), 'Article node created.');
|
||||||
|
|
||||||
// Test the response of the node on each site. Should allow access only to
|
// Test the response of the node on each site. Should allow access only to
|
||||||
@@ -70,11 +70,11 @@ class DomainAccessGrantsTest extends DomainTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create an article node.
|
// Create an article node.
|
||||||
$node2 = $this->drupalCreateNode(array(
|
$node2 = $this->drupalCreateNode([
|
||||||
'type' => 'article',
|
'type' => 'article',
|
||||||
DOMAIN_ACCESS_FIELD => array($domain->id()),
|
DOMAIN_ACCESS_FIELD => [$domain->id()],
|
||||||
DOMAIN_ACCESS_ALL_FIELD => 1,
|
DOMAIN_ACCESS_ALL_FIELD => 1,
|
||||||
));
|
]);
|
||||||
$this->assertTrue($node_storage->load($node2->id()), 'Article node created.');
|
$this->assertTrue($node_storage->load($node2->id()), 'Article node created.');
|
||||||
// Test the response of the node on each site. Should allow access on all.
|
// Test the response of the node on each site. Should allow access on all.
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user