added domain_menu_access, updated domain to last dev
This commit is contained in:
@@ -4,22 +4,22 @@ sudo: false
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- env: DRUPAL=8.4.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
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 5.5
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 7.1
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 7.0
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 5.6
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 7.1
|
||||
- env: DRUPAL=8.5.x
|
||||
php: 7.2
|
||||
- env: DRUPAL=8.6.x
|
||||
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:
|
||||
hosts:
|
||||
@@ -76,6 +76,9 @@ before_script:
|
||||
- travis_retry drush dl drupal-$DRUPAL --drupal-project-rename=drupal
|
||||
- cd drupal
|
||||
|
||||
# Update PHPUnit.
|
||||
- composer run-script drupal-phpunit-upgrade
|
||||
|
||||
# Make the module appear in the correct place
|
||||
- ln -s $TESTDIR modules/domain
|
||||
|
||||
@@ -91,11 +94,11 @@ before_script:
|
||||
- until curl -s example.com:8080; do true; done > /dev/null
|
||||
|
||||
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 --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 --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 --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 --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
|
||||
- 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 --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 --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 --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 --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 --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 --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
|
||||
19-DEC-2017 8.x-1.0-alpha11
|
||||
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
|
||||
====
|
||||
@@ -118,7 +119,6 @@ marked with [x] are considered complete.
|
||||
- [ ] Caching strategies in DomainNegotiator
|
||||
- [ ] Caching strategies in DomainConfigOverrides
|
||||
- [ ] Cache in the DomainAccessManager
|
||||
- [ ] Add filter options to domain_access and domain_source views
|
||||
- [ ] Proper handling of default node values
|
||||
- [ ] Do not allow actions to be edited?
|
||||
- [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.
|
||||
|
||||
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 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
|
||||
environments. See the README file for Domain Alias for more information.
|
||||
|
||||
* *Domain Alpha*
|
||||
Provides limited alpha-to-alpha updates. Recommended.
|
||||
|
||||
* *Domain Config*
|
||||
Provides a means for changing configuration settings on a per-domain basis. See the
|
||||
README for Domain Config for more information.
|
||||
@@ -54,17 +53,6 @@ Included modules
|
||||
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
|
||||
======
|
||||
|
||||
@@ -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.
|
||||
|
||||
If anyone is capable of building a vagrant box to simplify testing, that would be ideal.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
allow_non_ascii: false
|
||||
www_prefix: false
|
||||
login_paths: '/user/login\r\n/user/password'
|
||||
login_paths: "/user/login\r\n/user/password"
|
||||
css_classes: ''
|
||||
|
||||
@@ -83,3 +83,13 @@ condition.plugin.domain:
|
||||
sequence:
|
||||
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;
|
||||
*
|
||||
* @param array $domains
|
||||
* @param \Drupal\domain\DomainInterface[] $domains
|
||||
* An array of $domain record objects.
|
||||
*/
|
||||
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')) {
|
||||
// Add aliases to the list.
|
||||
$id = $domain->id();
|
||||
$operations['domain_alias'] = array(
|
||||
$operations['domain_alias'] = [
|
||||
'title' => t('Aliases'),
|
||||
'url' => Url::fromRoute('domain_alias.admin', array('domain' => $id)),
|
||||
'url' => \Drupal\Core\Url::fromRoute('domain_alias.admin', ['domain' => $id]),
|
||||
'weight' => 60,
|
||||
);
|
||||
];
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
@@ -88,6 +88,9 @@ function hook_domain_operations(\Drupal\domain\DomainInterface $domain, \Drupal\
|
||||
*
|
||||
* 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
|
||||
* The list of current validation errors. Modify this value by reference.
|
||||
* 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
|
||||
* modifiable.
|
||||
*
|
||||
* No return value. Modify $error_list by reference. Return an empty array
|
||||
* or NULL to validate this 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.
|
||||
if (substr($hostname, -4) != '.org') {
|
||||
$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'
|
||||
* permission.
|
||||
*
|
||||
* No return value. Modify the $query object via methods.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryInterface $query
|
||||
* An entity query prepared by DomainSelection::buildEntityQuery().
|
||||
* @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)
|
||||
* 'admin' for assigning administrative permissions for a specific domain.
|
||||
* 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.
|
||||
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, '<>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,146 +13,146 @@ use GuzzleHttp\Exception\RequestException;
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function domain_drush_command() {
|
||||
$items = array();
|
||||
$items = [];
|
||||
|
||||
$items['domain-list'] = array(
|
||||
$items['domain-list'] = [
|
||||
'description' => 'List active domains for the site.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-list',
|
||||
'drush domains',
|
||||
),
|
||||
'aliases' => array('domains'),
|
||||
);
|
||||
$items['domain-add'] = array(
|
||||
],
|
||||
'aliases' => ['domains'],
|
||||
];
|
||||
$items['domain-add'] = [
|
||||
'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\' --inactive=1 --https==1',
|
||||
'drush domain-add example.com \'My Test Site\' --weight=10',
|
||||
'drush domain-add example.com \'My Test Site\' --validate=1',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'hostname' => 'The domain hostname to register (e.g. example.com).',
|
||||
'name' => 'The name of the site (e.g. Domain Two).',
|
||||
),
|
||||
'options' => array(
|
||||
],
|
||||
'options' => [
|
||||
'inactive' => 'Set the domain to inactive status if set.',
|
||||
'https' => 'Use https protocol for this domain if set.',
|
||||
'weight' => 'Set the order (weight) of the domain.',
|
||||
'is_default' => 'Set this domain as the default domain.',
|
||||
'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.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-delete example.com',
|
||||
'drush domain-delete 1',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'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.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-test',
|
||||
'drush domain-test example.com',
|
||||
'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.',
|
||||
),
|
||||
'options' => array(
|
||||
],
|
||||
'options' => [
|
||||
'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.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-default example.com',
|
||||
'drush domain-default 1',
|
||||
'drush domain-default 1 --validate=1',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'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.',
|
||||
),
|
||||
);
|
||||
$items['domain-disable'] = array(
|
||||
],
|
||||
];
|
||||
$items['domain-disable'] = [
|
||||
'description' => 'Sets a domain status to off.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-disable example.com',
|
||||
'drush domain-disable 1',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'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.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-disable example.com',
|
||||
'drush domain-disable 1',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'domain_id' => 'The numeric id or hostname of the domain to enable.',
|
||||
),
|
||||
);
|
||||
$items['domain-name'] = array(
|
||||
],
|
||||
];
|
||||
$items['domain-name'] = [
|
||||
'description' => 'Changes a domain label.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-name example.com Foo',
|
||||
'drush domain-name 1 Foo',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'domain_id' => 'The numeric id or hostname of the domain to relabel.',
|
||||
'name' => 'The name to use for the domain.',
|
||||
),
|
||||
);
|
||||
$items['domain-machine-name'] = array(
|
||||
],
|
||||
];
|
||||
$items['domain-machine-name'] = [
|
||||
'description' => 'Changes a domain name.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-machine-name example.com foo',
|
||||
'drush domain-machine-name 1 foo',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'domain_id' => 'The numeric id or hostname of the domain to rename.',
|
||||
'name' => 'The machine-readable name to use for the domain.',
|
||||
),
|
||||
);
|
||||
$items['domain-scheme'] = array(
|
||||
],
|
||||
];
|
||||
$items['domain-scheme'] = [
|
||||
'description' => 'Changes a domain scheme.',
|
||||
'examples' => array(
|
||||
'examples' => [
|
||||
'drush domain-scheme example.com https',
|
||||
'drush domain-scheme 1 https',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'domain_id' => 'The numeric id or hostname of the domain to change.',
|
||||
'scheme' => 'The URL schema (http or https) to use for the domain.',
|
||||
),
|
||||
);
|
||||
$items['generate-domains'] = array(
|
||||
],
|
||||
];
|
||||
$items['generate-domains'] = [
|
||||
'description' => 'Generate domains for testing.',
|
||||
'arguments' => array(
|
||||
'arguments' => [
|
||||
'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.',
|
||||
'empty' => 'Pass empty=1 to truncate the {domain} table before creating records.'
|
||||
),
|
||||
'examples' => array(
|
||||
'empty' => 'Pass empty=1 to truncate the {domain} table before creating records.',
|
||||
],
|
||||
'examples' => [
|
||||
'drush domain-generate example.com',
|
||||
'drush domain-generate example.com --count=25',
|
||||
'drush domain-generate example.com --count=25 --empty=1',
|
||||
'drush gend',
|
||||
'drush gend --count=25',
|
||||
'drush gend --count=25 --empty=1',
|
||||
),
|
||||
'aliases' => array('gend'),
|
||||
);
|
||||
],
|
||||
'aliases' => ['gend'],
|
||||
];
|
||||
return $items;
|
||||
}
|
||||
|
||||
@@ -171,14 +171,14 @@ function domain_drush_help($section) {
|
||||
* Shows the 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)) {
|
||||
drush_print(dt('No domains have been created. Use drush domain-add to create one.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$header = array(
|
||||
$header = [
|
||||
'weight' => dt('Weight'),
|
||||
'name' => dt('Name'),
|
||||
'hostname' => dt('Hostname'),
|
||||
@@ -187,10 +187,10 @@ function drush_domain_list() {
|
||||
'is_default' => dt('Default'),
|
||||
'domain_id' => dt('Domain Id'),
|
||||
'id' => dt('Machine name'),
|
||||
);
|
||||
$rows = array(array_values($header));
|
||||
];
|
||||
$rows = [array_values($header)];
|
||||
foreach ($domains as $domain) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
foreach ($header as $key => $name) {
|
||||
$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
|
||||
* large number of domains. This test is mostly for UI testing.
|
||||
*
|
||||
* @param $primary
|
||||
* @param string $primary
|
||||
* The root domain to use for domain creation.
|
||||
*
|
||||
* @return
|
||||
* A list of the domains created.
|
||||
*/
|
||||
function drush_domain_generate_domains($primary = 'example.com') {
|
||||
// Check the number of domains to create.
|
||||
$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)) {
|
||||
$count = 15;
|
||||
}
|
||||
// Ensure we don't duplicate any domains.
|
||||
$existing = array();
|
||||
$existing = [];
|
||||
if (!empty($domains)) {
|
||||
foreach ($domains as $domain) {
|
||||
$existing[] = $domain->getHostname();
|
||||
}
|
||||
}
|
||||
// Set up one.* and so on.
|
||||
$names = array(
|
||||
$names = [
|
||||
'one',
|
||||
'two',
|
||||
'three',
|
||||
@@ -245,23 +242,23 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
||||
'foo',
|
||||
'bar',
|
||||
'baz',
|
||||
);
|
||||
];
|
||||
// Set the creation array.
|
||||
$new = array($primary);
|
||||
$new = [$primary];
|
||||
foreach ($names as $name) {
|
||||
$new[] = $name . '.' . $primary;
|
||||
}
|
||||
// Include a non hostname.
|
||||
$new[] = 'my' . $primary;
|
||||
// Filter against existing so we can count correctly.
|
||||
$prepared = array();
|
||||
$prepared = [];
|
||||
foreach ($new as $key => $value) {
|
||||
if (!in_array($value, $existing)) {
|
||||
$prepared[] = $value;
|
||||
}
|
||||
}
|
||||
// Add any test domains that have numeric prefixes. We don't expect these URLs to work,
|
||||
// and mainly use these for testing the user interface.
|
||||
// Add any test domains that have numeric prefixes. We don't expect these URLs
|
||||
// to work, and mainly use these for testing the user interface.
|
||||
$needed = $count - count($prepared);
|
||||
for ($i = 1; $i <= $needed; $i++) {
|
||||
$prepared[] = 'test' . $i . '.' . $primary;
|
||||
@@ -273,17 +270,17 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
||||
|
||||
// Create the domains.
|
||||
foreach ($prepared as $key => $item) {
|
||||
$hostname = strtolower($item);
|
||||
$values = array(
|
||||
$hostname = mb_strtolower($item);
|
||||
$values = [
|
||||
'name' => ($item != $primary) ? ucwords(str_replace(".$primary", '', $item)) : \Drupal::config('system.site')->get('name'),
|
||||
'hostname' => $hostname,
|
||||
'scheme' => 'http',
|
||||
'status' => 1,
|
||||
'weight' => ($item != $primary) ? $key + $start_weight + 1 : -1,
|
||||
'is_default' => 0,
|
||||
'id' => \Drupal::service('entity_type.manager')->getStorage('domain')->createMachineName($hostname),
|
||||
);
|
||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create($values);
|
||||
'id' => \Drupal::entityTypeManager()->getStorage('domain')->createMachineName($hostname),
|
||||
];
|
||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||
domain_drush_create($domain);
|
||||
}
|
||||
|
||||
@@ -296,7 +293,7 @@ function drush_domain_generate_domains($primary = 'example.com') {
|
||||
/**
|
||||
* Validates the domain generation script.
|
||||
*
|
||||
* @param $primary
|
||||
* @param string $primary
|
||||
* The root domain to use for domain creation.
|
||||
*/
|
||||
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}");
|
||||
}
|
||||
return;
|
||||
// TODO: Update this validation.
|
||||
$error = domain_valid_domain($primary);
|
||||
if (!empty($error)) {
|
||||
return drush_set_error('domain', $error);
|
||||
}
|
||||
// TODO: Add validation.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,10 +315,10 @@ function drush_domain_generate_domains_validate($primary = 'example.com') {
|
||||
function drush_domain_add($hostname, $name) {
|
||||
$records_count = \Drupal::entityTypeManager()->getStorage('domain')->getQuery()->count()->execute();
|
||||
$start_weight = $records_count + 1;
|
||||
$hostname = strtolower($hostname);
|
||||
$hostname = mb_strtolower($hostname);
|
||||
/** @var \Drupal\domain\DomainStorageInterface $domain_storage */
|
||||
$domain_storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$values = array(
|
||||
$domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
$values = [
|
||||
'hostname' => $hostname,
|
||||
'name' => $name,
|
||||
'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,
|
||||
'id' => $domain_storage->createMachineName($hostname),
|
||||
'validate_url' => (drush_get_option('validate')) ? 1 : 0,
|
||||
);
|
||||
];
|
||||
$domain = $domain_storage->create($values);
|
||||
domain_drush_create($domain);
|
||||
}
|
||||
@@ -355,7 +348,7 @@ function drush_domain_add_validate($hostname, $name) {
|
||||
if (!empty($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 TRUE;
|
||||
@@ -374,7 +367,7 @@ function domain_drush_create(DomainInterface $domain) {
|
||||
else {
|
||||
$domain->save();
|
||||
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 {
|
||||
drush_print(dt('The request could not be completed.'));
|
||||
@@ -417,7 +410,7 @@ function domain_drush_check_response(DomainInterface $domain) {
|
||||
/**
|
||||
* Validates a domain.
|
||||
*
|
||||
* @param $hostname
|
||||
* @param string $hostname
|
||||
* The domain name to validate for syntax and uniqueness.
|
||||
*
|
||||
* @return array
|
||||
@@ -434,7 +427,7 @@ function domain_drush_validate_domain($hostname) {
|
||||
/**
|
||||
* Deletes a domain record.
|
||||
*
|
||||
* @param $argument
|
||||
* @param string $argument
|
||||
* The domain_id to delete. Pass 'all' to delete all records.
|
||||
*/
|
||||
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.'));
|
||||
}
|
||||
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)) {
|
||||
drush_print(dt('There are no domains to delete.'));
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@@ -464,14 +457,14 @@ function drush_domain_delete($argument = NULL) {
|
||||
}
|
||||
foreach ($domains as $domain) {
|
||||
$domain->delete();
|
||||
drush_print(dt('Domain record @domain deleted.', array('@domain' => $domain->getHostname())));
|
||||
drush_print(dt('Domain record @domain deleted.', ['@domain' => $domain->getHostname()]));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// TODO: Set options for re-assigning content.
|
||||
$list = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
$options = array('0' => dt('Do not reassign'));
|
||||
$list = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
$options = ['0' => dt('Do not reassign')];
|
||||
foreach ($list as $data) {
|
||||
if ($data->id() != $domain->id()) {
|
||||
$options[$data->getDomainId()] = $data->getHostname();
|
||||
@@ -496,7 +489,7 @@ function drush_domain_delete($argument = NULL) {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
function drush_domain_test($argument = NULL) {
|
||||
@@ -505,11 +498,11 @@ function drush_domain_test($argument = NULL) {
|
||||
$GLOBALS['base_path'] = '/' . $base_path . '/';
|
||||
}
|
||||
if (is_null($argument)) {
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
}
|
||||
else {
|
||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||
$domains = array($domain);
|
||||
$domains = [$domain];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
@@ -517,10 +510,10 @@ function drush_domain_test($argument = NULL) {
|
||||
}
|
||||
foreach ($domains as $domain) {
|
||||
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 {
|
||||
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 {
|
||||
$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->status()) {
|
||||
$domain->disable();
|
||||
drush_print(dt('!domain has been disabled.', array('!domain' => $domain->getHostname())));
|
||||
drush_print(dt('!domain has been disabled.', ['!domain' => $domain->getHostname()]));
|
||||
}
|
||||
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->status()) {
|
||||
$domain->enable();
|
||||
drush_print(dt('!domain has been enabled.', array('!domain' => $domain->getHostname())));
|
||||
drush_print(dt('!domain has been enabled.', ['!domain' => $domain->getHostname()]));
|
||||
}
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
if ($domain = drush_domain_get_from_argument($argument)) {
|
||||
$results = \Drupal::entityTypeManager()
|
||||
->getStorage('domain')
|
||||
->loadByProperties(array('machine_name' => $machine_name));
|
||||
->loadByProperties(['machine_name' => $machine_name]);
|
||||
foreach ($results as $result) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -611,7 +604,7 @@ function drush_domain_machine_name($argument, $machine_name) {
|
||||
function drush_domain_scheme($argument) {
|
||||
// Resolve the domain.
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@@ -629,9 +622,9 @@ function drush_domain_scheme($argument) {
|
||||
* On failure, throws a drush error.
|
||||
*/
|
||||
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) {
|
||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->loadByHostname($argument);
|
||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->loadByHostname($argument);
|
||||
}
|
||||
if (!$domain) {
|
||||
drush_set_error('domain', dt('Domain record not found.'));
|
||||
|
||||
@@ -5,11 +5,12 @@ package: Domain
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- options
|
||||
- drupal:system (>=8.5)
|
||||
- drupal:options
|
||||
configure: domain.admin
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-08
|
||||
version: '8.x-1.0-alpha13'
|
||||
# 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: 1520519900
|
||||
datestamp: 1542230887
|
||||
|
||||
@@ -31,7 +31,6 @@ function _domain_configure_field() {
|
||||
$display->setComponent(DOMAIN_ADMIN_FIELD, [
|
||||
'type' => 'options_buttons',
|
||||
'weight' => 50,
|
||||
])
|
||||
->save();
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
* Defines a Domain concept for use with Drupal.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\domain\DomainInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* The name of the node access control field.
|
||||
@@ -71,11 +71,10 @@ function domain_token_info() {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$table = 'user__' . DOMAIN_ADMIN_FIELD;
|
||||
@@ -155,8 +154,8 @@ function domain_theme() {
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - 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'];
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ class DomainAccessCheck implements AccessCheckInterface {
|
||||
/**
|
||||
* Constructs the object.
|
||||
*
|
||||
* @param DomainNegotiatorInterface $negotiator
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* The domain negotiation service.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory.
|
||||
* @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) {
|
||||
$this->domainNegotiator = $negotiator;
|
||||
@@ -71,7 +71,6 @@ class DomainAccessCheck implements AccessCheckInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
$domain = $this->domainNegotiator->getActiveDomain();
|
||||
// Is the domain allowed?
|
||||
// No domain, let it pass.
|
||||
@@ -84,7 +83,7 @@ class DomainAccessCheck implements AccessCheckInterface {
|
||||
}
|
||||
// Inactive domain, require permissions.
|
||||
else {
|
||||
$permissions = array('administer domains', 'access inactive domains');
|
||||
$permissions = ['administer domains', 'access inactive domains'];
|
||||
$operator = 'OR';
|
||||
return AccessResult::allowedIfHasPermissions($account, $permissions, $operator)->setCacheMaxAge(0);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class DomainListCheck {
|
||||
* The account making the route request.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResult
|
||||
* The access result.
|
||||
*/
|
||||
public static function viewDomainList(AccountInterface $account) {
|
||||
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.
|
||||
*
|
||||
* 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
|
||||
* ones you can join them by using "+".
|
||||
* single domain, users with that domain with have access. If you specify
|
||||
* multiple ones you can join them by using "+".
|
||||
*
|
||||
* 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
|
||||
@@ -28,7 +28,6 @@ class DomainRouteCheck implements AccessInterface {
|
||||
*/
|
||||
protected $requirementsKey = '_domain';
|
||||
|
||||
|
||||
/**
|
||||
* The Domain negotiator.
|
||||
*
|
||||
@@ -39,7 +38,7 @@ class DomainRouteCheck implements AccessInterface {
|
||||
/**
|
||||
* Constructs the object.
|
||||
*
|
||||
* @param DomainNegotiatorInterface $negotiator
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* The domain negotiation service.
|
||||
*/
|
||||
public function __construct(DomainNegotiatorInterface $negotiator) {
|
||||
|
||||
+2
-1
@@ -59,7 +59,8 @@ class CurrentDomainContext implements ContextProviderInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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
|
||||
* A domain record object.
|
||||
* @param string|NULL $op
|
||||
* @param string|null $op
|
||||
* The operation being performed, either 'default' to make the domain record
|
||||
* the default, 'enable' to enable the domain record, or 'disable' to
|
||||
* disable the domain record.
|
||||
@@ -62,14 +62,14 @@ class DomainController {
|
||||
|
||||
// Set a message.
|
||||
if ($success) {
|
||||
drupal_set_message($message);
|
||||
\Drupal::messenger()->addMessage($message);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('The operation failed.'));
|
||||
\Drupal::messenger()->addMessage($this->t('The operation failed.'));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\domain\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
|
||||
@@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainElementManagerInterface;
|
||||
use Drupal\user\UserStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
@@ -20,11 +19,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
*/
|
||||
class DomainAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
@@ -105,10 +104,11 @@ class DomainAccessControlHandler extends EntityAccessControlHandler implements E
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to retrieve field data from.
|
||||
* @param \Drupal\Core\Session\AccountInterface
|
||||
* @param \Drupal\Core\Session\AccountInterface $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) {
|
||||
$user = $this->userStorage->load($account->id());
|
||||
|
||||
@@ -16,14 +16,14 @@ class DomainCreator implements DomainCreatorInterface {
|
||||
/**
|
||||
* The Domain loader.
|
||||
*
|
||||
* @var \Drupal\domain\DomainLoaderInterface $loader
|
||||
* @var \Drupal\domain\DomainLoaderInterface
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The Domain negotiator.
|
||||
*
|
||||
* @var \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||
*/
|
||||
protected $negotiator;
|
||||
|
||||
@@ -43,19 +43,19 @@ class DomainCreator implements DomainCreatorInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDomain(array $values = array()) {
|
||||
public function createDomain(array $values = []) {
|
||||
$default = $this->loader->loadDefaultId();
|
||||
$domains = $this->loader->loadMultiple();
|
||||
if (empty($values)) {
|
||||
$values['hostname'] = $this->createHostname();
|
||||
$values['name'] = \Drupal::config('system.site')->get('name');
|
||||
}
|
||||
$values += array(
|
||||
'scheme' => \Drupal::service('entity_type.manager')->getStorage('domain')->getDefaultScheme(),
|
||||
$values += [
|
||||
'scheme' => \Drupal::entityTypeManager()->getStorage('domain')->getDefaultScheme(),
|
||||
'status' => 1,
|
||||
'weight' => count($domains) + 1,
|
||||
'is_default' => (int) empty($default),
|
||||
);
|
||||
];
|
||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||
|
||||
return $domain;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Drupal\domain;
|
||||
|
||||
/**
|
||||
* Handles the creation of new domain records.
|
||||
*
|
||||
* @deprecated
|
||||
* This interface will be removed before the 8.1.0 release.
|
||||
*/
|
||||
@@ -17,10 +18,10 @@ interface DomainCreatorInterface {
|
||||
* Required values are: hostname, name.
|
||||
* Passing an empty array will create a domain from the current request.
|
||||
*
|
||||
* @return DomainInterface $domain
|
||||
* @return \Drupal\domain\DomainInterface
|
||||
* A domain record object.
|
||||
*/
|
||||
public function createDomain(array $values = array());
|
||||
public function createDomain(array $values = []);
|
||||
|
||||
/**
|
||||
* Gets the hostname of the active request.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\domain;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
@@ -16,21 +17,23 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
*
|
||||
* 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
|
||||
* show/hide domain options. See the DomainSourceElementManager for a non-default
|
||||
* implementation.
|
||||
* show/hide domain options. See the DomainSourceElementManager for a
|
||||
* non-default implementation.
|
||||
*/
|
||||
class DomainElementManager implements DomainElementManagerInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity type manager
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The domain storage.
|
||||
*
|
||||
* @var \Drupal\domain\DomainStorageInterface
|
||||
*/
|
||||
protected $domainStorage;
|
||||
@@ -38,8 +41,8 @@ class DomainElementManager implements DomainElementManagerInterface {
|
||||
/**
|
||||
* Constructs a DomainElementManager object.
|
||||
*
|
||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityTypeManager = $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) {
|
||||
// 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]);
|
||||
$empty = empty($form[$field_name]['widget']['#options']);
|
||||
|
||||
// If the domain form element is set as a group, and the field is not assigned to
|
||||
// another group, then move it. See domain_access_form_node_form_alter().
|
||||
// If the domain form element is set as a group, and the field is not
|
||||
// assigned to another group, then move it. See
|
||||
// domain_access_form_node_form_alter().
|
||||
if (isset($form['domain']) && !isset($form[$field_name]['#group'])) {
|
||||
$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.
|
||||
if (!empty($disallowed) || $empty) {
|
||||
// @TODO: Potentially show this information to users with permission.
|
||||
$form[$field_name . '_disallowed'] = array(
|
||||
$form[$field_name . '_disallowed'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $disallowed,
|
||||
);
|
||||
$form['domain_hidden_fields'] = array(
|
||||
];
|
||||
$form['domain_hidden_fields'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $fields,
|
||||
);
|
||||
];
|
||||
if ($hide_on_disallow || $empty) {
|
||||
$form[$field_name]['#access'] = FALSE;
|
||||
}
|
||||
@@ -97,7 +101,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function submitEntityForm(array &$form, FormStateInterface $form_state) {
|
||||
$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 = [];
|
||||
$info = $form_state->getBuildInfo();
|
||||
$entity = $form_state->getFormObject()->getEntity();
|
||||
@@ -135,7 +139,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fieldList($field_name) {
|
||||
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.
|
||||
$list = [];
|
||||
// @TODO In tests, $entity is returning NULL.
|
||||
@@ -171,7 +175,7 @@ class DomainElementManager implements DomainElementManagerInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubmitHandler() {
|
||||
return '\\Drupal\\domain\\DomainElementManager::submitEntityForm';
|
||||
@@ -192,10 +196,10 @@ class DomainElementManager implements DomainElementManagerInterface {
|
||||
foreach ($domains as $domain) {
|
||||
$items[] = $domain->label();
|
||||
}
|
||||
$build = array(
|
||||
$build = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
);
|
||||
];
|
||||
$string .= render($build);
|
||||
return '<div class="disallowed">' . $string . '</div>';
|
||||
}
|
||||
|
||||
+16
-16
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\domain;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
@@ -22,16 +23,16 @@ interface DomainElementManagerInterface {
|
||||
*
|
||||
* @param array $form
|
||||
* The form array.
|
||||
* @param FormStateInterface $form_state
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state object.
|
||||
* @param $field_name
|
||||
* @param string $field_name
|
||||
* 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
|
||||
* is not assigned to that domain, pass TRUE to remove the form element
|
||||
* entirely. See DomainSourceElementManager for the use-case.
|
||||
*
|
||||
* @return array $form
|
||||
* @return array
|
||||
* Return the modified form array.
|
||||
*/
|
||||
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
|
||||
* entity being saved.
|
||||
*
|
||||
* @param $form
|
||||
* The form array.
|
||||
* @param Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state object.
|
||||
* No return value. Hidden values are added to the field values directly.
|
||||
*
|
||||
* @return
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param array $field
|
||||
* 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.
|
||||
*
|
||||
* @param $field_name
|
||||
* @param string $field_name
|
||||
* The name of the field being processed. Inherited from setFormOptions.
|
||||
*
|
||||
* @return array
|
||||
@@ -85,7 +85,7 @@ interface DomainElementManagerInterface {
|
||||
* The domain access field values, keyed by id (machine_name) with value of
|
||||
* 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.
|
||||
@@ -97,8 +97,8 @@ interface DomainElementManagerInterface {
|
||||
* The method must be public and static, since it will be called from the
|
||||
* form submit handler without knowledge of the parent class.
|
||||
*
|
||||
* The base implementat is submitEntityForm, and can be overridden by
|
||||
* specific subclasses.
|
||||
* The base implementation is submitEntityForm, and can be overridden by
|
||||
* specific subclasses.
|
||||
*/
|
||||
public function getSubmitHandler();
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
namespace Drupal\domain;
|
||||
|
||||
use Drupal\Core\Config\ConfigValueException;
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
|
||||
/**
|
||||
* Base form for domain edit forms.
|
||||
@@ -36,11 +34,11 @@ class DomainForm extends EntityForm {
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* The entity type manager
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
@@ -52,8 +50,8 @@ class DomainForm extends EntityForm {
|
||||
* The renderer.
|
||||
* @param \Drupal\domain\DomainValidatorInterface $validator
|
||||
* The domain validator.
|
||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(DomainStorageInterface $domain_storage, RendererInterface $renderer, DomainValidatorInterface $validator, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->domainStorage = $domain_storage;
|
||||
@@ -88,70 +86,74 @@ class DomainForm extends EntityForm {
|
||||
$domain->addProperty('hostname', $this->domainStorage->createHostname());
|
||||
$domain->addProperty('name', $this->config('system.site')->get('name'));
|
||||
}
|
||||
$form['domain_id'] = array(
|
||||
$form['domain_id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $domain->getDomainId(),
|
||||
);
|
||||
$form['hostname'] = array(
|
||||
];
|
||||
$form['hostname'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Hostname'),
|
||||
'#size' => 40,
|
||||
'#maxlength' => 80,
|
||||
'#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).'),
|
||||
);
|
||||
$form['id'] = array(
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => !empty($domain->id()) ? $domain->id() : '',
|
||||
'#disabled' => !empty($domain->id()),
|
||||
'#machine_name' => array(
|
||||
'source' => array('hostname'),
|
||||
'exists' => array($this->domainStorage, 'load'),
|
||||
),
|
||||
);
|
||||
$form['name'] = array(
|
||||
'#machine_name' => [
|
||||
'source' => ['hostname'],
|
||||
'exists' => [$this->domainStorage, 'load'],
|
||||
],
|
||||
];
|
||||
$form['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Name'),
|
||||
'#size' => 40,
|
||||
'#maxlength' => 80,
|
||||
'#default_value' => $domain->label(),
|
||||
'#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.
|
||||
$add_suffix = FALSE;
|
||||
$form['scheme'] = array(
|
||||
$form['scheme'] = [
|
||||
'#type' => 'radios',
|
||||
'#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(),
|
||||
'#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',
|
||||
'#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(),
|
||||
'#description' => $this->t('"Inactive" domains are only accessible to user roles with that assigned permission.'),
|
||||
);
|
||||
$form['weight'] = array(
|
||||
];
|
||||
$form['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#title' => $this->t('Weight'),
|
||||
'#delta' => $count_existing + 1,
|
||||
'#default_value' => $domain->getWeight(),
|
||||
'#description' => $this->t('The sort order for this record. Lower values display first.'),
|
||||
);
|
||||
$form['is_default'] = array(
|
||||
];
|
||||
$form['is_default'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Default domain'),
|
||||
'#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.'),
|
||||
);
|
||||
$form['validate_url'] = array(
|
||||
];
|
||||
$form['validate_url'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Test server response'),
|
||||
'#default_value' => TRUE,
|
||||
'#description' => $this->t('Validate that url of the host is accessible to Drupal before saving.'),
|
||||
);
|
||||
];
|
||||
$required = $this->validator->getRequiredFields();
|
||||
foreach ($form as $key => $element) {
|
||||
if (in_array($key, $required)) {
|
||||
@@ -182,7 +184,8 @@ class DomainForm extends EntityForm {
|
||||
// Do not use domain loader because it may change hostname.
|
||||
$existing = $this->domainStorage->loadByProperties(['hostname' => $hostname]);
|
||||
$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.
|
||||
if ($existing && $existing->getDomainId() != $entity->getDomainId()) {
|
||||
$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) {
|
||||
$status = parent::save($form, $form_state);
|
||||
if ($status == SAVED_NEW) {
|
||||
drupal_set_message($this->t('Domain record created.'));
|
||||
\Drupal::messenger()->addMessage($this->t('Domain record created.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Domain record updated.'));
|
||||
\Drupal::messenger()->addMessage($this->t('Domain record updated.'));
|
||||
}
|
||||
$form_state->setRedirect('domain.admin');
|
||||
}
|
||||
|
||||
@@ -213,10 +213,8 @@ interface DomainInterface extends ConfigEntityInterface {
|
||||
/**
|
||||
* Find the port used for the domain.
|
||||
*
|
||||
* @param \Drupal\domain\DomainInterface $domain
|
||||
* A domain entity.
|
||||
*
|
||||
* @return An optional port string (e.g. ':8080') or an empty string;
|
||||
* @return string
|
||||
* An optional port string (e.g. ':8080') or an empty string;
|
||||
*/
|
||||
public function getPort();
|
||||
|
||||
@@ -226,7 +224,7 @@ interface DomainInterface extends ConfigEntityInterface {
|
||||
public function createDomainId();
|
||||
|
||||
/**
|
||||
* Retrieves the canonical (registered) hostname for the domaim.
|
||||
* Retrieves the canonical (registered) hostname for the domain.
|
||||
*
|
||||
* @return string
|
||||
* A hostname string.
|
||||
@@ -234,7 +232,7 @@ interface DomainInterface extends ConfigEntityInterface {
|
||||
public function getCanonical();
|
||||
|
||||
/**
|
||||
* Sets the canonical (registered) hostname for the domaim.
|
||||
* Sets the canonical (registered) hostname for the domain.
|
||||
*/
|
||||
public function setCanonical($hostname = NULL);
|
||||
|
||||
|
||||
@@ -6,16 +6,12 @@ use Drupal\Core\Config\Entity\DraggableListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\domain\DomainAccessControlHandler;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
use Drupal\domain\DomainElementManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -70,11 +66,25 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* DraggableListBuilder sets this to FALSE, which cancels any pagination. Restore the
|
||||
* default value from EntityListBuilder.
|
||||
* DraggableListBuilder sets this to FALSE, which cancels any pagination.
|
||||
* Restore the default value from EntityListBuilder.
|
||||
*
|
||||
* @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
|
||||
* The entity type definition.
|
||||
@@ -104,16 +114,16 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
* The domain storage class.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The active user account.
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $destination
|
||||
* @param \Drupal\Core\Routing\RedirectDestinationInterface $destination_handler
|
||||
* The redirect destination helper.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\domain\DomainElementManager $domain_element_manager
|
||||
* @param \Drupal\domain\DomainElementManagerInterface $domain_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);
|
||||
$this->entityTypeId = $entity_type->id();
|
||||
$this->domainStorage = $domain_storage;
|
||||
@@ -152,35 +162,35 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
$super_admin = $this->currentUser->hasPermission('administer domains');
|
||||
if ($super_admin || $this->currentUser->hasPermission('access inactive domains')) {
|
||||
if ($entity->status() && !$default) {
|
||||
$operations['disable'] = array(
|
||||
$operations['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,
|
||||
);
|
||||
];
|
||||
}
|
||||
elseif (!$default) {
|
||||
$operations['enable'] = array(
|
||||
$operations['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,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!$default && $super_admin) {
|
||||
$operations['default'] = array(
|
||||
$operations['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,
|
||||
);
|
||||
];
|
||||
}
|
||||
if (!$default && $this->accessHandler->checkAccess($entity, 'delete')->isAllowed()) {
|
||||
$operations['delete'] = array(
|
||||
$operations['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,
|
||||
);
|
||||
];
|
||||
}
|
||||
$operations += $this->moduleHandler->invokeAll('domain_operations', array($entity, $this->currentUser));
|
||||
$operations += $this->moduleHandler->invokeAll('domain_operations', [$entity, $this->currentUser]);
|
||||
foreach ($operations as $key => $value) {
|
||||
if (isset($value['query']['token'])) {
|
||||
$operations[$key]['query'] += $destination;
|
||||
@@ -222,13 +232,13 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
}
|
||||
|
||||
$row['label'] = $this->getLabel($entity);
|
||||
$row['hostname'] = array('#markup' => $entity->getLink());
|
||||
$row['hostname'] = ['#markup' => $entity->getLink()];
|
||||
if ($entity->isActive()) {
|
||||
$row['hostname']['#prefix'] = '<strong>';
|
||||
$row['hostname']['#suffix'] = '</strong>';
|
||||
}
|
||||
$row['status'] = array('#markup' => $entity->status() ? $this->t('Active') : $this->t('Inactive'));
|
||||
$row['is_default'] = array('#markup' => ($entity->isDefault() ? $this->t('Yes') : $this->t('No')));
|
||||
$row['status'] = ['#markup' => $entity->status() ? $this->t('Active') : $this->t('Inactive')];
|
||||
$row['is_default'] = ['#markup' => ($entity->isDefault() ? $this->t('Yes') : $this->t('No'))];
|
||||
$row += parent::buildRow($entity);
|
||||
|
||||
if (!$this->currentUser->hasPermission('administer domains')) {
|
||||
@@ -280,7 +290,6 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal sort method for form weights.
|
||||
*/
|
||||
@@ -294,8 +303,8 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Builds the entity listing as a form with pagination. This method overrides both
|
||||
* Drupal\Core\Config\Entity\DraggableListBuilder::render() and
|
||||
* Builds the entity listing as a form with pagination. This method overrides
|
||||
* both Drupal\Core\Config\Entity\DraggableListBuilder::render() and
|
||||
* Drupal\Core\Entity\EntityListBuilder::render().
|
||||
*/
|
||||
public function render() {
|
||||
@@ -304,9 +313,9 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
|
||||
// Only add the pager if a limit is specified.
|
||||
if ($this->limit) {
|
||||
$form['pager'] = array(
|
||||
$form['pager'] = [
|
||||
'#type' => 'pager',
|
||||
);
|
||||
];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
@@ -314,8 +323,8 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Loads entity IDs using a pager sorted by the entity weight. The default behavior when
|
||||
* using a limit is to sort by id.
|
||||
* Loads entity IDs using a pager sorted by the entity weight. The default
|
||||
* behavior when using a limit is to sort by id.
|
||||
*
|
||||
* We also have to limit by assigned domains of the active user.
|
||||
*
|
||||
@@ -328,10 +337,10 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
$query = $this->getStorage()->getQuery()
|
||||
->sort($this->entityType->getKey('weight'));
|
||||
|
||||
// If the user cannot administer domains, we must filter the query further by
|
||||
// assigned IDs. We don't have to check permissions here, because that is handled by
|
||||
// the route system and buildRow(). There are two permissions that allow users to view
|
||||
// the entire list.
|
||||
// If the user cannot administer domains, we must filter the query further
|
||||
// by assigned IDs. We don't have to check permissions here, because that is
|
||||
// handled by the route system and buildRow(). There are two permissions
|
||||
// that allow users to view the entire list.
|
||||
if (!$this->currentUser->hasPermission('administer domains') && !$this->currentUser->hasPermission('view domain list')) {
|
||||
$user = $this->userStorage->load($this->currentUser->id());
|
||||
$allowed = $this->domainElementManager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
||||
@@ -344,4 +353,5 @@ class DomainListBuilder extends DraggableListBuilder {
|
||||
}
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
|
||||
/**
|
||||
* Loads Domain records.
|
||||
*
|
||||
* @deprecated
|
||||
* This class will be removed before the 8.1.0 release.
|
||||
* Use DomainStorage instead, loaded through the EntityTypeManager.
|
||||
@@ -49,7 +50,7 @@ class DomainLoader implements DomainLoaderInterface {
|
||||
*/
|
||||
public function loadSchema() {
|
||||
$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) {
|
||||
$controller = $this->getStorage();
|
||||
if ($reset) {
|
||||
$controller->resetCache(array($id));
|
||||
$controller->resetCache([$id]);
|
||||
}
|
||||
return $controller->load($id);
|
||||
}
|
||||
@@ -78,7 +79,7 @@ class DomainLoader implements DomainLoaderInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadDefaultDomain() {
|
||||
$result = $this->getStorage()->loadByProperties(array('is_default' => TRUE));
|
||||
$result = $this->getStorage()->loadByProperties(['is_default' => TRUE]);
|
||||
if (!empty($result)) {
|
||||
return current($result);
|
||||
}
|
||||
@@ -101,7 +102,7 @@ class DomainLoader implements DomainLoaderInterface {
|
||||
*/
|
||||
public function loadMultipleSorted(array $ids = NULL) {
|
||||
$domains = $this->loadMultiple($ids);
|
||||
uasort($domains, array($this, 'sort'));
|
||||
uasort($domains, [$this, 'sort']);
|
||||
return $domains;
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ class DomainLoader implements DomainLoaderInterface {
|
||||
*/
|
||||
public function loadByHostname($hostname) {
|
||||
$hostname = $this->prepareHostname($hostname);
|
||||
$result = $this->getStorage()->loadByProperties(array('hostname' => $hostname));
|
||||
$result = $this->getStorage()->loadByProperties(['hostname' => $hostname]);
|
||||
if (empty($result)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -121,7 +122,7 @@ class DomainLoader implements DomainLoaderInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadOptionsList() {
|
||||
$list = array();
|
||||
$list = [];
|
||||
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
||||
$list[$id] = $domain->label();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Drupal\domain;
|
||||
|
||||
/**
|
||||
* Supplies loader methods for common domain requests.
|
||||
*
|
||||
* @deprecated
|
||||
* 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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $httpHost;
|
||||
|
||||
@@ -76,7 +78,7 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
||||
* The request stack object.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $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.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $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
|
||||
// is required for hook_domain_request_alter().
|
||||
else {
|
||||
$values = array('hostname' => $httpHost);
|
||||
/** @var \Drupal\domain\Entity\DomainInterface $domain */
|
||||
$values = ['hostname' => $httpHost];
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
$domain = $this->domainStorage->create($values);
|
||||
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
||||
}
|
||||
@@ -204,8 +206,8 @@ class DomainNegotiator implements DomainNegotiatorInterface {
|
||||
return TRUE;
|
||||
}
|
||||
// Check for registered alias matches.
|
||||
$values = array('hostname' => $hostname);
|
||||
/** @var \Drupal\domain\Entity\DomainInterface $domain */
|
||||
$values = ['hostname' => $hostname];
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
$domain = $this->domainStorage->create($values);
|
||||
$domain->setMatchType(self::DOMAIN_MATCH_NONE);
|
||||
|
||||
|
||||
@@ -84,7 +84,9 @@ interface DomainNegotiatorInterface {
|
||||
* @param string $hostname
|
||||
* 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);
|
||||
|
||||
|
||||
@@ -2,25 +2,20 @@
|
||||
|
||||
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\RequestContext;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Http\TrustedHostsRequestFactory;
|
||||
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
|
||||
* sensitive. The main implementation is in DomainSourceRedirectResponseSubscriber.
|
||||
* This class can be used in cases where LocalRedirectResponse needs to be
|
||||
* domain sensitive. The main implementation is in
|
||||
* DomainSourceRedirectResponseSubscriber.
|
||||
*
|
||||
* This class combines LocalAwareRedirectResponseTrait and UrlHelper methods that
|
||||
* cannot be overridden safely otherwise.
|
||||
* This class combines LocalAwareRedirectResponseTrait and UrlHelper methods
|
||||
* that cannot be overridden safely otherwise.
|
||||
*/
|
||||
class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||
|
||||
@@ -64,6 +59,7 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||
* Returns the request context.
|
||||
*
|
||||
* @return \Drupal\Core\Routing\RequestContext
|
||||
* The request context.
|
||||
*/
|
||||
protected function getRequestContext() {
|
||||
if (!isset($this->requestContext)) {
|
||||
@@ -90,16 +86,16 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||
* Determines if an external URL points to this domain-aware installation.
|
||||
*
|
||||
* This method replaces the logic in
|
||||
* Drupal\Component\Utility\UrlHelper::externalIsLocal(). Since that class is not
|
||||
* directly extendable, we have to replace it.
|
||||
* Drupal\Component\Utility\UrlHelper::externalIsLocal(). Since that class is
|
||||
* not directly extendable, we have to replace it.
|
||||
*
|
||||
* @param string $url
|
||||
* 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
|
||||
* 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
|
||||
* Exception thrown when $url is not fully qualified.
|
||||
@@ -155,13 +151,15 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||
self::$trustedHosts = [];
|
||||
}
|
||||
|
||||
// Trim and remove port number from host. Host is lowercase as per RFC 952/2181
|
||||
$host = strtolower(preg_replace('/:\d+$/', '', trim($host)));
|
||||
// Trim and remove port number from host. Host is lowercase as per RFC
|
||||
// 952/2181.
|
||||
$host = mb_strtolower(preg_replace('/:\d+$/', '', trim($host)));
|
||||
|
||||
// In the original Symfony code, hostname validation runs here. We have removed that
|
||||
// portion because Domains are already validated on creation.
|
||||
// In the original Symfony code, hostname validation runs here. We have
|
||||
// removed that portion because Domains are already validated on creation.
|
||||
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)) {
|
||||
return TRUE;
|
||||
}
|
||||
@@ -173,8 +171,9 @@ class DomainRedirectResponse extends CacheableSecuredRedirectResponse {
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
// In cases where trusted_host_patterns are not set, allow all. This is flagged as a
|
||||
// security issue by Drupal core in the Reports UI.
|
||||
// In cases where trusted_host_patterns are not set, allow all. This is
|
||||
// flagged as a security issue by Drupal core in the Reports UI.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ namespace Drupal\domain;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
|
||||
/**
|
||||
* Loads Domain records.
|
||||
@@ -66,7 +64,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
*/
|
||||
public function loadSchema() {
|
||||
$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}
|
||||
*/
|
||||
public function loadDefaultDomain() {
|
||||
$result = $this->loadByProperties(array('is_default' => TRUE));
|
||||
$result = $this->loadByProperties(['is_default' => TRUE]);
|
||||
if (!empty($result)) {
|
||||
return current($result);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadMultipleSorted(array $ids = NULL) {
|
||||
$domains = $this->loadMultiple($ids);
|
||||
uasort($domains, array($this, 'sort'));
|
||||
uasort($domains, [$this, 'sort']);
|
||||
return $domains;
|
||||
}
|
||||
|
||||
@@ -106,7 +103,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
*/
|
||||
public function loadByHostname($hostname) {
|
||||
$hostname = $this->prepareHostname($hostname);
|
||||
$result = $this->loadByProperties(array('hostname' => $hostname));
|
||||
$result = $this->loadByProperties(['hostname' => $hostname]);
|
||||
if (empty($result)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -117,7 +114,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadOptionsList() {
|
||||
$list = array();
|
||||
$list = [];
|
||||
foreach ($this->loadMultipleSorted() as $id => $domain) {
|
||||
$list[$id] = $domain->label();
|
||||
}
|
||||
@@ -153,12 +150,12 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
$values['hostname'] = $this->createHostname();
|
||||
$values['name'] = \Drupal::config('system.site')->get('name');
|
||||
}
|
||||
$values += array(
|
||||
$values += [
|
||||
'scheme' => $this->getDefaultScheme(),
|
||||
'status' => 1,
|
||||
'weight' => count($domains) + 1,
|
||||
'is_default' => (int) empty($default),
|
||||
);
|
||||
];
|
||||
$domain = parent::create($values);
|
||||
|
||||
return $domain;
|
||||
@@ -168,7 +165,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createHostname() {
|
||||
// We cannot inject the negotiator due to dependencies.
|
||||
// We cannot inject the negotiator due to dependencies.
|
||||
return \Drupal::service('domain.negotiator')->negotiateActiveHostname();
|
||||
}
|
||||
|
||||
@@ -186,7 +183,7 @@ class DomainStorage extends ConfigEntityStorage implements DomainStorageInterfac
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultScheme() {
|
||||
// Use the foundation request if possible/
|
||||
// Use the foundation request if possible.
|
||||
$request = \Drupal::request();
|
||||
if (!empty($request)) {
|
||||
$scheme = $request->getScheme();
|
||||
|
||||
@@ -20,7 +20,7 @@ interface DomainStorageInterface extends ConfigEntityStorageInterface {
|
||||
/**
|
||||
* Returns the id of the default domain.
|
||||
*
|
||||
* @return int
|
||||
* @return int|bool
|
||||
* The id of the default domain or FALSE if none is set.
|
||||
*/
|
||||
public function loadDefaultId();
|
||||
@@ -116,7 +116,7 @@ interface DomainStorageInterface extends ConfigEntityStorageInterface {
|
||||
*
|
||||
* This function helps us account for variable schemes across environments.
|
||||
*
|
||||
* @return $scheme
|
||||
* @return string
|
||||
* A string representation of s scheme (http|https).
|
||||
*/
|
||||
public function getDefaultScheme();
|
||||
|
||||
@@ -7,15 +7,11 @@ use Drupal\Core\Render\BubbleableMetadata;
|
||||
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
|
||||
* easier refactoring.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Token handler for Domain.
|
||||
*/
|
||||
class DomainToken {
|
||||
|
||||
use StringTranslationTrait;
|
||||
@@ -30,21 +26,21 @@ class DomainToken {
|
||||
/**
|
||||
* The Domain storage handler.
|
||||
*
|
||||
* @var \Drupal\domain\DomainStorageInterface $domainStorage
|
||||
* @var \Drupal\domain\DomainStorageInterface
|
||||
*/
|
||||
protected $domainStorage;
|
||||
|
||||
/**
|
||||
* The Domain negotiator.
|
||||
*
|
||||
* @var \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||
*/
|
||||
protected $negotiator;
|
||||
|
||||
/**
|
||||
* Constructs a DomainToken object.
|
||||
*
|
||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* The domain negotiator.
|
||||
@@ -60,64 +56,64 @@ class DomainToken {
|
||||
*/
|
||||
public function getTokenInfo() {
|
||||
// Domain token types.
|
||||
$info['types']['domain'] = array(
|
||||
$info['types']['domain'] = [
|
||||
'name' => $this->t('Domains'),
|
||||
'description' => $this->t('Tokens related to domains.'),
|
||||
'needs-data' => 'domain',
|
||||
);
|
||||
];
|
||||
// These two types require the Token contrib module.
|
||||
$info['types']['current-domain'] = array(
|
||||
$info['types']['current-domain'] = [
|
||||
'name' => $this->t('Current domain'),
|
||||
'description' => $this->t('Tokens related to the current domain.'),
|
||||
'type' => 'domain',
|
||||
);
|
||||
$info['types']['default-domain'] = array(
|
||||
];
|
||||
$info['types']['default-domain'] = [
|
||||
'name' => $this->t('Default domain'),
|
||||
'description' => $this->t('Tokens related to the default domain.'),
|
||||
'type' => 'domain',
|
||||
);
|
||||
];
|
||||
|
||||
// Domain tokens.
|
||||
$info['tokens']['domain']['id'] = array(
|
||||
$info['tokens']['domain']['id'] = [
|
||||
'name' => $this->t('Domain id'),
|
||||
'description' => $this->t('The domain\'s numeric ID.'),
|
||||
);
|
||||
$info['tokens']['domain']['machine-name'] = array(
|
||||
'description' => $this->t("The domain's numeric ID."),
|
||||
];
|
||||
$info['tokens']['domain']['machine-name'] = [
|
||||
'name' => $this->t('Domain machine name'),
|
||||
'description' => $this->t('The domain machine identifier.'),
|
||||
);
|
||||
$info['tokens']['domain']['path'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['path'] = [
|
||||
'name' => $this->t('Domain path'),
|
||||
'description' => $this->t('The base URL for the domain.'),
|
||||
);
|
||||
$info['tokens']['domain']['name'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['name'] = [
|
||||
'name' => $this->t('Domain name'),
|
||||
'description' => $this->t('The domain name.'),
|
||||
);
|
||||
$info['tokens']['domain']['url'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['url'] = [
|
||||
'name' => $this->t('Domain URL'),
|
||||
'description' => $this->t('The domain\'s URL for the current page request.'),
|
||||
);
|
||||
$info['tokens']['domain']['hostname'] = array(
|
||||
'description' => $this->t("The domain's URL for the current page request."),
|
||||
];
|
||||
$info['tokens']['domain']['hostname'] = [
|
||||
'name' => $this->t('Domain hostname'),
|
||||
'description' => $this->t('The domain hostname.'),
|
||||
);
|
||||
$info['tokens']['domain']['scheme'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['scheme'] = [
|
||||
'name' => $this->t('Domain scheme'),
|
||||
'description' => $this->t('The domain scheme.'),
|
||||
);
|
||||
$info['tokens']['domain']['status'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['status'] = [
|
||||
'name' => $this->t('Domain status'),
|
||||
'description' => $this->t('The domain status.'),
|
||||
);
|
||||
$info['tokens']['domain']['weight'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['weight'] = [
|
||||
'name' => $this->t('Domain weight'),
|
||||
'description' => $this->t('The domain weight.'),
|
||||
);
|
||||
$info['tokens']['domain']['is_default'] = array(
|
||||
];
|
||||
$info['tokens']['domain']['is_default'] = [
|
||||
'name' => $this->t('Domain default'),
|
||||
'description' => $this->t('The domain is the default domain.'),
|
||||
);
|
||||
];
|
||||
|
||||
return $info;
|
||||
}
|
||||
@@ -126,7 +122,7 @@ class DomainToken {
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
public function getTokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
|
||||
$replacements = array();
|
||||
$replacements = [];
|
||||
|
||||
$domain = NULL;
|
||||
|
||||
@@ -140,9 +136,11 @@ class DomainToken {
|
||||
$domain = $this->negotiator->getActiveDomain();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'current-domain':
|
||||
$domain = $this->negotiator->getActiveDomain();
|
||||
break;
|
||||
|
||||
case 'default-domain':
|
||||
$domain = $this->domainStorage->loadDefaultDomain();
|
||||
break;
|
||||
@@ -168,6 +166,7 @@ class DomainToken {
|
||||
* We assume that the token will call an instance of DomainInterface.
|
||||
*
|
||||
* @return array
|
||||
* An array of callbacks keyed by the token string.
|
||||
*/
|
||||
public function getCallbacks() {
|
||||
return [
|
||||
|
||||
@@ -6,7 +6,6 @@ use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
@@ -68,7 +67,7 @@ class DomainValidator implements DomainValidatorInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($hostname) {
|
||||
$error_list = array();
|
||||
$error_list = [];
|
||||
// Check for at least one dot or the use of 'localhost'.
|
||||
// Note that localhost can specify a port.
|
||||
$localhost_check = explode(':', $hostname);
|
||||
@@ -105,7 +104,7 @@ class DomainValidator implements DomainValidatorInterface {
|
||||
}
|
||||
}
|
||||
// Check for lower case.
|
||||
if ($hostname != Unicode::strtolower($hostname)) {
|
||||
if ($hostname != mb_strtolower($hostname)) {
|
||||
$error_list[] = $this->t('Only lower-case characters are allowed.');
|
||||
}
|
||||
// Check for 'www' prefix if redirection / handling is
|
||||
@@ -148,7 +147,7 @@ class DomainValidator implements DomainValidatorInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected $is_default;
|
||||
protected $is_default = FALSE;
|
||||
|
||||
/**
|
||||
* The domain record protocol (e.g. http://).
|
||||
@@ -146,6 +146,8 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
|
||||
/**
|
||||
* The canonical hostname for the domain.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $canonical;
|
||||
|
||||
@@ -154,15 +156,15 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$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();
|
||||
$count = $storage_controller->getQuery()->count()->execute();
|
||||
$values += array(
|
||||
$values += [
|
||||
'scheme' => empty($GLOBALS['is_https']) ? 'http' : 'https',
|
||||
'status' => 1,
|
||||
'weight' => $count + 1,
|
||||
'is_default' => (int) empty($default),
|
||||
);
|
||||
];
|
||||
// Note that we have not created a domain_id, which is only used for
|
||||
// node access control and will be added on save.
|
||||
}
|
||||
@@ -210,18 +212,18 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
if (!$this->isDefault()) {
|
||||
// Swap the current default.
|
||||
/** @var self $default */
|
||||
if ($default = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain()) {
|
||||
$default->is_default = 0;
|
||||
if ($default = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain()) {
|
||||
$default->is_default = FALSE;
|
||||
$default->setHostname($default->getCanonical());
|
||||
$default->save();
|
||||
}
|
||||
// Save the new default.
|
||||
$this->is_default = 1;
|
||||
$this->is_default = TRUE;
|
||||
$this->setHostname($this->getCanonical());
|
||||
$this->save();
|
||||
}
|
||||
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();
|
||||
}
|
||||
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->setHostname($this->getCanonical());
|
||||
$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,
|
||||
'@value' => $value,
|
||||
'@hostname' => $this->hostname,
|
||||
)));
|
||||
]));
|
||||
}
|
||||
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}
|
||||
*/
|
||||
public function setPath() {
|
||||
$this->path = $this->getScheme() . $this->getHostname() . base_path();
|
||||
global $base_path;
|
||||
$this->path = $this->getScheme() . $this->getHostname() . ($base_path ?: '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUrl() {
|
||||
$uri = \Drupal::request()->getRequestUri();
|
||||
$request = \Drupal::request();
|
||||
$uri = $request ? $request->getRequestUri() : '/';
|
||||
$this->url = $this->getScheme() . $this->getHostname() . $uri;
|
||||
}
|
||||
|
||||
@@ -332,11 +336,11 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
/** @var self $default */
|
||||
$default = $storage->loadDefaultDomain();
|
||||
if (!$default) {
|
||||
$this->is_default = 1;
|
||||
$this->is_default = TRUE;
|
||||
}
|
||||
elseif ($this->is_default && $default->getDomainId() != $this->getDomainId()) {
|
||||
// Swap the current default.
|
||||
$default->is_default = 0;
|
||||
$default->is_default = FALSE;
|
||||
$default->save();
|
||||
}
|
||||
// Ensures we have a proper domain_id.
|
||||
@@ -374,7 +378,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
'domain_disable_action.' . $entity->id(),
|
||||
'domain_enable_action.' . $entity->id(),
|
||||
]);
|
||||
foreach ($actions as $action) {
|
||||
foreach ($actions as $action) {
|
||||
$action->delete();
|
||||
}
|
||||
}
|
||||
@@ -390,8 +394,9 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
// across environments. Instead, we use the crc32 hash function to create a
|
||||
// unique numeric id for each domain. In some systems (Windows?) we have
|
||||
// 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
|
||||
// systems. On 32-bit systems, the number returned may also be too large for PHP.
|
||||
// If we don't use hash(), then crc32() returns different results for 32-
|
||||
// and 64-bit systems. On 32-bit systems, the number returned may also be
|
||||
// too large for PHP.
|
||||
// See #2908236.
|
||||
$id = hash('crc32', $this->id());
|
||||
$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.
|
||||
*
|
||||
* @param integer $id
|
||||
* An integer to ue as the numeric id.
|
||||
* @param int $id
|
||||
* An integer to use as the numeric id.
|
||||
*/
|
||||
public function createNumericId($id) {
|
||||
// Ensure that this value is unique.
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
$result = $storage->loadByProperties(array('domain_id' => $id));
|
||||
$result = $storage->loadByProperties(['domain_id' => $id]);
|
||||
if (empty($result)) {
|
||||
$this->domain_id = $id;
|
||||
}
|
||||
@@ -423,7 +428,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
public function getScheme($add_suffix = TRUE) {
|
||||
$scheme = $this->scheme;
|
||||
if ($scheme == 'variable') {
|
||||
$scheme = \Drupal::service('entity_type.manager')->getStorage('domain')->getDefaultScheme();
|
||||
$scheme = \Drupal::entityTypeManager()->getStorage('domain')->getDefaultScheme();
|
||||
}
|
||||
elseif ($scheme != 'https') {
|
||||
$scheme = 'http';
|
||||
@@ -462,7 +467,7 @@ class Domain extends ConfigEntityBase implements DomainInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLink($current_path = TRUE) {
|
||||
$options = array('absolute' => TRUE, 'https' => $this->isHttps());
|
||||
$options = ['absolute' => TRUE, 'https' => $this->isHttps()];
|
||||
if ($current_path) {
|
||||
$url = Url::fromUri($this->getUrl(), $options);
|
||||
}
|
||||
|
||||
+4
-4
@@ -4,7 +4,6 @@ namespace Drupal\domain\EventSubscriber;
|
||||
|
||||
use Drupal\domain\Access\DomainAccessCheck;
|
||||
use Drupal\domain\DomainNegotiatorInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
use Drupal\domain\DomainRedirectResponse;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Routing\TrustedRedirectResponse;
|
||||
@@ -59,7 +58,7 @@ class DomainSubscriber implements EventSubscriberInterface {
|
||||
*
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
|
||||
* The domain negotiator service.
|
||||
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\domain\Access\DomainAccessCheck $access_check
|
||||
* The access check interface.
|
||||
@@ -120,7 +119,8 @@ class DomainSubscriber implements EventSubscriberInterface {
|
||||
$response = new TrustedRedirectResponse($domain_url, $redirect_status);
|
||||
}
|
||||
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);
|
||||
}
|
||||
$event->setResponse($response);
|
||||
@@ -133,7 +133,7 @@ class DomainSubscriber implements EventSubscriberInterface {
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class DomainDeleteForm extends EntityConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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) {
|
||||
$this->entity->delete();
|
||||
drupal_set_message($this->t('Domain %label has been deleted.', array('%label' => $this->entity->label())));
|
||||
\Drupal::logger('domain')->notice('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.', ['%label' => $this->entity->label()]);
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Settings form for Domain module.
|
||||
*/
|
||||
|
||||
namespace Drupal\domain\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class DomainSettingsForm.
|
||||
*
|
||||
* @package Drupal\domain\Form
|
||||
*/
|
||||
class DomainSettingsForm extends ConfigFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -29,39 +31,42 @@ class DomainSettingsForm extends ConfigFormBase {
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('domain.settings');
|
||||
$form['allow_non_ascii'] = array(
|
||||
$form['allow_non_ascii'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Allow non-ASCII characters in domains and aliases'),
|
||||
'#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.'),
|
||||
);
|
||||
$form['www_prefix'] = array(
|
||||
];
|
||||
$form['www_prefix'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Ignore www prefix when negotiating domains'),
|
||||
'#default_value' => $config->get('www_prefix'),
|
||||
'#description' => $this->t('Domain negotiation will ignore any www prefixes for all requests.'),
|
||||
);
|
||||
];
|
||||
// Get the usable tokens for this field.
|
||||
$patterns = [];
|
||||
foreach (\Drupal::service('domain.token')->getCallbacks() as $key => $callback) {
|
||||
$patterns[] = "[domain:$key]";
|
||||
}
|
||||
$form['css_classes'] = array(
|
||||
$form['css_classes'] = [
|
||||
'#type' => 'textfield',
|
||||
'#size' => 80,
|
||||
'#title' => $this->t('Custom 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)),
|
||||
);
|
||||
$form['login_paths'] = array(
|
||||
'#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'] = [
|
||||
'#type' => 'textarea',
|
||||
'#rows' => 5,
|
||||
'#columns' => 40,
|
||||
'#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.
|
||||
Enter any paths that should be accessible, one per line. Normally, only the
|
||||
login path will be allowed.'),
|
||||
);
|
||||
];
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
|
||||
/**
|
||||
* An array of settings.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $settings = [];
|
||||
|
||||
@@ -48,30 +50,30 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
'#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.'),
|
||||
];
|
||||
$options = array(
|
||||
'select' => t('JavaScript select list'),
|
||||
'menus' => t('Menu-style tab links'),
|
||||
'ul' => t('Unordered list of links'),
|
||||
);
|
||||
$elements['link_theme'] = array(
|
||||
$options = [
|
||||
'select' => $this->t('JavaScript select list'),
|
||||
'menus' => $this->t('Menu-style tab links'),
|
||||
'ul' => $this->t('Unordered list of links'),
|
||||
];
|
||||
$elements['link_theme'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link theme'),
|
||||
'#default_value' => !empty($this->configuration['link_theme']) ? $this->configuration['link_theme'] : $defaults['link_theme'],
|
||||
'#options' => $options,
|
||||
'#description' => $this->t('Select how to display the block output.'),
|
||||
);
|
||||
$options = array(
|
||||
'name' => t('The domain display name'),
|
||||
'hostname' => t('The raw hostname'),
|
||||
'url' => t('The domain base URL'),
|
||||
);
|
||||
$elements['link_label'] = array(
|
||||
];
|
||||
$options = [
|
||||
'name' => $this->t('The domain display name'),
|
||||
'hostname' => $this->t('The raw hostname'),
|
||||
'url' => $this->t('The domain base URL'),
|
||||
];
|
||||
$elements['link_label'] = [
|
||||
'#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'],
|
||||
'#options' => $options,
|
||||
'#description' => $this->t('Select the text to display for each link.'),
|
||||
);
|
||||
];
|
||||
return $elements;
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
* Overrides \Drupal\block\BlockBase::access().
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -101,14 +103,14 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
public function build() {
|
||||
/** @var \Drupal\domain\DomainInterface $active_domain */
|
||||
$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();
|
||||
|
||||
// Determine the visible domain list.
|
||||
$items = [];
|
||||
$add_path = ($this->getSetting('link_options') == 'active');
|
||||
/** @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.
|
||||
$options = ['absolute' => TRUE, 'https' => ($domain->getScheme() == 'https')];
|
||||
if ($add_path) {
|
||||
@@ -157,8 +159,9 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
switch ($this->getSetting('link_theme')) {
|
||||
case 'select':
|
||||
$build['#theme'] = 'domain_nav_block';
|
||||
$build['items'] = $items;
|
||||
$build['#items'] = $items;
|
||||
break;
|
||||
|
||||
case 'menus':
|
||||
// Map the $items params to what menu.html.twig expects.
|
||||
$build['#items'] = $items;
|
||||
@@ -166,6 +169,7 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
$build['#sorted'] = TRUE;
|
||||
$build['#theme'] = 'menu__' . strtr($build['#menu_name'], '-', '_');
|
||||
break;
|
||||
|
||||
case 'ul':
|
||||
default:
|
||||
$build['#theme'] = 'item_list';
|
||||
@@ -190,11 +194,11 @@ class DomainNavBlock extends DomainBlockBase {
|
||||
/**
|
||||
* Gets the configuration for the block, loading defaults if not set.
|
||||
*
|
||||
* @param $key
|
||||
* The setting key to retrieve, a string
|
||||
* @param string $key
|
||||
* The setting key to retrieve, a string.
|
||||
*
|
||||
* @return
|
||||
*. The setting value, a string.
|
||||
* @return string
|
||||
* The setting value, a string.
|
||||
*/
|
||||
public function getSetting($key) {
|
||||
if (isset($this->settings[$key])) {
|
||||
|
||||
+22
-23
@@ -5,7 +5,6 @@ namespace Drupal\domain\Plugin\Block;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainInterface;
|
||||
|
||||
/**
|
||||
* Provides a server information block for a domain request.
|
||||
@@ -21,7 +20,7 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
* Overrides \Drupal\block\BlockBase::access().
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -32,25 +31,25 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||
if (!$domain) {
|
||||
return array(
|
||||
return [
|
||||
'#markup' => $this->t('No domain record could be loaded.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
$header = array($this->t('Server'), $this->t('Value'));
|
||||
$rows[] = array(
|
||||
$header = [$this->t('Server'), $this->t('Value')];
|
||||
$rows[] = [
|
||||
$this->t('HTTP_HOST request'),
|
||||
Html::escape($_SERVER['HTTP_HOST']),
|
||||
);
|
||||
];
|
||||
// Check the response test.
|
||||
$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');
|
||||
// This value is not translatable.
|
||||
$environment = 'default';
|
||||
if (!$check) {
|
||||
// Specific check for 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.
|
||||
$environment = $domain->alias->getEnvironment();
|
||||
}
|
||||
@@ -58,10 +57,10 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
$match = $this->t('FALSE: Using default domain.');
|
||||
}
|
||||
}
|
||||
$rows[] = array(
|
||||
$rows[] = [
|
||||
$this->t('Domain match'),
|
||||
$match,
|
||||
);
|
||||
];
|
||||
$rows[] = [
|
||||
$this->t('Environment'),
|
||||
$environment,
|
||||
@@ -80,10 +79,10 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
];
|
||||
|
||||
$www = \Drupal::config('domain.settings')->get('www_prefix');
|
||||
$rows[] = array(
|
||||
$rows[] = [
|
||||
$this->t('Strip www prefix'),
|
||||
!empty($www) ? $this->t('On') : $this->t('Off'),
|
||||
);
|
||||
];
|
||||
$list = $domain->toArray();
|
||||
ksort($list);
|
||||
foreach ($list as $key => $value) {
|
||||
@@ -99,16 +98,16 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
elseif ($key == 'status' || $key == 'is_default') {
|
||||
$value = empty($value) ? $this->t('FALSE') : $this->t('TRUE');
|
||||
}
|
||||
$rows[] = array(
|
||||
$rows[] = [
|
||||
Html::escape($key),
|
||||
!is_array($value) ? Html::escape($value) : $this->printArray($value),
|
||||
);
|
||||
];
|
||||
}
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,24 +120,24 @@ class DomainServerBlock extends DomainBlockBase {
|
||||
* A suitable output string.
|
||||
*/
|
||||
public function printArray(array $array) {
|
||||
$items = array();
|
||||
$items = [];
|
||||
foreach ($array as $key => $val) {
|
||||
if (!is_array($val)) {
|
||||
$value = Html::escape($val);
|
||||
}
|
||||
else {
|
||||
$list = array();
|
||||
$list = [];
|
||||
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);
|
||||
}
|
||||
$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',
|
||||
'#items' => $items,
|
||||
);
|
||||
];
|
||||
return render($variables);
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -19,7 +19,7 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
||||
* Overrides \Drupal\block\BlockBase::access().
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
||||
public function build() {
|
||||
/** @var \Drupal\domain\DomainInterface $active_domain */
|
||||
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||
$items = array();
|
||||
$items = [];
|
||||
/** @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();
|
||||
if (!$domain->status()) {
|
||||
$string .= '*';
|
||||
@@ -39,12 +39,12 @@ class DomainSwitcherBlock extends DomainBlockBase {
|
||||
if ($domain->id() == $active_domain->id()) {
|
||||
$string = '<em>' . $string . '</em>';
|
||||
}
|
||||
$items[] = array('#markup' => $string);
|
||||
$items[] = ['#markup' => $string];
|
||||
}
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\domain\Plugin\Block;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainInterface;
|
||||
@@ -21,7 +20,7 @@ class DomainTokenBlock extends DomainBlockBase {
|
||||
* Overrides \Drupal\block\BlockBase::access().
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -32,16 +31,16 @@ class DomainTokenBlock extends DomainBlockBase {
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
$domain = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||
if (!$domain) {
|
||||
return array(
|
||||
return [
|
||||
'#markup' => $this->t('No domain record could be loaded.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
$header = array($this->t('Token'), $this->t('Value'));
|
||||
return array(
|
||||
$header = [$this->t('Token'), $this->t('Value')];
|
||||
return [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $this->renderTokens($domain),
|
||||
'#header' => $header,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,11 +48,12 @@ class DomainTokenBlock extends DomainBlockBase {
|
||||
*
|
||||
* @param \Drupal\domain\DomainInterface $domain
|
||||
* The active domain request.
|
||||
*
|
||||
* @return array
|
||||
* An array keyed by token name, with value of replacement value.
|
||||
*/
|
||||
private function renderTokens(DomainInterface $domain) {
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
$token = \Drupal::token();
|
||||
$tokens = $token->getInfo();
|
||||
// The 'domain' token is supported by core. The others by Token module,
|
||||
|
||||
@@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
* id = "domain",
|
||||
* label = @Translation("Domain"),
|
||||
* 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}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['domains'] = array(
|
||||
$form['domains'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('When the following domains are active'),
|
||||
'#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.'),
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'domain/drupal.domain',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
'domains' => array(),
|
||||
) + parent::defaultConfiguration();
|
||||
return [
|
||||
'domains' => [],
|
||||
] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
||||
*/
|
||||
public function summary() {
|
||||
// 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) {
|
||||
$domains = implode(', ', $domains);
|
||||
}
|
||||
@@ -106,10 +106,10 @@ class Domain extends ConditionPluginBase implements ContainerFactoryPluginInterf
|
||||
$domains = reset($domains);
|
||||
}
|
||||
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 {
|
||||
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;
|
||||
|
||||
use Drupal\domain\Plugin\EntityReferenceSelection\DomainSelection;
|
||||
|
||||
/**
|
||||
* Provides entity reference selections for the domain entity type.
|
||||
*
|
||||
@@ -31,6 +29,6 @@ class DomainAdminSelection extends DomainSelection {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $field_type = 'admin';
|
||||
protected $fieldType = 'admin';
|
||||
|
||||
}
|
||||
|
||||
+16
-16
@@ -24,7 +24,7 @@ class DomainSelection extends DefaultSelection {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $field_type = 'editor';
|
||||
protected $fieldType = 'editor';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -47,7 +47,7 @@ class DomainSelection extends DefaultSelection {
|
||||
if (!empty($info->configuration['entity'])) {
|
||||
$context['entity_type'] = $info->configuration['entity']->getEntityTypeId();
|
||||
$context['bundle'] = $info->configuration['entity']->bundle();
|
||||
$context['field_type'] = $this->field_type;
|
||||
$context['field_type'] = $this->fieldType;
|
||||
|
||||
// Load the current user.
|
||||
$account = User::load($this->currentUser->id());
|
||||
@@ -65,48 +65,48 @@ class DomainSelection extends DefaultSelection {
|
||||
$selection_handler_settings = $this->configuration['handler_settings'];
|
||||
|
||||
// Merge-in default values.
|
||||
$selection_handler_settings += array(
|
||||
$selection_handler_settings += [
|
||||
// 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
|
||||
// equivalent to "no entities from any bundle can be referenced".
|
||||
'target_bundles' => NULL,
|
||||
'sort' => array(
|
||||
'sort' => [
|
||||
'field' => 'weight',
|
||||
'direction' => 'ASC',
|
||||
),
|
||||
],
|
||||
'auto_create' => FALSE,
|
||||
'default_selection' => 'current',
|
||||
);
|
||||
];
|
||||
|
||||
$form['target_bundles'] = array(
|
||||
$form['target_bundles'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'weight' => $this->t('Weight'),
|
||||
'label' => $this->t('Name'),
|
||||
'hostname' => $this->t('Hostname'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['sort']['field'] = array(
|
||||
$form['sort']['field'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Sort by'),
|
||||
'#options' => $fields,
|
||||
'#ajax' => FALSE,
|
||||
'#default_value' => $selection_handler_settings['sort']['field'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['sort']['direction'] = array(
|
||||
$form['sort']['direction'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Sort direction'),
|
||||
'#required' => TRUE,
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'ASC' => $this->t('Ascending'),
|
||||
'DESC' => $this->t('Descending'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $selection_handler_settings['sort']['direction'],
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ class DomainRecord extends DrupalSqlBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainNegotiator;
|
||||
use Drupal\domain\DomainNegotiatorInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param DomainStorageInterface $domain_storage
|
||||
* @param \Drupal\domain\DomainStorageInterface $domain_storage
|
||||
* The domain storage loader.
|
||||
* @param DomainNegotiator $domain_negotiator
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $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);
|
||||
$this->domainStorage = $domain_storage;
|
||||
$this->domainNegotiator = $domain_negotiator;
|
||||
@@ -117,7 +116,7 @@ class Domain extends AccessPluginBase implements CacheableDependencyInterface {
|
||||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['domain'] = array('default' => array());
|
||||
$options['domain'] = ['default' => []];
|
||||
|
||||
return $options;
|
||||
}
|
||||
@@ -127,27 +126,27 @@ class Domain extends AccessPluginBase implements CacheableDependencyInterface {
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
$form['domain'] = array(
|
||||
$form['domain'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Domain'),
|
||||
'#default_value' => $this->options['domain'],
|
||||
'#options' => $this->domainStorage->loadOptionsList(),
|
||||
'#description' => $this->t('Only the checked domain(s) will be able to access this display.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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);
|
||||
|
||||
if (!$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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $base_hostname;
|
||||
public $baseHostname;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'node');
|
||||
public static $modules = ['domain', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -45,7 +47,7 @@ abstract class DomainTestBase extends WebTestBase {
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
|
||||
// Set the base hostname for domains.
|
||||
@@ -59,15 +61,16 @@ abstract class DomainTestBase extends WebTestBase {
|
||||
* The user account object to check.
|
||||
*
|
||||
* @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.
|
||||
if (!isset($account->session_id)) {
|
||||
return (bool) $account->id();
|
||||
}
|
||||
// The session ID is hashed before being stored in the database.
|
||||
// @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)) {
|
||||
$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) {
|
||||
$this->loggedInUser = $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:
|
||||
- domain
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-08
|
||||
version: '8.x-1.0-alpha13'
|
||||
# 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: 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) {
|
||||
$operations = [];
|
||||
// Add aliases to the list.
|
||||
$id = $domain->id();
|
||||
$operations['domain_test'] = array(
|
||||
$operations['domain_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,
|
||||
);
|
||||
];
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_domain_references_alter
|
||||
* Implements hook_domain_references_alter().
|
||||
*/
|
||||
function domain_test_domain_references_alter($query, $account, $context) {
|
||||
if ($context['entity_type'] == 'node') {
|
||||
|
||||
+17
-17
@@ -20,16 +20,22 @@ class DomainConditionTest extends DomainTestBase {
|
||||
|
||||
/**
|
||||
* A test domain.
|
||||
*
|
||||
* @var \Drupal\domain\DomainInterface
|
||||
*/
|
||||
protected $test_domain;
|
||||
protected $testDomain;
|
||||
|
||||
/**
|
||||
* A test domain that never matches $test_domain.
|
||||
*
|
||||
* @var \Drupal\domain\DomainInterface
|
||||
*/
|
||||
protected $not_domain;
|
||||
protected $notDomain;
|
||||
|
||||
/**
|
||||
* An array of all testing domains.
|
||||
*
|
||||
* @var \Drupal\domain\DomainInterface[]
|
||||
*/
|
||||
protected $domains;
|
||||
|
||||
@@ -46,9 +52,9 @@ class DomainConditionTest extends DomainTestBase {
|
||||
$this->domainCreateTestDomains(5);
|
||||
|
||||
// Get two sample domains.
|
||||
$this->domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$this->test_domain = array_shift($this->domains);
|
||||
$this->not_domain = array_shift($this->domains);
|
||||
$this->domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
$this->testDomain = array_shift($this->domains);
|
||||
$this->notDomain = array_shift($this->domains);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,29 +63,23 @@ class DomainConditionTest extends DomainTestBase {
|
||||
public function testConditions() {
|
||||
// Grab the domain condition and configure it to check against one domain.
|
||||
$condition = $this->manager->createInstance('domain')
|
||||
->setConfig('domains', array($this->test_domain->id() => $this->test_domain->id()))
|
||||
->setContextValue('entity:domain', $this->not_domain);
|
||||
->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()])
|
||||
->setContextValue('entity:domain', $this->notDomain);
|
||||
$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.
|
||||
$condition = $this->manager->createInstance('domain')
|
||||
->setConfig('domains', array($this->test_domain->id() => $this->test_domain->id()))
|
||||
->setContextValue('entity:domain', $this->test_domain);
|
||||
->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()])
|
||||
->setContextValue('entity:domain', $this->testDomain);
|
||||
$this->assertTrue($condition->execute(), 'Domain request condition succeeds on matching domain.');
|
||||
|
||||
// Check for the proper 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.
|
||||
$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.
|
||||
$this->assertFalse($condition->execute(), 'Domain request condition fails when condition negated.');
|
||||
|
||||
+4
-7
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain record actions.
|
||||
*
|
||||
@@ -15,7 +13,7 @@ class DomainActionsTest extends DomainTestBase {
|
||||
* Tests bulk actions through the domain overview page.
|
||||
*/
|
||||
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);
|
||||
|
||||
$path = 'admin/config/domain';
|
||||
@@ -28,7 +26,7 @@ class DomainActionsTest extends DomainTestBase {
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Test the domains.
|
||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
$domains = $storage->loadMultiple();
|
||||
$this->assertTrue(count($domains) == 4, 'Four domain records found.');
|
||||
|
||||
@@ -43,7 +41,7 @@ class DomainActionsTest extends DomainTestBase {
|
||||
$this->assertText($name, 'Name found properly.');
|
||||
}
|
||||
// Test the list of actions.
|
||||
$actions = array('delete', 'disable', 'default');
|
||||
$actions = ['delete', 'disable', 'default'];
|
||||
foreach ($actions as $action) {
|
||||
$this->assertRaw("/domain/{$action}/", 'Actions found properly.');
|
||||
}
|
||||
@@ -68,7 +66,7 @@ class DomainActionsTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// Test the list of actions.
|
||||
$actions = array('enable', 'delete', 'disable', 'default');
|
||||
$actions = ['enable', 'delete', 'disable', 'default'];
|
||||
foreach ($actions as $action) {
|
||||
$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;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests behavior for the domain admin field element.
|
||||
*
|
||||
@@ -16,7 +14,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'field', 'field_ui', 'user');
|
||||
public static $modules = ['domain', 'field', 'field_ui', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -32,12 +30,12 @@ class DomainAdminElementTest extends DomainTestBase {
|
||||
* Basic test setup.
|
||||
*/
|
||||
public function testDomainAccessElement() {
|
||||
$admin = $this->drupalCreateUser(array(
|
||||
$admin = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer users',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('admin/people/create');
|
||||
@@ -50,7 +48,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
||||
$this->fillField('pass[pass2]', 'test');
|
||||
|
||||
// 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;
|
||||
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
||||
foreach ($domains as $domain) {
|
||||
@@ -73,16 +71,16 @@ class DomainAdminElementTest extends DomainTestBase {
|
||||
$this->assert(count($values) == 3, 'User saved with three domain records.');
|
||||
|
||||
// Now login as a user with limited rights.
|
||||
$account = $this->drupalCreateUser(array(
|
||||
$account = $this->drupalCreateUser([
|
||||
'administer users',
|
||||
'assign domain administrators',
|
||||
));
|
||||
]);
|
||||
$ids = ['example_com', 'one_example_com'];
|
||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||
$tester = $storage->load($account->id());
|
||||
$values = $manager->getFieldValues($tester, DOMAIN_ADMIN_FIELD);
|
||||
$this->assert(count($values) == 2, 'User saved with two domain records.');
|
||||
$storage->resetCache(array($account->id()));
|
||||
$storage->resetCache([$account->id()]);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
$this->drupalGet('user/' . $user->id() . '/edit');
|
||||
@@ -107,7 +105,7 @@ class DomainAdminElementTest extends DomainTestBase {
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Now, check the user.
|
||||
$storage->resetCache(array($user->id()));
|
||||
$storage->resetCache([$user->id()]);
|
||||
$user = $storage->load($user->id());
|
||||
// Check that two values are set.
|
||||
$values = $manager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
|
||||
|
||||
+8
-6
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain CSS configuration.
|
||||
@@ -17,11 +16,14 @@ class DomainCSSTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain');
|
||||
public static $modules = ['domain'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function 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();
|
||||
|
||||
// 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());
|
||||
$text = '<body class="' . Html::getClass($domain->id() . '-class');
|
||||
$this->assertNoRaw($text, 'No custom CSS present.');
|
||||
@@ -50,7 +52,7 @@ class DomainCSSTest extends DomainTestBase {
|
||||
$config->set('css_classes', '[domain:machine-name]-class')->save();
|
||||
|
||||
// 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
|
||||
// necessary to add the url.site cache context. See README.md.
|
||||
drupal_flush_all_caches();
|
||||
@@ -63,7 +65,7 @@ class DomainCSSTest extends DomainTestBase {
|
||||
$config = $this->config('domain.settings');
|
||||
$config->set('css_classes', '[domain:machine-name]-class [domain:name]-class')->save();
|
||||
// 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
|
||||
// necessary to add the url.site cache context. See README.md.
|
||||
drupal_flush_all_caches();
|
||||
|
||||
+3
-5
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain record response check.
|
||||
*
|
||||
@@ -15,10 +13,10 @@ class DomainCheckResponseTest extends DomainTestBase {
|
||||
* Tests that a domain responds as expected.
|
||||
*/
|
||||
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);
|
||||
|
||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
|
||||
// Make a POST request on admin/config/domain/add.
|
||||
$edit = $this->domainPostValues();
|
||||
@@ -38,7 +36,7 @@ class DomainCheckResponseTest extends DomainTestBase {
|
||||
try {
|
||||
$this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
|
||||
}
|
||||
catch (Exception $e) {
|
||||
catch (\Exception $e) {
|
||||
// Ensure no test errors.
|
||||
}
|
||||
// The domain should not save.
|
||||
|
||||
+11
-4
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain record creation API.
|
||||
*
|
||||
@@ -19,10 +17,19 @@ class DomainCreateTest extends DomainTestBase {
|
||||
$this->domainTableIsEmpty();
|
||||
|
||||
// Create a new domain programmatically.
|
||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
$domain = $storage->create();
|
||||
$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);
|
||||
$this->assertTrue(isset($property), 'Property loaded');
|
||||
}
|
||||
|
||||
+18
-20
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain record entity reference field type.
|
||||
*
|
||||
@@ -16,18 +14,18 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function testDomainField() {
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Visit the article field administration page.
|
||||
@@ -64,13 +62,13 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
||||
* Create content for a domain field.
|
||||
*/
|
||||
public function testDomainFieldStorage() {
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Create test domain field.
|
||||
@@ -87,7 +85,7 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
||||
$this->assertText('Domain test field', 'Found the domain field instance.');
|
||||
|
||||
// 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) {
|
||||
$string = 'value="' . $domain->id() . '"';
|
||||
$this->assertRaw($string, 'Found the domain option');
|
||||
@@ -123,34 +121,34 @@ class DomainEntityReferenceTest extends DomainTestBase {
|
||||
$label = 'domain';
|
||||
$name = 'field_' . $label;
|
||||
|
||||
$storage = array(
|
||||
$storage = [
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => -1,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'target_type' => 'domain',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$field_storage_config = \Drupal::entityTypeManager()->getStorage('field_storage_config')->create($storage);
|
||||
$field_storage_config->save();
|
||||
|
||||
$field = array(
|
||||
$field = [
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'label' => 'Domain test field',
|
||||
'bundle' => 'article',
|
||||
'settings' => array(
|
||||
'handler_settings' => array(
|
||||
'sort' => array('field' => 'weight', 'direction' => 'ASC'),
|
||||
),
|
||||
),
|
||||
);
|
||||
'settings' => [
|
||||
'handler_settings' => [
|
||||
'sort' => ['field' => 'weight', 'direction' => 'ASC'],
|
||||
],
|
||||
],
|
||||
];
|
||||
$field_config = \Drupal::entityTypeManager()->getStorage('field_config')->create($field);
|
||||
$field_config->save();
|
||||
|
||||
// Tell the form system how to behave.
|
||||
if ($display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.article.default')) {
|
||||
if ($display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.article.default')) {
|
||||
$display->setComponent($name, ['type' => 'options_buttons'])->save();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-6
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain record form interface.
|
||||
*
|
||||
@@ -15,10 +13,10 @@ class DomainFormsTest extends DomainTestBase {
|
||||
* Create, edit and delete a domain via the user interface.
|
||||
*/
|
||||
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);
|
||||
|
||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
|
||||
// No domains should exist.
|
||||
$this->domainTableIsEmpty();
|
||||
@@ -27,7 +25,12 @@ class DomainFormsTest extends DomainTestBase {
|
||||
$this->drupalGet('admin/config/domain');
|
||||
|
||||
// Check for the add message.
|
||||
$this->assertText('There is no Domain record yet.', 'Text for no domains found.');
|
||||
if (substr_count(\Drupal::VERSION, '8.5') > 0) {
|
||||
$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.
|
||||
$this->drupalGet('admin/config/domain/add');
|
||||
|
||||
@@ -67,7 +70,7 @@ class DomainFormsTest extends DomainTestBase {
|
||||
$this->drupalGet($deleteUrl);
|
||||
|
||||
// Delete the record.
|
||||
$this->drupalPostForm($deleteUrl, array(), 'Delete');
|
||||
$this->drupalPostForm($deleteUrl, [], 'Delete');
|
||||
$storage->resetCache([$default_id]);
|
||||
$domain = $storage->load($default_id);
|
||||
$this->assertTrue(empty($domain), 'Domain record deleted.');
|
||||
|
||||
+7
-9
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests domain record HTTP response.
|
||||
*
|
||||
@@ -21,24 +19,24 @@ class DomainGetResponseTest extends DomainTestBase {
|
||||
// Create a new domain programmatically.
|
||||
$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';
|
||||
/** @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.
|
||||
$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.
|
||||
$values = array(
|
||||
$values = [
|
||||
'hostname' => 'foo.bar',
|
||||
'id' => 'foo_bar',
|
||||
'name' => 'Foo',
|
||||
);
|
||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create($values);
|
||||
];
|
||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create($values);
|
||||
|
||||
$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\user\RoleInterface;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the access rules and redirects for inactive domains.
|
||||
@@ -18,7 +17,7 @@ class DomainInactiveTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'node', 'views');
|
||||
public static $modules = ['domain', 'node', 'views'];
|
||||
|
||||
/**
|
||||
* Test inactive domain.
|
||||
@@ -30,7 +29,7 @@ class DomainInactiveTest extends DomainTestBase {
|
||||
|
||||
// Create four new domains programmatically.
|
||||
$this->domainCreateTestDomains(4);
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
|
||||
// Grab a known domain for testing.
|
||||
$domain = $domains['two_example_com'];
|
||||
@@ -40,7 +39,7 @@ class DomainInactiveTest extends DomainTestBase {
|
||||
|
||||
// Disable the domain and test for redirect.
|
||||
$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.
|
||||
$this->drupalGet($domain->getPath());
|
||||
|
||||
@@ -57,7 +56,7 @@ class DomainInactiveTest extends DomainTestBase {
|
||||
$this->assertResponse(200, 'Request to reset password on inactive domain allowed.');
|
||||
|
||||
// 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.
|
||||
drupal_flush_all_caches();
|
||||
$this->assertFalse($domain->status(), 'Tested domain is set to inactive.');
|
||||
@@ -70,13 +69,14 @@ class DomainInactiveTest extends DomainTestBase {
|
||||
// Check against trusted host patterns.
|
||||
$settings['settings']['trusted_host_patterns'] = (object) [
|
||||
'value' => ['^' . $this->prepareTrustedHostname($domain->getHostname()) . '$',
|
||||
'^' . $this->prepareTrustedHostname($domain2->getHostname()) . '$'],
|
||||
'^' . $this->prepareTrustedHostname($domain2->getHostname()) . '$',
|
||||
],
|
||||
'required' => TRUE,
|
||||
];
|
||||
$this->writeSettings($settings);
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
+7
-9
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests behavior for the domain list builder.
|
||||
*
|
||||
@@ -16,7 +14,7 @@ class DomainListBuilderTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'user');
|
||||
public static $modules = ['domain', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -32,13 +30,13 @@ class DomainListBuilderTest extends DomainTestBase {
|
||||
* Basic test setup.
|
||||
*/
|
||||
public function testDomainListBuilder() {
|
||||
$admin = $this->drupalCreateUser(array(
|
||||
$admin = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('admin/config/domain');
|
||||
@@ -64,12 +62,12 @@ class DomainListBuilderTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// Now login as a user with limited rights.
|
||||
$account = $this->drupalCreateUser(array(
|
||||
$account = $this->drupalCreateUser([
|
||||
'create article content',
|
||||
'edit any article content',
|
||||
'edit assigned domains',
|
||||
'view domain list',
|
||||
));
|
||||
]);
|
||||
$ids = ['example_com', 'one_example_com'];
|
||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||
@@ -130,12 +128,12 @@ class DomainListBuilderTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// Now login as a user with more limited rights.
|
||||
$account2 = $this->drupalCreateUser(array(
|
||||
$account2 = $this->drupalCreateUser([
|
||||
'create article content',
|
||||
'edit any article content',
|
||||
'edit assigned domains',
|
||||
'view assigned domains',
|
||||
));
|
||||
]);
|
||||
$ids = ['example_com', 'one_example_com'];
|
||||
$this->addDomainsToEntity('user', $account2->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||
|
||||
+6
-7
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests behavior for the weight element of the domain list builder.
|
||||
*
|
||||
@@ -16,7 +14,7 @@ class DomainListWeightTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'user');
|
||||
public static $modules = ['domain', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -43,13 +41,13 @@ class DomainListWeightTest extends DomainTestBase {
|
||||
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59');
|
||||
$domains_old = $domains;
|
||||
|
||||
$admin = $this->drupalCreateUser(array(
|
||||
$admin = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('admin/config/domain');
|
||||
@@ -70,7 +68,7 @@ class DomainListWeightTest extends DomainTestBase {
|
||||
$this->assert($domain->getWeight() == 61, 'Weight set to 61 ' . $domain->getWeight());
|
||||
}
|
||||
else {
|
||||
$this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight(). 'Weights unchanged');
|
||||
$this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight() . 'Weights unchanged');
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@@ -101,10 +99,11 @@ class DomainListWeightTest extends DomainTestBase {
|
||||
$this->assert($domain->getWeight() == 2, 'Weight set to 2');
|
||||
}
|
||||
else {
|
||||
$this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight(). 'Weights unchanged');
|
||||
$this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight() . 'Weights unchanged');
|
||||
}
|
||||
}
|
||||
// The last domain should be test59_example_com.
|
||||
$this->assert($domain->id() == 'test59_example_com', 'Last domain is test59' . $domain->id());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain navigation block.
|
||||
@@ -17,7 +16,7 @@ class DomainNavBlockTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'node', 'block');
|
||||
public static $modules = ['domain', 'node', 'block'];
|
||||
|
||||
/**
|
||||
* Test domain navigation block.
|
||||
@@ -25,13 +24,13 @@ class DomainNavBlockTest extends DomainTestBase {
|
||||
public function testDomainNav() {
|
||||
// Create four new domains programmatically.
|
||||
$this->domainCreateTestDomains(4);
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
|
||||
// Place the nav block.
|
||||
$block = $this->drupalPlaceBlock('domain_nav_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.
|
||||
$this->drupalGet('<front>');
|
||||
@@ -56,7 +55,7 @@ class DomainNavBlockTest extends DomainTestBase {
|
||||
}
|
||||
}
|
||||
// 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.
|
||||
$this->drupalGet('<front>');
|
||||
@@ -94,4 +93,5 @@ class DomainNavBlockTest extends DomainTestBase {
|
||||
$this->assertRaw($domain->getPath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-4
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain negotiation manager.
|
||||
@@ -17,7 +16,7 @@ class DomainNegotiatorTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'domain_test', 'block');
|
||||
public static $modules = ['domain', 'domain_test', 'block'];
|
||||
|
||||
/**
|
||||
* Tests the handling of an inbound request.
|
||||
@@ -34,10 +33,10 @@ class DomainNegotiatorTest extends DomainTestBase {
|
||||
$this->drupalPlaceBlock('domain_server_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.
|
||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
||||
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||
$this->drupalGet($domain->getPath());
|
||||
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
||||
}
|
||||
|
||||
+19
-15
@@ -2,13 +2,11 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests behavior for hook_domain_references_alter().
|
||||
*
|
||||
* The module suite ships with two field types -- admin and editor. We want to ensure
|
||||
* that these are filtered properly by hook_domain_references_alter().
|
||||
* The module suite ships with two field types -- admin and editor. We want to
|
||||
* ensure that these are filtered properly by hook_domain_references_alter().
|
||||
*
|
||||
* @group domain
|
||||
*/
|
||||
@@ -19,7 +17,13 @@ class DomainReferencesTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
||||
public static $modules = [
|
||||
'domain',
|
||||
'domain_access',
|
||||
'field',
|
||||
'field_ui',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -36,13 +40,13 @@ class DomainReferencesTest extends DomainTestBase {
|
||||
*/
|
||||
public function testDomainReferences() {
|
||||
// Create an admin user. This will be user 2.
|
||||
$admin = $this->drupalCreateUser(array(
|
||||
$admin = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer users',
|
||||
'administer domains',
|
||||
'assign domain editors',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('admin/people/create');
|
||||
@@ -55,7 +59,7 @@ class DomainReferencesTest extends DomainTestBase {
|
||||
$this->fillField('pass[pass2]', 'test');
|
||||
|
||||
// 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'];
|
||||
$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.');
|
||||
|
||||
// Now login as a user with limited rights. This is user 4.
|
||||
$account = $this->drupalCreateUser(array(
|
||||
$account = $this->drupalCreateUser([
|
||||
'administer users',
|
||||
'assign domain administrators',
|
||||
));
|
||||
]);
|
||||
// Set some domain assignments for this user.
|
||||
$ids = ['example_com', 'one_example_com'];
|
||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ADMIN_FIELD);
|
||||
@@ -137,7 +141,7 @@ class DomainReferencesTest extends DomainTestBase {
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Now, check the user.
|
||||
$storage->resetCache(array($testuser->id()));
|
||||
$storage->resetCache([$testuser->id()]);
|
||||
$testuser = $storage->load($testuser->id());
|
||||
// Check that two values are set.
|
||||
$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.');
|
||||
|
||||
// Now login as a user with different limited rights. This is user 5.
|
||||
$new_account = $this->drupalCreateUser(array(
|
||||
$new_account = $this->drupalCreateUser([
|
||||
'administer users',
|
||||
'assign domain administrators',
|
||||
'assign domain editors',
|
||||
));
|
||||
]);
|
||||
$ids = ['example_com', 'one_example_com'];
|
||||
$new_ids = ['one_example_com', 'four_example_com'];
|
||||
$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.');
|
||||
|
||||
// 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->drupalGet('user/' . $testuser->id() . '/edit');
|
||||
@@ -203,7 +207,7 @@ class DomainReferencesTest extends DomainTestBase {
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Now, check the user.
|
||||
$storage->resetCache(array($testuser->id()));
|
||||
$storage->resetCache([$testuser->id()]);
|
||||
$testuser = $storage->load($testuser->id());
|
||||
// Check that two values are set.
|
||||
$values = $manager->getFieldValues($testuser, DOMAIN_ADMIN_FIELD);
|
||||
|
||||
+32
-18
@@ -8,6 +8,11 @@ use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\domain\DomainInterface;
|
||||
use Drupal\Tests\domain\Traits\DomainTestTrait;
|
||||
|
||||
/**
|
||||
* Class DomainTestBase.
|
||||
*
|
||||
* @package Drupal\Tests\domain\Functional
|
||||
*/
|
||||
abstract class DomainTestBase extends BrowserTestBase {
|
||||
|
||||
use DomainTestTrait;
|
||||
@@ -15,17 +20,19 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $base_hostname;
|
||||
public $baseHostname;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'node');
|
||||
public static $modules = ['domain', 'node'];
|
||||
|
||||
/**
|
||||
* We use the standard profile for testing.
|
||||
@@ -41,12 +48,13 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
parent::setUp();
|
||||
|
||||
// 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
|
||||
* helper methods that make writing tests a bit easier.
|
||||
* The methods below are brazenly copied from Rules module.
|
||||
*
|
||||
* They are all helper methods that make writing tests a bit easier.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -68,8 +76,8 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
* @param string $locator
|
||||
* Link id, title, text or image alt.
|
||||
*
|
||||
* @return \Behat\Mink\Element\NodeElement|null
|
||||
* The link node element.
|
||||
* @return bool
|
||||
* TRUE if link is absent, or FALSE.
|
||||
*/
|
||||
public function findNoLink($locator) {
|
||||
return empty($this->getSession()->getPage()->hasLink($locator));
|
||||
@@ -132,9 +140,10 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* 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) {
|
||||
$this->getSession()->getPage()->checkField($locator);
|
||||
@@ -143,9 +152,10 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* 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) {
|
||||
$this->getSession()->getPage()->uncheckField($locator);
|
||||
@@ -154,15 +164,18 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* Selects option from select field with specified locator.
|
||||
*
|
||||
* @param string $locator input id, name or label
|
||||
* @param string $value option value
|
||||
* @param Boolean $multiple select multiple options
|
||||
* @param string $locator
|
||||
* An input id, name or label.
|
||||
* @param string $value
|
||||
* The option value.
|
||||
* @param bool $multiple
|
||||
* Whether to select multiple options.
|
||||
*
|
||||
* @throws ElementNotFoundException
|
||||
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||
*
|
||||
* @see NodeElement::selectOption
|
||||
*/
|
||||
public function selectFieldOption($locator, $value, $multiple = false) {
|
||||
public function selectFieldOption($locator, $value, $multiple = FALSE) {
|
||||
$this->getSession()->getPage()->selectFieldOption($locator, $value, $multiple);
|
||||
}
|
||||
|
||||
@@ -173,6 +186,7 @@ abstract class DomainTestBase extends BrowserTestBase {
|
||||
* The user account object to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if a given user account is logged in, or FALSE.
|
||||
*/
|
||||
protected function drupalUserIsLoggedIn(AccountInterface $account) {
|
||||
// @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.
|
||||
// @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;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain token handler.
|
||||
@@ -17,7 +16,7 @@ class DomainTokenTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'block');
|
||||
public static $modules = ['domain', 'block'];
|
||||
|
||||
/**
|
||||
* Tests the handling of an inbound request.
|
||||
@@ -34,10 +33,10 @@ class DomainTokenTest extends DomainTestBase {
|
||||
$this->drupalPlaceBlock('domain_token_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.
|
||||
foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple() as $domain) {
|
||||
foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
|
||||
$this->drupalGet($domain->getPath());
|
||||
$this->assertRaw($domain->label(), 'Loaded the proper domain.');
|
||||
$this->assertRaw('<th>Token</th>', 'Token values printed.');
|
||||
|
||||
+22
-14
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Core\Config\ConfigValueException;
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests domain record validation.
|
||||
@@ -19,7 +18,7 @@ class DomainValidatorTest extends DomainTestBase {
|
||||
// No domains should exist.
|
||||
$this->domainTableIsEmpty();
|
||||
$validator = \Drupal::service('domain.validator');
|
||||
$storage = \Drupal::service('entity_type.manager')->getStorage('domain');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('domain');
|
||||
|
||||
// Create a domain.
|
||||
$this->domainCreateTestDomains(1, 'foo.com');
|
||||
@@ -33,15 +32,22 @@ class DomainValidatorTest extends DomainTestBase {
|
||||
$hostnames = [
|
||||
'localhost' => 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,
|
||||
'example.com:8080' => 1,
|
||||
'example.com::8080' => 0, // only one colon.
|
||||
'example.com:abc' => 0, // no letters after a colon.
|
||||
'.example.com' => 0, // cannot begin with a dot.
|
||||
'example.com.' => 0, // cannot end with a dot.
|
||||
'EXAMPLE.com' => 0, // lowercase only.
|
||||
'éxample.com' => 0, // ascii-only.
|
||||
// Only one colon.
|
||||
'example.com::8080' => 0,
|
||||
// No letters after a colon.
|
||||
'example.com:abc' => 0,
|
||||
// Cannot begin with a dot.
|
||||
'.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) {
|
||||
$errors = $validator->validate($hostname);
|
||||
@@ -69,18 +75,20 @@ class DomainValidatorTest extends DomainTestBase {
|
||||
}
|
||||
// Test the two configurable options.
|
||||
$config = $this->config('domain.settings');
|
||||
$config->set('www_prefix', true);
|
||||
$config->set('allow_non_ascii', true);
|
||||
$config->set('www_prefix', TRUE);
|
||||
$config->set('allow_non_ascii', TRUE);
|
||||
$config->save();
|
||||
// Valid hostnames to test. Valid is the boolean value.
|
||||
$hostnames = [
|
||||
'www.example.com' => 0, // no www-prefix allowed
|
||||
'éxample.com' => 1, // ascii-only allowed.
|
||||
// No www-prefix allowed.
|
||||
'www.example.com' => 0,
|
||||
// ascii-only allowed.
|
||||
'éxample.com' => 1,
|
||||
];
|
||||
foreach ($hostnames as $hostname => $valid) {
|
||||
$errors = $validator->validate($hostname);
|
||||
if ($valid) {
|
||||
$this->assertTrue(empty($errors),'Validation test correct with no errors.');
|
||||
$this->assertTrue(empty($errors), 'Validation test correct with no errors.');
|
||||
}
|
||||
else {
|
||||
$this->assertTrue(!empty($errors), 'Validation test correct with errors.');
|
||||
|
||||
+6
-6
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\domain\Functional;
|
||||
|
||||
use Drupal\Tests\domain\Functional\DomainTestBase;
|
||||
|
||||
/**
|
||||
* Tests the domain access plugin for Views.
|
||||
*
|
||||
@@ -16,11 +14,13 @@ class DomainViewsAccessTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'node', 'views', 'block');
|
||||
public static $modules = ['domain', 'node', 'views', 'block'];
|
||||
|
||||
/**
|
||||
* Disabled config schema checking.
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
* @TODO: https://github.com/agentrickard/domain/issues/200
|
||||
*/
|
||||
protected $strictConfigSchema = FALSE;
|
||||
@@ -31,13 +31,13 @@ class DomainViewsAccessTest extends DomainTestBase {
|
||||
public function testInactiveDomain() {
|
||||
// Create five new domains programmatically.
|
||||
$this->domainCreateTestDomains(5);
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
// Enable the views.
|
||||
$this->enableViewsTestModule();
|
||||
// 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
|
||||
// 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.
|
||||
$this->drupalPlaceBlock('views_block:domain_views_access-block_1');
|
||||
|
||||
@@ -75,7 +75,7 @@ class DomainViewsAccessTest extends DomainTestBase {
|
||||
* using it, it cannot be enabled normally.
|
||||
*/
|
||||
protected function enableViewsTestModule() {
|
||||
\Drupal::service('module_installer')->install(array('domain_test'));
|
||||
\Drupal::service('module_installer')->install(['domain_test']);
|
||||
$this->resetAll();
|
||||
$this->rebuildContainer();
|
||||
$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.
|
||||
*
|
||||
* Note that the other hooks are covered by functional tests, since they involve UI
|
||||
* elements.
|
||||
* Note that the other hooks are covered by functional tests, since they involve
|
||||
* UI elements.
|
||||
*
|
||||
* @see DomainReferencesTest
|
||||
* @see DomainListBuilderTes
|
||||
@@ -27,25 +27,33 @@ class DomainHookTest extends KernelTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'domain_test', 'user', 'node');
|
||||
public static $modules = ['domain', 'domain_test', 'user', 'node'];
|
||||
|
||||
/**
|
||||
* Domain id key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key = 'example_com';
|
||||
|
||||
/**
|
||||
* The Domain storage handler service.
|
||||
*
|
||||
* @var \Drupal\domain\DomainStorageInterface
|
||||
*/
|
||||
public $domainStorage;
|
||||
|
||||
/**
|
||||
* The current user service.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
public $currentUser;
|
||||
|
||||
/**
|
||||
* The mondule handler service.
|
||||
* The module handler service.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
public $moduleHandler;
|
||||
|
||||
@@ -59,7 +67,7 @@ class DomainHookTest extends KernelTestBase {
|
||||
$this->domainCreateTestDomains();
|
||||
|
||||
// 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->moduleHandler = \Drupal::service('module_handler');
|
||||
}
|
||||
@@ -74,8 +82,8 @@ class DomainHookTest extends KernelTestBase {
|
||||
// Internal hooks.
|
||||
$path = $domain->getPath();
|
||||
$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($url), new FormattableMarkup('The url property was set to %url by hook_entity_load.', array('%url' => $url)));
|
||||
$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.', ['%url' => $url]));
|
||||
|
||||
// External hooks.
|
||||
$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() {
|
||||
// Set the request.
|
||||
$negotiator = \Drupal::service('domain.negotiator');
|
||||
$negotiator->setRequestDomain($this->base_hostname);
|
||||
$negotiator->setRequestDomain($this->baseHostname);
|
||||
|
||||
// Check that the property was added by our hook.
|
||||
$domain = $negotiator->getActiveDomain();
|
||||
@@ -116,7 +124,7 @@ class DomainHookTest extends KernelTestBase {
|
||||
$domain = $this->domainStorage->load($this->key);
|
||||
|
||||
// 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.
|
||||
$this->assertTrue(isset($operations['domain_test']), 'Domain test operation loaded.');
|
||||
|
||||
+6
-2
@@ -19,15 +19,19 @@ class DomainVariableSchemeTest extends KernelTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain');
|
||||
public static $modules = ['domain'];
|
||||
|
||||
/**
|
||||
* Domain id key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key = 'example_com';
|
||||
|
||||
/**
|
||||
* The Domain storage handler service.
|
||||
*
|
||||
* @var \Drupal\domain\DomainStorageInterface
|
||||
*/
|
||||
public $domainStorage;
|
||||
|
||||
@@ -41,7 +45,7 @@ class DomainVariableSchemeTest extends KernelTestBase {
|
||||
$this->domainCreateTestDomains();
|
||||
|
||||
// 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;
|
||||
|
||||
use Drupal\domain\DomainInterface;
|
||||
|
||||
/**
|
||||
* Contains helper classes for tests to set up various configuration.
|
||||
*/
|
||||
@@ -22,21 +20,33 @@ trait DomainTestTrait {
|
||||
*
|
||||
* @param int $count
|
||||
* 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).
|
||||
* @param array $list
|
||||
* An optional list of subdomains to apply instead of the default set.
|
||||
*/
|
||||
public function domainCreateTestDomains($count = 1, $base_hostname = NULL, $list = array()) {
|
||||
$original_domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
public function domainCreateTestDomains($count = 1, $base_hostname = NULL, array $list = []) {
|
||||
$original_domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(NULL, TRUE);
|
||||
if (empty($base_hostname)) {
|
||||
$base_hostname = $this->base_hostname;
|
||||
$base_hostname = $this->baseHostname;
|
||||
}
|
||||
// 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
|
||||
// $list array to change the default.
|
||||
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++) {
|
||||
if ($i === 0) {
|
||||
@@ -56,15 +66,15 @@ trait DomainTestTrait {
|
||||
$name = 'Test ' . $i;
|
||||
}
|
||||
// Create a new domain programmatically.
|
||||
$values = array(
|
||||
$values = [
|
||||
'hostname' => $hostname,
|
||||
'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->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.
|
||||
* @param int $entity_id
|
||||
* The entity id.
|
||||
* @param array $ids
|
||||
* An array of ids to add.
|
||||
* @param array|string $ids
|
||||
* An id or array of ids to add.
|
||||
* @param string $field
|
||||
* The name of the domain field used to attach to the entity.
|
||||
*/
|
||||
@@ -93,8 +103,8 @@ trait DomainTestTrait {
|
||||
* An array of domain entities.
|
||||
*/
|
||||
public function getDomains() {
|
||||
\Drupal::service('entity_type.manager')->getStorage('domain')->resetCache();
|
||||
return \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
\Drupal::entityTypeManager()->getStorage('domain')->resetCache();
|
||||
return \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,21 +114,21 @@ trait DomainTestTrait {
|
||||
* An array of domain entities.
|
||||
*/
|
||||
public function getDomainsSorted() {
|
||||
\Drupal::service('entity_type.manager')->getStorage('domain')->resetCache();
|
||||
return \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted();
|
||||
\Drupal::entityTypeManager()->getStorage('domain')->resetCache();
|
||||
return \Drupal::entityTypeManager()->getStorage('domain')->loadMultipleSorted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a domain hostname to a trusted host pattern.
|
||||
*
|
||||
* @param $hostname
|
||||
* @param string $hostname
|
||||
* A hostname string.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* A regex-safe hostname, without delimiters.
|
||||
*/
|
||||
public function prepareTrustedHostname($hostname) {
|
||||
$hostname = strtolower(preg_replace('/:\d+$/', '', trim($hostname)));
|
||||
$hostname = mb_strtolower(preg_replace('/:\d+$/', '', trim($hostname)));
|
||||
return preg_quote($hostname);
|
||||
}
|
||||
|
||||
@@ -126,16 +136,16 @@ trait DomainTestTrait {
|
||||
* Set the base hostname for this test.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.');
|
||||
$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.');
|
||||
}
|
||||
|
||||
@@ -143,15 +153,15 @@ trait DomainTestTrait {
|
||||
* Creates domain record for use with POST request tests.
|
||||
*/
|
||||
public function domainPostValues() {
|
||||
$edit = array();
|
||||
$domain = \Drupal::service('entity_type.manager')->getStorage('domain')->create();
|
||||
$edit = [];
|
||||
$domain = \Drupal::entityTypeManager()->getStorage('domain')->create();
|
||||
$required = \Drupal::service('domain.validator')->getRequiredFields();
|
||||
foreach ($required as $key) {
|
||||
$edit[$key] = $domain->get($key);
|
||||
}
|
||||
// URL validation has issues on Travis, so only do it when requested.
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -5,6 +5,9 @@ domain_access.settings:
|
||||
node_advanced_tab:
|
||||
type: boolean
|
||||
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:
|
||||
type: action_configuration_default
|
||||
label: 'Assign content to all affiliates'
|
||||
|
||||
@@ -5,11 +5,11 @@ package: Domain
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- domain
|
||||
- node
|
||||
- drupal:node
|
||||
- domain:domain
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-08
|
||||
version: '8.x-1.0-alpha13'
|
||||
# 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: 1520519900
|
||||
datestamp: 1542230887
|
||||
|
||||
@@ -29,8 +29,18 @@ function domain_access_install() {
|
||||
domain_access_confirm_fields($entity_type, $bundle);
|
||||
}
|
||||
// Install our actions.
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
foreach ($domains as $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\Session\AccountInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* 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().
|
||||
*/
|
||||
function domain_access_node_grants(AccountInterface $account, $op) {
|
||||
$grants = array();
|
||||
$grants = [];
|
||||
/** @var \Drupal\domain\Entity\Domain $active */
|
||||
$active = \Drupal::service('domain.negotiator')->getActiveDomain();
|
||||
|
||||
if (empty($active)) {
|
||||
$active = \Drupal::service('entity_type.manager')->getStorage('domain')->loadDefaultDomain();
|
||||
$active = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain();
|
||||
}
|
||||
|
||||
// No domains means no permissions.
|
||||
@@ -74,7 +73,7 @@ function domain_access_node_grants(AccountInterface $account, $op) {
|
||||
* Implements hook_node_access_records().
|
||||
*/
|
||||
function domain_access_node_access_records(NodeInterface $node) {
|
||||
$grants = array();
|
||||
$grants = [];
|
||||
// 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
|
||||
// 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) {
|
||||
/** @var \Drupal\domain\DomainInterface $domain */
|
||||
if ($domain = \Drupal::service('entity_type.manager')->getStorage('domain')->load($id)) {
|
||||
$grants[] = array(
|
||||
if ($domain = \Drupal::entityTypeManager()->getStorage('domain')->load($id)) {
|
||||
$grants[] = [
|
||||
'realm' => ($translation->isPublished()) ? 'domain_id' : 'domain_unpublished',
|
||||
'gid' => $domain->getDomainId(),
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 1,
|
||||
'grant_delete' => 1,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
// Set the domain_site grant.
|
||||
if (!empty($translation->get(DOMAIN_ACCESS_ALL_FIELD)->value) && $translation->isPublished()) {
|
||||
$grants[] = array(
|
||||
$grants[] = [
|
||||
'realm' => 'domain_site',
|
||||
'gid' => 0,
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
}
|
||||
// Because of language translation, we must save a record for each language.
|
||||
// even if that record adds no permissions, as this one does.
|
||||
else {
|
||||
$grants[] = array(
|
||||
$grants[] = [
|
||||
'realm' => 'domain_site',
|
||||
'gid' => 1,
|
||||
'grant_view' => 0,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return $grants;
|
||||
@@ -167,7 +166,7 @@ function domain_access_presave_generate(EntityInterface $entity) {
|
||||
if (isset($entity->devel_generate['domain_access'])) {
|
||||
$selection = array_filter($entity->devel_generate['domain_access']);
|
||||
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))));
|
||||
}
|
||||
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.
|
||||
$form['submit']['#weight'] = 10;
|
||||
$list = ['random-selection' => t('Random selection')];
|
||||
$list += \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList();
|
||||
$form['domain_access'] = array(
|
||||
$list += \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList();
|
||||
$form['domain_access'] = [
|
||||
'#title' => t('Domains'),
|
||||
'#type' => 'checkboxes',
|
||||
'#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),
|
||||
'#default_value' => ['random-selection'],
|
||||
'#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'),
|
||||
'#type' => 'radios',
|
||||
'#options' => [
|
||||
@@ -221,7 +220,7 @@ function domain_access_form_devel_generate_form_content_alter(&$form, &$form_sta
|
||||
'#default_value' => 'random-selection',
|
||||
'#weight' => 3,
|
||||
'#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_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_ALL_FIELD]['#group'] = 'domain';
|
||||
$form['domain'] = [
|
||||
'#type' => 'details',
|
||||
'#open' => (bool) \Drupal::config('domain_access.settings')->get('node_advanced_tab_open'),
|
||||
'#title' => t('Domain settings'),
|
||||
'#group' => 'advanced',
|
||||
'#attributes' => [
|
||||
'class' => ['node-form-options']
|
||||
'class' => ['node-form-options'],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => ['node/drupal.node'],
|
||||
],
|
||||
'#weight' => 100,
|
||||
'#optional' => TRUE
|
||||
'#optional' => TRUE,
|
||||
];
|
||||
}
|
||||
// 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.
|
||||
*
|
||||
@@ -496,15 +509,16 @@ function domain_access_node_type_insert(EntityInterface $entity) {
|
||||
* If calling this function for entities other than user or node, it is the
|
||||
* caller's responsibility to provide this text.
|
||||
*
|
||||
* 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
|
||||
* provide their own field storage. See the field storage YML sample in
|
||||
* tests/modules/domain_access_test for an example of field storage definitions.
|
||||
* 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
|
||||
* provide their own field storage. See the field storage YML sample in
|
||||
* tests/modules/domain_access_test for an example of field storage
|
||||
* definitions.
|
||||
*
|
||||
* @see domain_access_node_type_insert()
|
||||
* @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.
|
||||
try {
|
||||
$text['node'] = [
|
||||
@@ -522,7 +536,7 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
||||
|
||||
$field_storage = \Drupal::entityTypeManager()->getStorage('field_config');
|
||||
if (!$field = $field_storage->load($id)) {
|
||||
$field = array(
|
||||
$field = [
|
||||
'field_name' => DOMAIN_ACCESS_FIELD,
|
||||
'entity_type' => $entity_type,
|
||||
'label' => 'Domain Access',
|
||||
@@ -531,7 +545,7 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
||||
'required' => $entity_type !== 'user',
|
||||
'description' => 'Select the affiliate domain(s) for this ' . $text[$entity_type]['name'],
|
||||
'default_value_callback' => 'Drupal\domain_access\DomainAccessManager::getDefaultValue',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'handler' => 'default:domain',
|
||||
// Handler_settings are deprecated but seem to be necessary here.
|
||||
'handler_settings' => [
|
||||
@@ -540,27 +554,27 @@ function domain_access_confirm_fields($entity_type, $bundle, $text = array()) {
|
||||
],
|
||||
'target_bundles' => NULL,
|
||||
'sort' => ['field' => 'weight', 'direction' => 'ASC'],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$field_config = $field_storage->create($field);
|
||||
$field_config->save();
|
||||
}
|
||||
// Assign the all affiliates field.
|
||||
$id = $entity_type . '.' . $bundle . '.' . DOMAIN_ACCESS_ALL_FIELD;
|
||||
if (!$field = $field_storage->load($id)) {
|
||||
$field = array(
|
||||
$field = [
|
||||
'field_name' => DOMAIN_ACCESS_ALL_FIELD,
|
||||
'entity_type' => $entity_type,
|
||||
'label' => $text[$entity_type]['label'],
|
||||
'bundle' => $bundle,
|
||||
'required' => FALSE,
|
||||
'description' => $text[$entity_type]['description'],
|
||||
);
|
||||
];
|
||||
$field_config = $field_storage->create($field);
|
||||
$field_config->save();
|
||||
}
|
||||
// Tell the form system how to behave. Default to radio buttons.
|
||||
if ($display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load($entity_type . '.' . $bundle . '.default')) {
|
||||
if ($display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load($entity_type . '.' . $bundle . '.default')) {
|
||||
$display->setComponent(DOMAIN_ACCESS_FIELD, [
|
||||
'type' => 'options_buttons',
|
||||
'weight' => 40,
|
||||
@@ -586,16 +600,16 @@ function domain_access_views_data_alter(array &$data) {
|
||||
$data[$table][DOMAIN_ACCESS_FIELD . '_target_id']['argument']['id'] = 'domain_access_argument';
|
||||
|
||||
// Current domain filter.
|
||||
$data[$table]['current_all'] = array(
|
||||
$data[$table]['current_all'] = [
|
||||
'title' => t('Current domain'),
|
||||
'group' => t('Domain'),
|
||||
'filter' => array(
|
||||
'filter' => [
|
||||
'field' => DOMAIN_ACCESS_FIELD . '_target_id',
|
||||
'id' => 'domain_access_current_all_filter',
|
||||
'title' => t('Available on current domain'),
|
||||
'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.
|
||||
unset($data[$table][DOMAIN_ACCESS_FIELD]['relationship']);
|
||||
|
||||
@@ -622,57 +636,57 @@ function domain_access_domain_insert($entity) {
|
||||
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
||||
if (!$controller->load($id)) {
|
||||
/** @var \Drupal\system\Entity\Action $action */
|
||||
$action = $controller->create(array(
|
||||
$action = $controller->create([
|
||||
'id' => $id,
|
||||
'type' => 'node',
|
||||
'label' => t('Add selected content to the @label domain', array('@label' => $entity->label())),
|
||||
'configuration' => array(
|
||||
'label' => t('Add selected content to the @label domain', ['@label' => $entity->label()]),
|
||||
'configuration' => [
|
||||
'domain_id' => $entity->id(),
|
||||
),
|
||||
],
|
||||
'plugin' => 'domain_access_add_action',
|
||||
));
|
||||
]);
|
||||
$action->trustData()->save();
|
||||
}
|
||||
$remove_id = 'domain_access_remove_action.' . $entity->id();
|
||||
if (!$controller->load($remove_id)) {
|
||||
/** @var \Drupal\system\Entity\Action $action */
|
||||
$action = $controller->create(array(
|
||||
$action = $controller->create([
|
||||
'id' => $remove_id,
|
||||
'type' => 'node',
|
||||
'label' => t('Remove selected content from the @label domain', array('@label' => $entity->label())),
|
||||
'configuration' => array(
|
||||
'label' => t('Remove selected content from the @label domain', ['@label' => $entity->label()]),
|
||||
'configuration' => [
|
||||
'domain_id' => $entity->id(),
|
||||
),
|
||||
],
|
||||
'plugin' => 'domain_access_remove_action',
|
||||
));
|
||||
]);
|
||||
$action->trustData()->save();
|
||||
}
|
||||
$id = 'domain_access_add_editor_action.' . $entity->id();
|
||||
if (!$controller->load($id)) {
|
||||
/** @var \Drupal\system\Entity\Action $action */
|
||||
$action = $controller->create(array(
|
||||
$action = $controller->create([
|
||||
'id' => $id,
|
||||
'type' => 'user',
|
||||
'label' => t('Add editors to the @label domain', array('@label' => $entity->label())),
|
||||
'configuration' => array(
|
||||
'label' => t('Add editors to the @label domain', ['@label' => $entity->label()]),
|
||||
'configuration' => [
|
||||
'domain_id' => $entity->id(),
|
||||
),
|
||||
],
|
||||
'plugin' => 'domain_access_add_editor_action',
|
||||
));
|
||||
]);
|
||||
$action->trustData()->save();
|
||||
}
|
||||
$remove_id = 'domain_access_remove_editor_action.' . $entity->id();
|
||||
if (!$controller->load($remove_id)) {
|
||||
/** @var \Drupal\system\Entity\Action $action */
|
||||
$action = $controller->create(array(
|
||||
$action = $controller->create([
|
||||
'id' => $remove_id,
|
||||
'type' => 'user',
|
||||
'label' => t('Remove editors from the @label domain', array('@label' => $entity->label())),
|
||||
'configuration' => array(
|
||||
'label' => t('Remove editors from the @label domain', ['@label' => $entity->label()]),
|
||||
'configuration' => [
|
||||
'domain_id' => $entity->id(),
|
||||
),
|
||||
],
|
||||
'plugin' => 'domain_access_remove_editor_action',
|
||||
));
|
||||
]);
|
||||
$action->trustData()->save();
|
||||
}
|
||||
}
|
||||
@@ -682,12 +696,12 @@ function domain_access_domain_insert($entity) {
|
||||
*/
|
||||
function domain_access_domain_delete(EntityInterface $entity) {
|
||||
$controller = \Drupal::entityTypeManager()->getStorage('action');
|
||||
$actions = $controller->loadMultiple(array(
|
||||
$actions = $controller->loadMultiple([
|
||||
'domain_access_add_action.' . $entity->id(),
|
||||
'domain_access_remove_action.' . $entity->id(),
|
||||
'domain_access_add_editor_action.' . $entity->id(),
|
||||
'domain_access_remove_editor_action.' . $entity->id(),
|
||||
));
|
||||
]);
|
||||
foreach ($actions as $action) {
|
||||
$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
|
||||
* 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) {
|
||||
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
|
||||
* 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) {
|
||||
// Set domain access default value when the user does not have access
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
domain_access.manager:
|
||||
class: Drupal\domain_access\DomainAccessManager
|
||||
arguments: ['@domain.negotiator']
|
||||
arguments: ['@domain.negotiator', '@module_handler', '@entity_type.manager']
|
||||
access_check.domain_access_views:
|
||||
class: Drupal\domain_access\Access\DomainAccessViewsAccess
|
||||
arguments: ['@entity_type.manager', '@domain_access.manager']
|
||||
|
||||
+8
-4
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\domain_access\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessCheckInterface;
|
||||
@@ -6,10 +7,13 @@ use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Drupal\domain\DomainInterface;
|
||||
use Drupal\domain_access\DomainAccessManagerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class DomainAccessViewsAccess.
|
||||
*
|
||||
* @package Drupal\domain_access\Access
|
||||
*/
|
||||
class DomainAccessViewsAccess implements AccessCheckInterface {
|
||||
|
||||
/**
|
||||
@@ -29,7 +33,7 @@ class DomainAccessViewsAccess implements AccessCheckInterface {
|
||||
/**
|
||||
* The Domain storage handler.
|
||||
*
|
||||
* @var \Drupal\domain\DomainStorageInterface $domainStorage
|
||||
* @var \Drupal\domain\DomainStorageInterface
|
||||
*/
|
||||
protected $domainStorage;
|
||||
|
||||
@@ -43,7 +47,7 @@ class DomainAccessViewsAccess implements AccessCheckInterface {
|
||||
/**
|
||||
* The Domain access manager.
|
||||
*
|
||||
* @var \Drupal\domain_access\DomainAccessManagerInterface $manager
|
||||
* @var \Drupal\domain_access\DomainAccessManagerInterface
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Drupal\domain_access;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainInterface;
|
||||
use Drupal\domain\DomainNegotiatorInterface;
|
||||
@@ -19,24 +19,54 @@ use Drupal\domain\DomainNegotiatorInterface;
|
||||
class DomainAccessManager implements DomainAccessManagerInterface {
|
||||
|
||||
/**
|
||||
* The domain negotiator.
|
||||
*
|
||||
* @var \Drupal\domain\DomainNegotiatorInterface
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param \Drupal\domain\DomainNegotiatorInterface $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->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.
|
||||
$list = [];
|
||||
// @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkEntityAccess(EntityInterface $entity, AccountInterface $account) {
|
||||
public function checkEntityAccess(FieldableEntityInterface $entity, AccountInterface $account) {
|
||||
$entity_domains = $this->getAccessValues($entity);
|
||||
$user = \Drupal::entityTypeManager()->getStorage('user')->load($account->id());
|
||||
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) {
|
||||
$item = [];
|
||||
@@ -100,7 +130,7 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasDomainPermissions(AccountInterface $account, DomainInterface $domain, array $permissions, $conjunction = 'AND') {
|
||||
// Assume no access.
|
||||
@@ -137,4 +167,37 @@ class DomainAccessManager implements DomainAccessManagerInterface {
|
||||
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;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\domain\DomainInterface;
|
||||
|
||||
@@ -17,7 +15,7 @@ interface DomainAccessManagerInterface {
|
||||
/**
|
||||
* 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.
|
||||
* @param string $field_name
|
||||
* The name of the field that holds our data.
|
||||
@@ -25,23 +23,23 @@ interface DomainAccessManagerInterface {
|
||||
* @return array
|
||||
* 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.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity to retrieve field data from.
|
||||
*
|
||||
* @return bool
|
||||
* 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.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
|
||||
* The entity being checked for access.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The account of the user performing the action.
|
||||
@@ -49,7 +47,7 @@ interface DomainAccessManagerInterface {
|
||||
* @return bool
|
||||
* 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.
|
||||
@@ -67,14 +65,14 @@ interface DomainAccessManagerInterface {
|
||||
/**
|
||||
* 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.
|
||||
* @param DomainInterface $domain
|
||||
* @param \Drupal\domain\DomainInterface $domain
|
||||
* The domain being checked.
|
||||
* @param array $permissions
|
||||
* The relevant permissions to check.
|
||||
* @param string $conjunction
|
||||
*. The conunction AND|OR to use when checking permssions.
|
||||
* The conjunction AND|OR to use when checking permissions.
|
||||
*
|
||||
* @return bool
|
||||
* 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');
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function permissions() {
|
||||
$permissions = array(
|
||||
'assign domain editors' => array(
|
||||
$permissions = [
|
||||
'assign domain editors' => [
|
||||
'title' => $this->t('Assign additional editors to assigned domains'),
|
||||
'restrict access' => TRUE,
|
||||
),
|
||||
'assign editors to any domain' => array(
|
||||
],
|
||||
'assign editors to any domain' => [
|
||||
'title' => $this->t('Assign additional editors to any domains'),
|
||||
'restrict access' => TRUE,
|
||||
),
|
||||
'publish to any domain' => array(
|
||||
],
|
||||
'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'),
|
||||
),
|
||||
'create domain content' => array(
|
||||
],
|
||||
'create domain content' => [
|
||||
'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'),
|
||||
),
|
||||
'delete domain content' => array(
|
||||
],
|
||||
'delete domain content' => [
|
||||
'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'),
|
||||
'restrict access' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Generate standard node permissions for all applicable node types.
|
||||
foreach (NodeType::loadMultiple() as $type) {
|
||||
@@ -59,7 +59,7 @@ class DomainAccessPermissions {
|
||||
*
|
||||
* Shamelessly lifted from node_list_permissions().
|
||||
*
|
||||
* @param NodeType $type
|
||||
* @param \Drupal\node\Entity\NodeType $type
|
||||
* The node type object.
|
||||
*
|
||||
* @return array
|
||||
@@ -68,17 +68,17 @@ class DomainAccessPermissions {
|
||||
private function nodePermissions(NodeType $type) {
|
||||
// Build standard list of node permissions for this type.
|
||||
$id = $type->id();
|
||||
$perms = array(
|
||||
"create $id content on assigned domains" => array(
|
||||
'title' => $this->t('%type_name: Create new content on assigned domains', array('%type_name' => $type->label())),
|
||||
),
|
||||
"update $id content on assigned domains" => array(
|
||||
'title' => $this->t('%type_name: Edit any content on assigned domains', array('%type_name' => $type->label())),
|
||||
),
|
||||
"delete $id content on assigned domains" => array(
|
||||
'title' => $this->t('%type_name: Delete any content on assigned domains', array('%type_name' => $type->label())),
|
||||
),
|
||||
);
|
||||
$perms = [
|
||||
"create $id content on assigned domains" => [
|
||||
'title' => $this->t('%type_name: Create new content on assigned domains', ['%type_name' => $type->label()]),
|
||||
],
|
||||
"update $id content on assigned domains" => [
|
||||
'title' => $this->t('%type_name: Edit any content on assigned domains', ['%type_name' => $type->label()]),
|
||||
],
|
||||
"delete $id content on assigned domains" => [
|
||||
'title' => $this->t('%type_name: Delete any content on assigned domains', ['%type_name' => $type->label()]),
|
||||
],
|
||||
];
|
||||
|
||||
return $perms;
|
||||
}
|
||||
|
||||
+21
-8
@@ -1,15 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Settings form for Domain Access.
|
||||
*/
|
||||
|
||||
namespace Drupal\domain_access\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class DomainAccessSettingsForm.
|
||||
*
|
||||
* @package Drupal\domain_access\Form
|
||||
*/
|
||||
class DomainAccessSettingsForm extends ConfigFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -29,12 +31,23 @@ class DomainAccessSettingsForm extends ConfigFormBase {
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('domain_access.settings');
|
||||
$form['node_advanced_tab'] = array(
|
||||
$form['node_advanced_tab'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Move Domain Access fields to advanced node settings.'),
|
||||
'#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.'),
|
||||
);
|
||||
];
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -43,11 +56,11 @@ class DomainAccessSettingsForm extends ConfigFormBase {
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$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();
|
||||
|
||||
parent::submitForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -48,23 +48,23 @@ abstract class DomainAccessActionBase extends ConfigurableActionBase implements
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'domain_id' => '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadOptionsList();
|
||||
$form['domain_id'] = array(
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadOptionsList();
|
||||
$form['domain_id'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Domain'),
|
||||
'#options' => $domains,
|
||||
'#default_value' => $this->configuration['id'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ class DomainAccessRemove extends DomainAccessActionBase {
|
||||
public function execute($entity = NULL) {
|
||||
$id = $this->configuration['domain_id'];
|
||||
$node_domains = \Drupal::service('domain_access.manager')->getAccessValues($entity);
|
||||
|
||||
|
||||
// Remove domain assignment if present.
|
||||
if ($entity !== FALSE && isset($node_domains[$id])) {
|
||||
unset($node_domains[$id]);
|
||||
|
||||
+7
-6
@@ -4,17 +4,14 @@ namespace Drupal\domain_access\Plugin\views\access;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Drupal\domain\DomainInterface;
|
||||
use Drupal\domain\DomainStorageInterface;
|
||||
use Drupal\domain_access\DomainAccessManagerInterface;
|
||||
use Drupal\user\UserStorageInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $permission = 'publish to any assigned domain';
|
||||
|
||||
/**
|
||||
* Sets the permission to use when checking all access.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $allPermission = 'publish to any domain';
|
||||
|
||||
@@ -71,11 +72,11 @@ class DomainAccessContent extends AccessPluginBase implements CacheableDependenc
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param DomainStorageInterface $domain_storage
|
||||
* @param \Drupal\domain\DomainStorageInterface $domain_storage
|
||||
* The domain storage service.
|
||||
* @param UserStorageInterface $user_storage
|
||||
* @param \Drupal\user\UserStorageInterface $user_storage
|
||||
* The user storage service.
|
||||
* @param DomainAccessManagerInterface $manager
|
||||
* @param \Drupal\domain_access\DomainAccessManagerInterface $manager
|
||||
* The domain access manager service.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $permission = 'assign domain editors';
|
||||
|
||||
/**
|
||||
* Sets the permission to use when checking all access.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $allPermission = 'assign editors to any domain';
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ class DomainAccessArgument extends StringArgument {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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 parent::title();
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ class DomainAccessField extends Field {
|
||||
$item['rendered']['#type'] = 'markup';
|
||||
$item['rendered']['#markup'] = '<a href="' . $domain->buildUrl($url) . '">' . $domain->label() . '</a>';
|
||||
}
|
||||
uasort($items, array($this, 'sort'));
|
||||
uasort($items, [$this, 'sort']);
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
+2
-2
@@ -27,14 +27,14 @@ class DomainAccessCurrentAllFilter extends BooleanOperator {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
protected function operators() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ class DomainAccessFilter extends InOperator {
|
||||
// @TODO: filter this list.
|
||||
if (!isset($this->valueOptions)) {
|
||||
$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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -11,8 +11,8 @@ dependencies:
|
||||
- domain_access
|
||||
- taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-08
|
||||
version: '8.x-1.0-alpha13'
|
||||
# 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: 1520519900
|
||||
datestamp: 1542230887
|
||||
|
||||
+6
-6
@@ -16,19 +16,19 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function testDomainAccessAllField() {
|
||||
$label = 'Send to all affiliates';
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Visit the article field administration page.
|
||||
@@ -51,14 +51,14 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
||||
*/
|
||||
public function testDomainAccessAllFieldStorage() {
|
||||
$label = 'Send to all affiliates';
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
'publish to any domain',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Create 5 domains.
|
||||
@@ -72,7 +72,7 @@ class DomainAccessAllAffiliatesTest extends DomainTestBase {
|
||||
$this->assertText($label, 'Found the domain field instance.');
|
||||
|
||||
// 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) {
|
||||
$string = 'value="' . $domain->id() . '"';
|
||||
$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
|
||||
*/
|
||||
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().
|
||||
*/
|
||||
public function testDomainAccessDefaultValue() {
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
'publish to any domain',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Create 5 domains.
|
||||
@@ -68,10 +68,10 @@ class DomainAccessDefaultValueTest extends DomainTestBase {
|
||||
$this->drupalLogout();
|
||||
|
||||
// Create a limited value user.
|
||||
$this->test_user = $this->drupalCreateUser(array(
|
||||
$this->test_user = $this->drupalCreateUser([
|
||||
'create article content',
|
||||
'edit any article content',
|
||||
));
|
||||
]);
|
||||
|
||||
// Login and try to edit the created node.
|
||||
$this->drupalLogin($this->test_user);
|
||||
|
||||
+31
-10
@@ -16,7 +16,13 @@ class DomainAccessElementTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
||||
public static $modules = [
|
||||
'domain',
|
||||
'domain_access',
|
||||
'field',
|
||||
'field_ui',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -29,27 +35,36 @@ class DomainAccessElementTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test setup.
|
||||
* Test runner.
|
||||
*/
|
||||
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',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
'publish to any domain',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->drupalGet('node/add/' . $node_type);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Set the title, so the node can be saved.
|
||||
$this->fillField('title[0][value]', 'Test node');
|
||||
|
||||
// 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;
|
||||
$ids = ['example_com', 'one_example_com', 'two_example_com'];
|
||||
foreach ($domains as $domain) {
|
||||
@@ -70,8 +85,10 @@ class DomainAccessElementTest extends DomainTestBase {
|
||||
$this->pressButton('edit-submit');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Get node data. Note that we create one new node for each test case.
|
||||
$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.
|
||||
$manager = \Drupal::service('domain_access.manager');
|
||||
$values = $manager->getAccessValues($node);
|
||||
@@ -80,7 +97,11 @@ class DomainAccessElementTest extends DomainTestBase {
|
||||
$this->assert($value == 1, 'Node saved to all affiliates.');
|
||||
|
||||
// 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'];
|
||||
$this->addDomainsToEntity('user', $account->id(), $ids, DOMAIN_ACCESS_FIELD);
|
||||
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
||||
@@ -118,8 +139,8 @@ class DomainAccessElementTest extends DomainTestBase {
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Now, check the node.
|
||||
$storage->resetCache(array($node->id()));
|
||||
$node = $storage->load(1);
|
||||
$storage->resetCache([$node->id()]);
|
||||
$node = $storage->load($node->id());
|
||||
// Check that two values are set.
|
||||
$values = $manager->getAccessValues($node);
|
||||
$this->assert(count($values) == 2, 'Node saved with two domain records.');
|
||||
|
||||
+13
-5
@@ -17,7 +17,15 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
||||
*
|
||||
* @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}
|
||||
@@ -35,13 +43,13 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
||||
public function testDomainAccessEntityFields() {
|
||||
$label = 'Send to all affiliates';
|
||||
// Create a vocabulary.
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', [
|
||||
'name' => 'Domain vocabulary',
|
||||
'description' => 'Test taxonomy for Domain Access',
|
||||
'vid' => 'domain_access',
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'weight' => 100,
|
||||
));
|
||||
]);
|
||||
$vocabulary->save();
|
||||
$text['taxonomy_term'] = [
|
||||
'name' => 'term',
|
||||
@@ -49,7 +57,7 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
||||
'description' => 'Make this term available on all domains.',
|
||||
];
|
||||
domain_access_confirm_fields('taxonomy_term', 'domain_access', $text);
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
@@ -59,7 +67,7 @@ class DomainAccessEntityFieldTest extends DomainTestBase {
|
||||
'administer taxonomy',
|
||||
'administer taxonomy_term fields',
|
||||
'administer taxonomy_term form display',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/domain_access/overview/fields');
|
||||
$this->assertResponse(200, 'Manage fields page accessed.');
|
||||
|
||||
+6
-6
@@ -16,18 +16,18 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function testDomainAccessNodeField() {
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Visit the article field administration page.
|
||||
@@ -49,14 +49,14 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
||||
* Tests the storage of the domain access field.
|
||||
*/
|
||||
public function testDomainAccessFieldStorage() {
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
$this->admin_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'administer domains',
|
||||
'publish to any domain',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Create 5 domains.
|
||||
@@ -70,7 +70,7 @@ class DomainAccessEntityReferenceTest extends DomainTestBase {
|
||||
$this->assertText('Domain Access', 'Found the domain field instance.');
|
||||
|
||||
// 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) {
|
||||
$string = 'value="' . $domain->id() . '"';
|
||||
$this->assertRaw($string, 'Found the domain option.');
|
||||
|
||||
+18
-12
@@ -17,7 +17,13 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('domain', 'domain_access', 'field', 'field_ui', 'user');
|
||||
public static $modules = [
|
||||
'domain',
|
||||
'domain_access',
|
||||
'field',
|
||||
'field_ui',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -44,7 +50,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
$this->assertResponse(200, 'Article creation found.');
|
||||
|
||||
// Check for the form options.
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
foreach ($domains as $domain) {
|
||||
$this->assertText($domain->label(), 'Domain form item found.');
|
||||
}
|
||||
@@ -72,7 +78,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
$this->assertNoText($label, 'All affiliates field not found.');
|
||||
|
||||
// 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);
|
||||
|
||||
// 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 save will fail with an EntityStorageException until
|
||||
// https://www.drupal.org/node/2609252 is fixed.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
||||
@@ -99,7 +105,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
$this->assertTrue($node, 'Node found in database.');
|
||||
|
||||
// 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);
|
||||
|
||||
// Visit the account creation page.
|
||||
@@ -112,7 +118,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// 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);
|
||||
$this->addDomainsToEntity('user', $user5->id(), $active_domain, DOMAIN_ACCESS_FIELD);
|
||||
$this->drupalLogin($user5);
|
||||
@@ -132,7 +138,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// Test a user who can access no domain settings.
|
||||
$user6 = $this->drupalCreateUser(array('administer users'));
|
||||
$user6 = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($user6);
|
||||
|
||||
// Visit the account creation page.
|
||||
@@ -145,7 +151,7 @@ class DomainAccessFieldTest extends DomainTestBase {
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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.');
|
||||
|
||||
// Check for the form options.
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
foreach ($domains as $domain) {
|
||||
$this->assertText($domain->label(), 'Domain form item found.');
|
||||
}
|
||||
$this->assertText($label, 'All affiliates field found.');
|
||||
|
||||
// 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);
|
||||
|
||||
$user_edit_page = 'user/' . $user8->id() . '/edit';
|
||||
$this->drupalGet($user_edit_page);
|
||||
// Check for the form options.
|
||||
$domains = \Drupal::service('entity_type.manager')->getStorage('domain')->loadMultiple();
|
||||
$domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
|
||||
foreach ($domains as $domain) {
|
||||
$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.');
|
||||
|
||||
// Change own username.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
|
||||
$this->drupalPostForm($user_edit_page, $edit, t('Save'));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user