diff --git a/composer.json b/composer.json index 70a7fd0dd52155dbede892b42fa6f14ad46ec0bd..573c174a4abb541c12510ccbad15856edad65b8a 100644 --- a/composer.json +++ b/composer.json @@ -114,7 +114,6 @@ "drupal/dropzonejs": "2.8", "drupal/editor_advanced_link": "1.9", "drupal/embed": "1.6", - "drupal/entity": "1.2", "drupal/entity_browser": "2.9", "drupal/entity_clone": "^2.0.0", "drupal/entity_embed": "1.3", diff --git a/composer.lock b/composer.lock index 7d3f9816104f22c0d2df78cac65b04e346c62569..5e0bad6fa6cd2ce1ee3bae60cd64d579cb9648f3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e7563b426a09017f8207d3ccff7d6732", + "content-hash": "a45b11c7b0d2acfdd244a1febdad8693", "packages": [ { "name": "alchemy/zippy", @@ -1416,25 +1416,29 @@ }, { "name": "doctrine/deprecations", - "version": "v1.0.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -1453,9 +1457,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, - "time": "2022-05-02T15:47:09+00:00" + "time": "2023-06-03T09:27:29+00:00" }, { "name": "doctrine/lexer", @@ -3781,74 +3785,6 @@ "source": "https://git.drupalcode.org/project/embed" } }, - { - "name": "drupal/entity", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://git.drupalcode.org/project/entity.git", - "reference": "8.x-1.2" - }, - "dist": { - "type": "zip", - "url": "https://ftp.drupal.org/files/projects/entity-8.x-1.2.zip", - "reference": "8.x-1.2", - "shasum": "7e7cb12ea65d9f986b59935eda316387cf511079" - }, - "require": { - "drupal/core": "^8.8 || ^9" - }, - "type": "drupal-module", - "extra": { - "drupal": { - "version": "8.x-1.2", - "datestamp": "1606399149", - "security-coverage": { - "status": "covered", - "message": "Covered by Drupal's security advisory policy" - } - } - }, - "notification-url": "https://packages.drupal.org/8/downloads", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "Berdir", - "homepage": "https://www.drupal.org/user/214652" - }, - { - "name": "bojanz", - "homepage": "https://www.drupal.org/user/86106" - }, - { - "name": "dawehner", - "homepage": "https://www.drupal.org/user/99340" - }, - { - "name": "dixon_", - "homepage": "https://www.drupal.org/user/239911" - }, - { - "name": "fago", - "homepage": "https://www.drupal.org/user/16747" - }, - { - "name": "mglaman", - "homepage": "https://www.drupal.org/user/2416470" - }, - { - "name": "TR", - "homepage": "https://www.drupal.org/user/202830" - } - ], - "description": "Provides expanded entity APIs, which will be moved to Drupal core one day.", - "homepage": "http://drupal.org/project/entity", - "support": { - "source": "https://git.drupalcode.org/project/entity" - } - }, { "name": "drupal/entity_browser", "version": "2.9.0", @@ -8627,16 +8563,16 @@ }, { "name": "egulias/email-validator", - "version": "3.2.5", + "version": "3.2.6", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "b531a2311709443320c786feb4519cfaf94af796" + "reference": "e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/b531a2311709443320c786feb4519cfaf94af796", - "reference": "b531a2311709443320c786feb4519cfaf94af796", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7", + "reference": "e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7", "shasum": "" }, "require": { @@ -8682,7 +8618,7 @@ ], "support": { "issues": "https://github.com/egulias/EmailValidator/issues", - "source": "https://github.com/egulias/EmailValidator/tree/3.2.5" + "source": "https://github.com/egulias/EmailValidator/tree/3.2.6" }, "funding": [ { @@ -8690,7 +8626,7 @@ "type": "github" } ], - "time": "2023-01-02T17:26:14+00:00" + "time": "2023-06-01T07:04:22+00:00" }, { "name": "enlightn/security-checker", @@ -16085,16 +16021,16 @@ }, { "name": "symfony/var-dumper", - "version": "v5.4.23", + "version": "v5.4.25", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "9a8a5b6d6508928174ded2109e29328a55342a42" + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/9a8a5b6d6508928174ded2109e29328a55342a42", - "reference": "9a8a5b6d6508928174ded2109e29328a55342a42", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/82269f73c0f0f9859ab9b6900eebacbe54954ede", + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede", "shasum": "" }, "require": { @@ -16103,7 +16039,6 @@ "symfony/polyfill-php80": "^1.16" }, "conflict": { - "phpunit/phpunit": "<5.4.3", "symfony/console": "<4.4" }, "require-dev": { @@ -16154,7 +16089,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v5.4.23" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.25" }, "funding": [ { @@ -16170,7 +16105,7 @@ "type": "tidelift" } ], - "time": "2023-04-18T09:26:27+00:00" + "time": "2023-06-20T20:56:26+00:00" }, { "name": "symfony/var-exporter", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 2cbb06db5d41e8612ab66c49a2262581812749bb..fb52be67a0f93cfbb35c7ae1fe5ccd617667a79a 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1461,31 +1461,35 @@ }, { "name": "doctrine/deprecations", - "version": "v1.0.0", - "version_normalized": "1.0.0.0", + "version": "v1.1.1", + "version_normalized": "1.1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" }, - "time": "2022-05-02T15:47:09+00:00", + "time": "2023-06-03T09:27:29+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -1501,7 +1505,7 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, "install-path": "../doctrine/deprecations" }, @@ -3911,73 +3915,6 @@ }, "install-path": "../../web/modules/embed" }, - { - "name": "drupal/entity", - "version": "1.2.0", - "version_normalized": "1.2.0.0", - "source": { - "type": "git", - "url": "https://git.drupalcode.org/project/entity.git", - "reference": "8.x-1.2" - }, - "dist": { - "type": "zip", - "url": "https://ftp.drupal.org/files/projects/entity-8.x-1.2.zip", - "reference": "8.x-1.2", - "shasum": "7e7cb12ea65d9f986b59935eda316387cf511079" - }, - "require": { - "drupal/core": "^8.8 || ^9" - }, - "type": "drupal-module", - "extra": { - "drupal": { - "version": "8.x-1.2", - "datestamp": "1606399149", - "security-coverage": { - "status": "covered", - "message": "Covered by Drupal's security advisory policy" - } - } - }, - "installation-source": "dist", - "notification-url": "https://packages.drupal.org/8/downloads", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "Berdir", - "homepage": "https://www.drupal.org/user/214652" - }, - { - "name": "bojanz", - "homepage": "https://www.drupal.org/user/86106" - }, - { - "name": "dawehner", - "homepage": "https://www.drupal.org/user/99340" - }, - { - "name": "dixon_", - "homepage": "https://www.drupal.org/user/239911" - }, - { - "name": "fago", - "homepage": "https://www.drupal.org/user/16747" - }, - { - "name": "mglaman", - "homepage": "https://www.drupal.org/user/2416470" - } - ], - "description": "Provides expanded entity APIs, which will be moved to Drupal core one day.", - "homepage": "http://drupal.org/project/entity", - "support": { - "source": "https://git.drupalcode.org/project/entity" - }, - "install-path": "../../web/modules/entity" - }, { "name": "drupal/entity_browser", "version": "2.9.0", @@ -8947,17 +8884,17 @@ }, { "name": "egulias/email-validator", - "version": "3.2.5", - "version_normalized": "3.2.5.0", + "version": "3.2.6", + "version_normalized": "3.2.6.0", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "b531a2311709443320c786feb4519cfaf94af796" + "reference": "e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/b531a2311709443320c786feb4519cfaf94af796", - "reference": "b531a2311709443320c786feb4519cfaf94af796", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7", + "reference": "e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7", "shasum": "" }, "require": { @@ -8972,7 +8909,7 @@ "suggest": { "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" }, - "time": "2023-01-02T17:26:14+00:00", + "time": "2023-06-01T07:04:22+00:00", "type": "library", "extra": { "branch-alias": { @@ -9005,7 +8942,7 @@ ], "support": { "issues": "https://github.com/egulias/EmailValidator/issues", - "source": "https://github.com/egulias/EmailValidator/tree/3.2.5" + "source": "https://github.com/egulias/EmailValidator/tree/3.2.6" }, "funding": [ { @@ -16689,17 +16626,17 @@ }, { "name": "symfony/var-dumper", - "version": "v5.4.23", - "version_normalized": "5.4.23.0", + "version": "v5.4.25", + "version_normalized": "5.4.25.0", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "9a8a5b6d6508928174ded2109e29328a55342a42" + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/9a8a5b6d6508928174ded2109e29328a55342a42", - "reference": "9a8a5b6d6508928174ded2109e29328a55342a42", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/82269f73c0f0f9859ab9b6900eebacbe54954ede", + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede", "shasum": "" }, "require": { @@ -16708,7 +16645,6 @@ "symfony/polyfill-php80": "^1.16" }, "conflict": { - "phpunit/phpunit": "<5.4.3", "symfony/console": "<4.4" }, "require-dev": { @@ -16723,7 +16659,7 @@ "ext-intl": "To show region name in time zone dump", "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" }, - "time": "2023-04-18T09:26:27+00:00", + "time": "2023-06-20T20:56:26+00:00", "bin": [ "Resources/bin/var-dump-server" ], @@ -16761,7 +16697,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v5.4.23" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.25" }, "funding": [ { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index c11be1243039d62536daf0b33c90c3305c848473..5f90d65f6d73aa48af3875cac8113056440a1fc1 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'osu-asc-webservices/d8-upstream', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '8322ffc7651bab972d71fa671738ac3969b0eb9b', + 'reference' => '467f19657ab91922f4980095ea79aed35fa6633d', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -236,9 +236,9 @@ 'dev_requirement' => false, ), 'doctrine/deprecations' => array( - 'pretty_version' => 'v1.0.0', - 'version' => '1.0.0.0', - 'reference' => '0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de', + 'pretty_version' => 'v1.1.1', + 'version' => '1.1.1.0', + 'reference' => '612a3ee5ab0d5dd97b7cf3874a6efe24325efac3', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/deprecations', 'aliases' => array(), @@ -715,15 +715,6 @@ 'aliases' => array(), 'dev_requirement' => false, ), - 'drupal/entity' => array( - 'pretty_version' => '1.2.0', - 'version' => '1.2.0.0', - 'reference' => '8.x-1.2', - 'type' => 'drupal-module', - 'install_path' => __DIR__ . '/../../web/modules/entity', - 'aliases' => array(), - 'dev_requirement' => false, - ), 'drupal/entity_browser' => array( 'pretty_version' => '2.9.0', 'version' => '2.9.0.0', @@ -1400,9 +1391,9 @@ 'dev_requirement' => false, ), 'egulias/email-validator' => array( - 'pretty_version' => '3.2.5', - 'version' => '3.2.5.0', - 'reference' => 'b531a2311709443320c786feb4519cfaf94af796', + 'pretty_version' => '3.2.6', + 'version' => '3.2.6.0', + 'reference' => 'e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7', 'type' => 'library', 'install_path' => __DIR__ . '/../egulias/email-validator', 'aliases' => array(), @@ -1621,7 +1612,7 @@ 'osu-asc-webservices/d8-upstream' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '8322ffc7651bab972d71fa671738ac3969b0eb9b', + 'reference' => '467f19657ab91922f4980095ea79aed35fa6633d', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -2523,9 +2514,9 @@ 'dev_requirement' => false, ), 'symfony/var-dumper' => array( - 'pretty_version' => 'v5.4.23', - 'version' => '5.4.23.0', - 'reference' => '9a8a5b6d6508928174ded2109e29328a55342a42', + 'pretty_version' => 'v5.4.25', + 'version' => '5.4.25.0', + 'reference' => '82269f73c0f0f9859ab9b6900eebacbe54954ede', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/var-dumper', 'aliases' => array(), diff --git a/vendor/doctrine/deprecations/README.md b/vendor/doctrine/deprecations/README.md index 22f0cced3e65712d5f62b41f931ee15b15b138ab..93caf83f821755f39bea54026d4cc52b9e5976ae 100644 --- a/vendor/doctrine/deprecations/README.md +++ b/vendor/doctrine/deprecations/README.md @@ -19,13 +19,16 @@ Enable Doctrine deprecations to be sent to a PSR3 logger: ``` Enable Doctrine deprecations to be sent as `@trigger_error($message, E_USER_DEPRECATED)` -messages. +messages by setting the `DOCTRINE_DEPRECATIONS` environment variable to `trigger`. +Alternatively, call: ```php \Doctrine\Deprecations\Deprecation::enableWithTriggerError(); ``` -If you only want to enable deprecation tracking, without logging or calling `trigger_error` then call: +If you only want to enable deprecation tracking, without logging or calling `trigger_error` +then set the `DOCTRINE_DEPRECATIONS` environment variable to `track`. +Alternatively, call: ```php \Doctrine\Deprecations\Deprecation::enableTrackingDeprecations(); diff --git a/vendor/doctrine/deprecations/composer.json b/vendor/doctrine/deprecations/composer.json index c79e38cdcd41e75faf3a0a56bc7b6d7922701fee..f8319f9a2a113c7c192271378ead2efe8d39db66 100644 --- a/vendor/doctrine/deprecations/composer.json +++ b/vendor/doctrine/deprecations/composer.json @@ -1,22 +1,28 @@ { "name": "doctrine/deprecations", - "type": "library", "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", - "homepage": "https://www.doctrine-project.org/", "license": "MIT", + "type": "library", + "homepage": "https://www.doctrine-project.org/", "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3", - "doctrine/coding-standard": "^9" + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" }, "autoload": { - "psr-4": {"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"} + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } }, "autoload-dev": { "psr-4": { diff --git a/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php b/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php index 1029372faa62b61f0244bd9de2389ff63c64309e..07cb43b6ce30e97dd9f0d927bd0d6abfe8976da2 100644 --- a/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php +++ b/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php @@ -8,6 +8,7 @@ use function array_key_exists; use function array_reduce; +use function assert; use function debug_backtrace; use function sprintf; use function strpos; @@ -46,8 +47,8 @@ class Deprecation private const TYPE_TRIGGER_ERROR = 2; private const TYPE_PSR_LOGGER = 4; - /** @var int */ - private static $type = self::TYPE_NONE; + /** @var int-mask-of<self::TYPE_*>|null */ + private static $type; /** @var LoggerInterface|null */ private static $logger; @@ -56,6 +57,9 @@ class Deprecation private static $ignoredPackages = []; /** @var array<string,int> */ + private static $triggeredDeprecations = []; + + /** @var array<string,bool> */ private static $ignoredLinks = []; /** @var bool */ @@ -68,21 +72,27 @@ class Deprecation * deprecation. It is additionally used to de-duplicate the trigger of the * same deprecation during a request. * - * @param mixed $args + * @param float|int|string $args */ public static function trigger(string $package, string $link, string $message, ...$args): void { - if (self::$type === self::TYPE_NONE) { + $type = self::$type ?? self::getTypeFromEnv(); + + if ($type === self::TYPE_NONE) { + return; + } + + if (isset(self::$ignoredLinks[$link])) { return; } - if (array_key_exists($link, self::$ignoredLinks)) { - self::$ignoredLinks[$link]++; + if (array_key_exists($link, self::$triggeredDeprecations)) { + self::$triggeredDeprecations[$link]++; } else { - self::$ignoredLinks[$link] = 1; + self::$triggeredDeprecations[$link] = 1; } - if (self::$deduplication === true && self::$ignoredLinks[$link] > 1) { + if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) { return; } @@ -114,18 +124,20 @@ public static function trigger(string $package, string $link, string $message, . * deprecation tracking is enabled even during deduplication, because it * needs to call {@link debug_backtrace()} * - * @param mixed $args + * @param float|int|string $args */ public static function triggerIfCalledFromOutside(string $package, string $link, string $message, ...$args): void { - if (self::$type === self::TYPE_NONE) { + $type = self::$type ?? self::getTypeFromEnv(); + + if ($type === self::TYPE_NONE) { return; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); // first check that the caller is not from a tests folder, in which case we always let deprecations pass - if (strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) { + if (isset($backtrace[1]['file'], $backtrace[0]['file']) && strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) { $path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR; if (strpos($backtrace[0]['file'], $path) === false) { @@ -137,13 +149,17 @@ public static function triggerIfCalledFromOutside(string $package, string $link, } } - if (array_key_exists($link, self::$ignoredLinks)) { - self::$ignoredLinks[$link]++; + if (isset(self::$ignoredLinks[$link])) { + return; + } + + if (array_key_exists($link, self::$triggeredDeprecations)) { + self::$triggeredDeprecations[$link]++; } else { - self::$ignoredLinks[$link] = 1; + self::$triggeredDeprecations[$link] = 1; } - if (self::$deduplication === true && self::$ignoredLinks[$link] > 1) { + if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) { return; } @@ -157,31 +173,35 @@ public static function triggerIfCalledFromOutside(string $package, string $link, } /** - * @param array<mixed> $backtrace + * @param list<array{function: string, line?: int, file?: string, class?: class-string, type?: string, args?: mixed[], object?: object}> $backtrace */ private static function delegateTriggerToBackend(string $message, array $backtrace, string $link, string $package): void { - if ((self::$type & self::TYPE_PSR_LOGGER) > 0) { + $type = self::$type ?? self::getTypeFromEnv(); + + if (($type & self::TYPE_PSR_LOGGER) > 0) { $context = [ - 'file' => $backtrace[0]['file'], - 'line' => $backtrace[0]['line'], + 'file' => $backtrace[0]['file'] ?? null, + 'line' => $backtrace[0]['line'] ?? null, 'package' => $package, 'link' => $link, ]; + assert(self::$logger !== null); + self::$logger->notice($message, $context); } - if (! ((self::$type & self::TYPE_TRIGGER_ERROR) > 0)) { + if (! (($type & self::TYPE_TRIGGER_ERROR) > 0)) { return; } $message .= sprintf( ' (%s:%d called by %s:%d, %s, package %s)', - self::basename($backtrace[0]['file']), - $backtrace[0]['line'], - self::basename($backtrace[1]['file']), - $backtrace[1]['line'], + self::basename($backtrace[0]['file'] ?? 'native code'), + $backtrace[0]['line'] ?? 0, + self::basename($backtrace[1]['file'] ?? 'native code'), + $backtrace[1]['line'] ?? 0, $link, $package ); @@ -205,16 +225,19 @@ private static function basename(string $filename): string public static function enableTrackingDeprecations(): void { + self::$type = self::$type ?? 0; self::$type |= self::TYPE_TRACK_DEPRECATIONS; } public static function enableWithTriggerError(): void { + self::$type = self::$type ?? 0; self::$type |= self::TYPE_TRIGGER_ERROR; } public static function enableWithPsrLogger(LoggerInterface $logger): void { + self::$type = self::$type ?? 0; self::$type |= self::TYPE_PSR_LOGGER; self::$logger = $logger; } @@ -229,9 +252,10 @@ public static function disable(): void self::$type = self::TYPE_NONE; self::$logger = null; self::$deduplication = true; + self::$ignoredLinks = []; - foreach (self::$ignoredLinks as $link => $count) { - self::$ignoredLinks[$link] = 0; + foreach (self::$triggeredDeprecations as $link => $count) { + self::$triggeredDeprecations[$link] = 0; } } @@ -243,13 +267,13 @@ public static function ignorePackage(string $packageName): void public static function ignoreDeprecations(string ...$links): void { foreach ($links as $link) { - self::$ignoredLinks[$link] = 0; + self::$ignoredLinks[$link] = true; } } public static function getUniqueTriggeredDeprecationsCount(): int { - return array_reduce(self::$ignoredLinks, static function (int $carry, int $count) { + return array_reduce(self::$triggeredDeprecations, static function (int $carry, int $count) { return $carry + $count; }, 0); } @@ -261,6 +285,28 @@ public static function getUniqueTriggeredDeprecationsCount(): int */ public static function getTriggeredDeprecations(): array { - return self::$ignoredLinks; + return self::$triggeredDeprecations; + } + + /** + * @return int-mask-of<self::TYPE_*> + */ + private static function getTypeFromEnv(): int + { + switch ($_SERVER['DOCTRINE_DEPRECATIONS'] ?? $_ENV['DOCTRINE_DEPRECATIONS'] ?? null) { + case 'trigger': + self::$type = self::TYPE_TRIGGER_ERROR; + break; + + case 'track': + self::$type = self::TYPE_TRACK_DEPRECATIONS; + break; + + default: + self::$type = self::TYPE_NONE; + break; + } + + return self::$type; } } diff --git a/vendor/doctrine/deprecations/phpstan.neon b/vendor/doctrine/deprecations/phpstan.neon new file mode 100644 index 0000000000000000000000000000000000000000..4ee286b8a779691c0ccd5a75f2776e169e63210c --- /dev/null +++ b/vendor/doctrine/deprecations/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: 6 + paths: + - lib + - tests + +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/vendor/doctrine/deprecations/psalm.xml b/vendor/doctrine/deprecations/psalm.xml new file mode 100644 index 0000000000000000000000000000000000000000..ad76e32e3c87ea485a23721e6ed785a6826f560f --- /dev/null +++ b/vendor/doctrine/deprecations/psalm.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<psalm + errorLevel="1" + resolveFromConfigFile="true" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="https://getpsalm.org/schema/config" + xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + findUnusedBaselineEntry="true" + findUnusedCode="false" +> + <projectFiles> + <directory name="lib/Doctrine/Deprecations" /> + <directory name="tests/Doctrine/Deprecations" /> + <ignoreFiles> + <directory name="vendor" /> + </ignoreFiles> + </projectFiles> + <plugins> + <pluginClass class="Psalm\PhpUnitPlugin\Plugin"/> + </plugins> + <issueHandlers> + <DeprecatedMethod> + <errorLevel type="suppress"> + <!-- Remove when dropping support for PHPUnit 9.6 --> + <referencedMethod name="PHPUnit\Framework\TestCase::expectDeprecation"/> + <referencedMethod name="PHPUnit\Framework\TestCase::expectDeprecationMessage"/> + </errorLevel> + </DeprecatedMethod> + </issueHandlers> +</psalm> diff --git a/vendor/egulias/email-validator/src/EmailLexer.php b/vendor/egulias/email-validator/src/EmailLexer.php index 6add6bd2b9e39e5fc28dc04cd3aab32e14b2796c..4099758ce5d2453e124f270c85ac7aee78f8f9af 100644 --- a/vendor/egulias/email-validator/src/EmailLexer.php +++ b/vendor/egulias/email-validator/src/EmailLexer.php @@ -213,13 +213,11 @@ public function find($type) : bool public function moveNext() : bool { if ($this->hasToRecord && $this->previous === self::$nullToken) { - $this->accumulator .= $this->token['value']; + $this->accumulator .= ((array) $this->token)['value']; } - $this->previous = $this->token instanceof Token - ? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position] - : $this->token; - + $this->previous = (array) $this->token; + if($this->lookahead === null) { $this->lookahead = self::$nullToken; } @@ -227,7 +225,7 @@ public function moveNext() : bool $hasNext = parent::moveNext(); if ($this->hasToRecord) { - $this->accumulator .= $this->token['value']; + $this->accumulator .= ((array) $this->token)['value']; } return $hasNext; diff --git a/vendor/egulias/email-validator/src/Parser.php b/vendor/egulias/email-validator/src/Parser.php index b1905f9abf9b34e3e1d283bbc24eb65a3c6e2cd3..4e5ac7d1f6da036b753936a4f89082c4b5017506 100644 --- a/vendor/egulias/email-validator/src/Parser.php +++ b/vendor/egulias/email-validator/src/Parser.php @@ -29,7 +29,7 @@ abstract protected function preLeftParsing() : Result; public function __construct(EmailLexer $lexer) { - $this->lexer = $lexer; + $this->lexer = $lexer; } public function parse(string $str) : Result @@ -51,7 +51,7 @@ public function parse(string $str) : Result return $localPartResult; } - $domainPartResult = $this->parseRightFromAt(); + $domainPartResult = $this->parseRightFromAt(); if ($domainPartResult->isInvalid()) { return $domainPartResult; @@ -73,6 +73,6 @@ protected function hasAtToken() : bool $this->lexer->moveNext(); $this->lexer->moveNext(); - return $this->lexer->token['type'] !== EmailLexer::S_AT; + return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT; } } diff --git a/vendor/egulias/email-validator/src/Parser/Comment.php b/vendor/egulias/email-validator/src/Parser/Comment.php index d6f3032fc3c66924854aad7ded9f7463cf6c1398..34ef97263de85675e17c8ea93760c481ef2df7e8 100644 --- a/vendor/egulias/email-validator/src/Parser/Comment.php +++ b/vendor/egulias/email-validator/src/Parser/Comment.php @@ -31,15 +31,15 @@ public function __construct(EmailLexer $lexer, CommentStrategy $commentStrategy) public function parse() : Result { - if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) { $this->openedParenthesis++; if($this->noClosingParenthesis()) { - return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); + return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']); } } - if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { - return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS) { + return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']); } $this->warnings[WarningComment::CODE] = new WarningComment(); @@ -58,10 +58,10 @@ public function parse() : Result } if($this->openedParenthesis >= 1) { - return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); + return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']); } if ($this->openedParenthesis < 0) { - return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); + return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']); } $finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer); @@ -78,7 +78,7 @@ public function parse() : Result private function warnEscaping() : bool { //Backslash found - if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { + if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) { return false; } @@ -87,12 +87,12 @@ private function warnEscaping() : bool } $this->warnings[QuotedPart::CODE] = - new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']); + new QuotedPart($this->lexer->getPrevious()['type'], ((array) $this->lexer->token)['type']); return true; } - private function noClosingParenthesis() : bool + private function noClosingParenthesis() : bool { try { $this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS); diff --git a/vendor/egulias/email-validator/src/Parser/CommentStrategy/DomainComment.php b/vendor/egulias/email-validator/src/Parser/CommentStrategy/DomainComment.php index cbbe3f201b0fe1dc3c79924e1090b74c375c4c3e..17b686be1c6c72218c5cacd6da7c9d55e4fe0342 100644 --- a/vendor/egulias/email-validator/src/Parser/CommentStrategy/DomainComment.php +++ b/vendor/egulias/email-validator/src/Parser/CommentStrategy/DomainComment.php @@ -23,7 +23,7 @@ public function endOfLoopValidations(EmailLexer $lexer) : Result { //test for end of string if (!$lexer->isNextToken(EmailLexer::S_DOT)) { - return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), ((array) $lexer->token)['value']); } //add warning //Address is valid within the message but cannot be used unmodified for the envelope diff --git a/vendor/egulias/email-validator/src/Parser/CommentStrategy/LocalComment.php b/vendor/egulias/email-validator/src/Parser/CommentStrategy/LocalComment.php index e72319a215013ed93927fb217dbb4c9d849bce55..179802b8334db88ab4223d51a897be319545a134 100644 --- a/vendor/egulias/email-validator/src/Parser/CommentStrategy/LocalComment.php +++ b/vendor/egulias/email-validator/src/Parser/CommentStrategy/LocalComment.php @@ -24,7 +24,7 @@ public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool public function endOfLoopValidations(EmailLexer $lexer) : Result { if (!$lexer->isNextToken(EmailLexer::S_AT)) { - return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), $lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), ((array) $lexer->token)['value']); } $this->warnings[CFWSNearAt::CODE] = new CFWSNearAt(); return new ValidEmail(); diff --git a/vendor/egulias/email-validator/src/Parser/DomainLiteral.php b/vendor/egulias/email-validator/src/Parser/DomainLiteral.php index e6d66d0bd80fc88cfcead5571648a0b0fc87ea1e..10486346ad6000d8eb79a21a45b48a0883d1a181 100644 --- a/vendor/egulias/email-validator/src/Parser/DomainLiteral.php +++ b/vendor/egulias/email-validator/src/Parser/DomainLiteral.php @@ -39,14 +39,14 @@ public function parse() : Result $addressLiteral = ''; do { - if ($this->lexer->token['type'] === EmailLexer::C_NUL) { - return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) { + return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']); } $this->addObsoleteWarnings(); if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) { - return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']); } if ($this->lexer->isNextTokenAny( @@ -57,21 +57,21 @@ public function parse() : Result } if ($this->lexer->isNextToken(EmailLexer::S_CR)) { - return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']); + return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) { - return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH) { + return new InvalidEmail(new UnusualElements(((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_IPV6TAG) { $IPv6TAG = true; } - if ($this->lexer->token['type'] === EmailLexer::S_CLOSEBRACKET) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEBRACKET) { break; } - $addressLiteral .= $this->lexer->token['value']; + $addressLiteral .= ((array) $this->lexer->token)['value']; } while ($this->lexer->moveNext()); @@ -144,7 +144,7 @@ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) : void $this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated(); } } - + public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string { $matchesIP = []; @@ -189,7 +189,7 @@ protected function checkIPV4Tag($addressLiteral) : bool private function addObsoleteWarnings() : void { - if(in_array($this->lexer->token['type'], self::OBSOLETE_WARNINGS)) { + if(in_array(((array) $this->lexer->token)['type'], self::OBSOLETE_WARNINGS)) { $this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT(); } } diff --git a/vendor/egulias/email-validator/src/Parser/DomainPart.php b/vendor/egulias/email-validator/src/Parser/DomainPart.php index e1f5b3bef3e0606b1ccf1f3e62006e7e4756b97d..84a4180f3689a61e40a138cb1d90d912bf41314b 100644 --- a/vendor/egulias/email-validator/src/Parser/DomainPart.php +++ b/vendor/egulias/email-validator/src/Parser/DomainPart.php @@ -50,8 +50,8 @@ public function parse() : Result return $domainChecks; } - if ($this->lexer->token['type'] === EmailLexer::S_AT) { - return new InvalidEmail(new ConsecutiveAt(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_AT) { + return new InvalidEmail(new ConsecutiveAt(), ((array) $this->lexer->token)['value']); } $result = $this->doParseDomainPart(); @@ -69,7 +69,7 @@ public function parse() : Result $length = strlen($this->domainPart); if ($length > self::DOMAIN_MAX_LENGTH) { - return new InvalidEmail(new DomainTooLong(), $this->lexer->token['value']); + return new InvalidEmail(new DomainTooLong(), ((array) $this->lexer->token)['value']); } return new ValidEmail(); @@ -79,13 +79,13 @@ private function checkEndOfDomain() : Result { $prev = $this->lexer->getPrevious(); if ($prev['type'] === EmailLexer::S_DOT) { - return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']); + return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']); } if ($prev['type'] === EmailLexer::S_HYPHEN) { return new InvalidEmail(new DomainHyphened('Hypen found at the end of the domain'), $prev['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_SP) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_SP) { return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']); } return new ValidEmail(); @@ -98,13 +98,13 @@ private function performDomainStartChecks() : Result if ($invalidTokens->isInvalid()) { return $invalidTokens; } - + $missingDomain = $this->checkEmptyDomain(); if ($missingDomain->isInvalid()) { return $missingDomain; } - if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) { $this->warnings[DeprecatedComment::CODE] = new DeprecatedComment(); } return new ValidEmail(); @@ -112,12 +112,12 @@ private function performDomainStartChecks() : Result private function checkEmptyDomain() : Result { - $thereIsNoDomain = $this->lexer->token['type'] === EmailLexer::S_EMPTY || - ($this->lexer->token['type'] === EmailLexer::S_SP && + $thereIsNoDomain = ((array) $this->lexer->token)['type'] === EmailLexer::S_EMPTY || + (((array) $this->lexer->token)['type'] === EmailLexer::S_SP && !$this->lexer->isNextToken(EmailLexer::GENERIC)); if ($thereIsNoDomain) { - return new InvalidEmail(new NoDomainPart(), $this->lexer->token['value']); + return new InvalidEmail(new NoDomainPart(), ((array) $this->lexer->token)['value']); } return new ValidEmail(); @@ -125,11 +125,11 @@ private function checkEmptyDomain() : Result private function checkInvalidTokensAfterAT() : Result { - if ($this->lexer->token['type'] === EmailLexer::S_DOT) { - return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT) { + return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) { - return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN) { + return new InvalidEmail(new DomainHyphened('After AT'), ((array) $this->lexer->token)['value']); } return new ValidEmail(); } @@ -156,8 +156,8 @@ protected function doParseDomainPart() : Result return $notAllowedChars; } - if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS || - $this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS || + ((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { $hasComments = true; $commentsResult = $this->parseComments(); @@ -172,7 +172,7 @@ protected function doParseDomainPart() : Result return $dotsResult; } - if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET) { $literalResult = $this->parseDomainLiteral(); $this->addTLDWarnings($tldMissing); @@ -189,9 +189,9 @@ protected function doParseDomainPart() : Result return $FwsResult; } - $domain .= $this->lexer->token['value']; + $domain .= ((array) $this->lexer->token)['value']; - if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) { $tldMissing = false; } @@ -201,7 +201,7 @@ protected function doParseDomainPart() : Result } $this->lexer->moveNext(); - } while (null !== $this->lexer->token['type']); + } while (null !== ((array) $this->lexer->token)['type']); $labelCheck = $this->checkLabelLength(true); if ($labelCheck->isInvalid()) { @@ -219,8 +219,8 @@ protected function doParseDomainPart() : Result private function checkNotAllowedChars($token) : Result { $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; - if (isset($notAllowed[$token['type']])) { - return new InvalidEmail(new CharNotAllowed(), $token['value']); + if (isset($notAllowed[((array) $token)['type']])) { + return new InvalidEmail(new CharNotAllowed(), ((array) $token)['value']); } return new ValidEmail(); } @@ -233,7 +233,7 @@ protected function parseDomainLiteral() : Result try { $this->lexer->find(EmailLexer::S_CLOSEBRACKET); } catch (\RuntimeException $e) { - return new InvalidEmail(new ExpectingDomainLiteralClose(), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingDomainLiteralClose(), ((array) $this->lexer->token)['value']); } $domainLiteralParser = new DomainLiteralParser($this->lexer); @@ -244,17 +244,17 @@ protected function parseDomainLiteral() : Result protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result { - if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) { - return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) { + return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { - return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { + return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH + if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::GENERIC)) { - return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), ((array) $this->lexer->token)['value']); } return $this->validateTokens($hasComments); @@ -273,8 +273,8 @@ protected function validateTokens(bool $hasComments) : Result $validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true; } - if (!isset($validDomainTokens[$this->lexer->token['type']])) { - return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']); + if (!isset($validDomainTokens[((array) $this->lexer->token)['type']])) { + return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']); } return new ValidEmail(); @@ -282,13 +282,13 @@ protected function validateTokens(bool $hasComments) : Result private function checkLabelLength(bool $isEndOfDomain = false) : Result { - if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT || $isEndOfDomain) { if ($this->isLabelTooLong($this->label)) { - return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']); + return new InvalidEmail(new LabelTooLong(), ((array) $this->lexer->token)['value']); } $this->label = ''; } - $this->label .= $this->lexer->token['value']; + $this->label .= ((array) $this->lexer->token)['value']; return new ValidEmail(); } diff --git a/vendor/egulias/email-validator/src/Parser/DoubleQuote.php b/vendor/egulias/email-validator/src/Parser/DoubleQuote.php index b32e2b6b23afc612cd434f9b1bc7539d7cb0f410..d722292d4ea1dc07796d8ee98b76fd2aa7ae6a22 100644 --- a/vendor/egulias/email-validator/src/Parser/DoubleQuote.php +++ b/vendor/egulias/email-validator/src/Parser/DoubleQuote.php @@ -30,24 +30,24 @@ public function parse() : Result EmailLexer::S_CR => true, EmailLexer::S_LF => true ]; - + $setSpecialsWarning = true; $this->lexer->moveNext(); - while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) { - if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) { + while (((array) $this->lexer->token)['type'] !== EmailLexer::S_DQUOTE && null !== ((array) $this->lexer->token)['type']) { + if (isset($special[((array) $this->lexer->token)['type']]) && $setSpecialsWarning) { $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS(); $setSpecialsWarning = false; } - if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) { $this->lexer->moveNext(); } $this->lexer->moveNext(); - if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) { - return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']); + if (!$this->escaped() && isset($invalid[((array) $this->lexer->token)['type']])) { + return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']); } } @@ -59,7 +59,7 @@ public function parse() : Result } if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) { - return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']); } return new ValidEmail(); @@ -71,15 +71,15 @@ protected function checkDQUOTE() : Result if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) { $description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit'; - return new InvalidEmail(new ExpectingATEXT($description), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT($description), ((array) $this->lexer->token)['value']); } try { $this->lexer->find(EmailLexer::S_DQUOTE); } catch (\Exception $e) { - return new InvalidEmail(new UnclosedQuotedString(), $this->lexer->token['value']); + return new InvalidEmail(new UnclosedQuotedString(), ((array) $this->lexer->token)['value']); } - $this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], $this->lexer->token['value']); + $this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], ((array) $this->lexer->token)['value']); return new ValidEmail(); } diff --git a/vendor/egulias/email-validator/src/Parser/FoldingWhiteSpace.php b/vendor/egulias/email-validator/src/Parser/FoldingWhiteSpace.php index fff6ec3ef5b54e2948b0d4c9810ad4505686c298..be4b05b82f5c68b3aaf58ea06a9450a795b2f247 100644 --- a/vendor/egulias/email-validator/src/Parser/FoldingWhiteSpace.php +++ b/vendor/egulias/email-validator/src/Parser/FoldingWhiteSpace.php @@ -36,16 +36,16 @@ public function parse() : Result return $resultCRLF; } - if ($this->lexer->token['type'] === EmailLexer::S_CR) { - return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_CR) { + return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']); } if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) { - return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token['value']); + return new InvalidEmail(new AtextAfterCFWS(), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) { - return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_LF || ((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) { + return new InvalidEmail(new ExpectingCTEXT(), ((array) $this->lexer->token)['value']); } if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) { @@ -59,28 +59,28 @@ public function parse() : Result protected function checkCRLFInFWS() : Result { - if ($this->lexer->token['type'] !== EmailLexer::CRLF) { + if (((array) $this->lexer->token)['type'] !== EmailLexer::CRLF) { return new ValidEmail(); } if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) { - return new InvalidEmail(new CRLFX2(), $this->lexer->token['value']); + return new InvalidEmail(new CRLFX2(), ((array) $this->lexer->token)['value']); } //this has no coverage. Condition is repeated from above one if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) { - return new InvalidEmail(new CRLFAtTheEnd(), $this->lexer->token['value']); + return new InvalidEmail(new CRLFAtTheEnd(), ((array) $this->lexer->token)['value']); } return new ValidEmail(); } - + protected function isFWS() : bool { if ($this->escaped()) { return false; } - return in_array($this->lexer->token['type'], self::FWS_TYPES); + return in_array(((array) $this->lexer->token)['type'], self::FWS_TYPES); } } diff --git a/vendor/egulias/email-validator/src/Parser/IDLeftPart.php b/vendor/egulias/email-validator/src/Parser/IDLeftPart.php index 5fd9cdf9929d06aba5e9d5dda33f8fcb8f6f871d..3b01ae290244461aa8b3e3c2d9a4946c2fcda002 100644 --- a/vendor/egulias/email-validator/src/Parser/IDLeftPart.php +++ b/vendor/egulias/email-validator/src/Parser/IDLeftPart.php @@ -10,6 +10,6 @@ class IDLeftPart extends LocalPart { protected function parseComments(): Result { - return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token['value']); + return new InvalidEmail(new CommentsInIDRight(), ((array) $this->lexer->token)['value']); } } diff --git a/vendor/egulias/email-validator/src/Parser/IDRightPart.php b/vendor/egulias/email-validator/src/Parser/IDRightPart.php index 1a1268f2dfb006aaefe9facf39ce55c35b8a95b1..d19e05ab6fe6f9653009272a3926bbe9f34feb02 100644 --- a/vendor/egulias/email-validator/src/Parser/IDRightPart.php +++ b/vendor/egulias/email-validator/src/Parser/IDRightPart.php @@ -20,9 +20,9 @@ protected function validateTokens(bool $hasComments) : Result EmailLexer::S_GREATERTHAN => true, EmailLexer::S_LOWERTHAN => true, ]; - - if (isset($invalidDomainTokens[$this->lexer->token['type']])) { - return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']); + + if (isset($invalidDomainTokens[((array) $this->lexer->token)['type']])) { + return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']); } return new ValidEmail(); } diff --git a/vendor/egulias/email-validator/src/Parser/LocalPart.php b/vendor/egulias/email-validator/src/Parser/LocalPart.php index 154521b27f869fcbe1ff13182edf9f19ff22c3bc..3f2ef7d8ed99eeb263ba052cf17c9d40096bfae7 100644 --- a/vendor/egulias/email-validator/src/Parser/LocalPart.php +++ b/vendor/egulias/email-validator/src/Parser/LocalPart.php @@ -36,12 +36,12 @@ public function parse() : Result { $this->lexer->startRecording(); - while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) { + while (((array) $this->lexer->token)['type'] !== EmailLexer::S_AT && null !== ((array) $this->lexer->token)['type']) { if ($this->hasDotAtStart()) { - return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']); + return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DQUOTE) { $dquoteParsingResult = $this->parseDoubleQuote(); //Invalid double quote parsing @@ -50,8 +50,8 @@ public function parse() : Result } } - if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS || - $this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { + if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS || + ((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { $commentsResult = $this->parseComments(); //Invalid comment parsing @@ -60,14 +60,14 @@ public function parse() : Result } } - if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { - return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { + return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']); } - if ($this->lexer->token['type'] === EmailLexer::S_DOT && + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_AT) ) { - return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']); + return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']); } $resultEscaping = $this->validateEscaping(); @@ -99,8 +99,8 @@ public function parse() : Result protected function validateTokens(bool $hasComments) : Result { - if (isset(self::INVALID_TOKENS[$this->lexer->token['type']])) { - return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token['value']); + if (isset(self::INVALID_TOKENS[((array) $this->lexer->token)['type']])) { + return new InvalidEmail(new ExpectingATEXT('Invalid token found'), ((array) $this->lexer->token)['value']); } return new ValidEmail(); } @@ -110,7 +110,7 @@ public function localPart() : string return $this->localPart; } - private function parseLocalFWS() : Result + private function parseLocalFWS() : Result { $foldingWS = new FoldingWhiteSpace($this->lexer); $resultFWS = $foldingWS->parse(); @@ -122,7 +122,7 @@ private function parseLocalFWS() : Result private function hasDotAtStart() : bool { - return $this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']; + return ((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']; } private function parseDoubleQuote() : Result @@ -148,12 +148,12 @@ protected function parseComments(): Result private function validateEscaping() : Result { //Backslash found - if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { + if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) { return new ValidEmail(); } if ($this->lexer->isNextToken(EmailLexer::GENERIC)) { - return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), $this->lexer->token['value']); + return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), ((array) $this->lexer->token)['value']); } if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) { diff --git a/vendor/egulias/email-validator/src/Parser/PartParser.php b/vendor/egulias/email-validator/src/Parser/PartParser.php index a75a172acb42ed3c4ec542d00cd5cccaf24a47ea..7fc6d7bf31e9cfa15c447b47881548674cb4ddc2 100644 --- a/vendor/egulias/email-validator/src/Parser/PartParser.php +++ b/vendor/egulias/email-validator/src/Parser/PartParser.php @@ -45,8 +45,8 @@ protected function parseFWS() : Result protected function checkConsecutiveDots() : Result { - if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { - return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']); + if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { + return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']); } return new ValidEmail(); @@ -58,6 +58,6 @@ protected function escaped() : bool return $previous && $previous['type'] === EmailLexer::S_BACKSLASH && - $this->lexer->token['type'] !== EmailLexer::GENERIC; + ((array) $this->lexer->token)['type'] !== EmailLexer::GENERIC; } } diff --git a/vendor/symfony/var-dumper/Caster/DateCaster.php b/vendor/symfony/var-dumper/Caster/DateCaster.php index 18641fbc1d348c2de4d9121f887f6db9eb206f9d..d07bac583147d5846688ab842894d4744cf95d8e 100644 --- a/vendor/symfony/var-dumper/Caster/DateCaster.php +++ b/vendor/symfony/var-dumper/Caster/DateCaster.php @@ -27,7 +27,7 @@ class DateCaster public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, bool $isNested, int $filter) { $prefix = Caster::PREFIX_VIRTUAL; - $location = $d->getTimezone()->getLocation(); + $location = $d->getTimezone() ? $d->getTimezone()->getLocation() : null; $fromNow = (new \DateTime())->diff($d); $title = $d->format('l, F j, Y') diff --git a/vendor/symfony/var-dumper/composer.json b/vendor/symfony/var-dumper/composer.json index dc46f58d99ecae911ba8940310d7afa619099cda..fc127d721ab1616ac26016c1ab81b7b8ca5e0c9e 100644 --- a/vendor/symfony/var-dumper/composer.json +++ b/vendor/symfony/var-dumper/composer.json @@ -28,7 +28,6 @@ "twig/twig": "^2.13|^3.0.4" }, "conflict": { - "phpunit/phpunit": "<5.4.3", "symfony/console": "<4.4" }, "suggest": { diff --git a/web/modules/entity/.travis.yml b/web/modules/entity/.travis.yml deleted file mode 100644 index e48d5d7d39f46a0caf725e415d91d8ea1323d02d..0000000000000000000000000000000000000000 --- a/web/modules/entity/.travis.yml +++ /dev/null @@ -1,58 +0,0 @@ -language: php -sudo: false - -php: - - 5.5 - - 5.6 - - 7 - - hhvm - -matrix: - allow_failures: - # We cannot use hhvm-nightly since that does not work in Travis CI's old - # Ubuntu 12.04. - - php: hhvm - # Don't wait for the allowed failures to build. - fast_finish: true - -mysql: - database: entity - username: root - encoding: utf8 - -before_script: - # Remove Xdebug as we don't need it and it causes - # PHP Fatal error: Maximum function nesting level of '256' reached. - # We also don't care if that file exists or not on PHP 7. - - phpenv config-rm xdebug.ini || true - - # Remember the current entity test directory for later use in the Drupal - # installation. - - TESTDIR=$(pwd) - # Navigate out of module directory to prevent blown stack by recursive module - # lookup. - - cd .. - - # Create database. - - mysql -e 'create database entity' - # Export database variable for kernel tests. - - export SIMPLETEST_DB=mysql://root:@127.0.0.1/entity - # Download Drupal 8 core. - - travis_retry git clone --branch 8.5.x --depth 1 http://git.drupal.org/project/drupal.git - - cd drupal - - composer self-update - - composer install -n - - # Reference entity in build site. - - ln -s $TESTDIR modules/entity - - # Start a web server on port 8888, run in the background; wait for - # initialization. - - nohup php -S localhost:8888 > /dev/null 2>&1 & - - # Export web server URL for browser tests. - - export SIMPLETEST_BASE_URL=http://localhost:8888 - -script: - # Run the PHPUnit tests which also include the kernel tests. - - ./vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist --verbose ./modules/entity diff --git a/web/modules/entity/LICENSE.txt b/web/modules/entity/LICENSE.txt deleted file mode 100644 index d159169d1050894d3ea3b98e1c965c4058208fe1..0000000000000000000000000000000000000000 --- a/web/modules/entity/LICENSE.txt +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/web/modules/entity/README.txt b/web/modules/entity/README.txt deleted file mode 100644 index ab843c59fc673b7813842913f033064b38f48a0a..0000000000000000000000000000000000000000 --- a/web/modules/entity/README.txt +++ /dev/null @@ -1,16 +0,0 @@ -Entity API module ------------------ - -Provides improvements and extensions to the Drupal 8 Entity system. -Acts as a staging ground for Drupal core, with each core minor release (8.5, 8.6, 8.7) -receiving a portion of this module's functionality. - -Current functionality: -- Local action providers (core issue: #2976861) -- Local task providers -- Permission providers (core issue: #2809177) -- Query access API (Change record: https://www.drupal.org/node/3002038, core issue: #777578) -- Bundle plugin API (plugin-based entity bundles, currently not proposed for core inclusion) -- A generic UI for revisions (WIP, see #2625122) -- Duplicate entity UI -- EntityViewsData handler with many improvements over the one in core. diff --git a/web/modules/entity/composer.json b/web/modules/entity/composer.json deleted file mode 100644 index e028b70d446aa236763e7f70dd12b749d7e8089c..0000000000000000000000000000000000000000 --- a/web/modules/entity/composer.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "drupal/entity", - "type": "drupal-module", - "description": "Provides expanded entity APIs, which will be moved to Drupal core one day.", - "homepage": "http://drupal.org/project/entity", - "license": "GPL-2.0-or-later", - "require": { - "drupal/core": "^8.8 || ^9" - } -} diff --git a/web/modules/entity/config/schema/entity.schema.yml b/web/modules/entity/config/schema/entity.schema.yml deleted file mode 100644 index 4d44600ff3ab7e6d4adb499693e99460e50f46ad..0000000000000000000000000000000000000000 --- a/web/modules/entity/config/schema/entity.schema.yml +++ /dev/null @@ -1,11 +0,0 @@ -action.configuration.entity_delete_action:*: - type: action_configuration_default - label: 'Delete entity configuration' - -views.field.entity_link_revision: - type: views.field.entity_link - label: 'Entity revision link' - -views.field.entity_link_revision_revert: - type: views.field.entity_link - label: 'Entity revision revert link' diff --git a/web/modules/entity/drupalci.yml b/web/modules/entity/drupalci.yml deleted file mode 100644 index 5df69a2c2b221b9493383bca1a3083c637c811a9..0000000000000000000000000000000000000000 --- a/web/modules/entity/drupalci.yml +++ /dev/null @@ -1,21 +0,0 @@ -# https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-testing -build: - assessment: - validate_codebase: - phplint: - container_composer: - phpcs: - # phpcs will use core's specified version of Coder. - sniff-all-files: true - halt-on-fail: false - testing: - run_tests.standard: - types: 'PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional' - testgroups: '--all' - suppress-deprecations: false - run_tests.javascript: - concurrency: 1 - types: 'PHPUnit-FunctionalJavascript' - testgroups: '--all' - suppress-deprecations: false - halt-on-fail: false diff --git a/web/modules/entity/entity.info.yml b/web/modules/entity/entity.info.yml deleted file mode 100644 index 7f1f0c405ef386ec232bb64540e0916f387dfa45..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.info.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: Entity -description: Provides expanded entity APIs, which will be moved to Drupal core one day. -type: module -core_version_requirement: ^8.8 || ^9 - -# Information added by Drupal.org packaging script on 2020-11-26 -version: '8.x-1.2' -project: 'entity' -datestamp: 1606399152 diff --git a/web/modules/entity/entity.links.action.yml b/web/modules/entity/entity.links.action.yml deleted file mode 100644 index 5e02edcd7c394b35168364790afb63810ddc5804..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.links.action.yml +++ /dev/null @@ -1,2 +0,0 @@ -entity.entity_actions: - deriver: Drupal\entity\Plugin\Derivative\EntityActionsDeriver diff --git a/web/modules/entity/entity.links.task.yml b/web/modules/entity/entity.links.task.yml deleted file mode 100644 index 3c822b25b2a024a89d32f6bb14776289df5a018b..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.links.task.yml +++ /dev/null @@ -1,2 +0,0 @@ -entity.entity_tasks: - deriver: Drupal\entity\Plugin\Derivative\EntityTasksDeriver diff --git a/web/modules/entity/entity.module b/web/modules/entity/entity.module deleted file mode 100644 index 1c54903fa4387e25cc3cc0469c36eae4c5e90c5b..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.module +++ /dev/null @@ -1,216 +0,0 @@ -<?php - -/** - * @file - * Provides expanded entity APIs. - */ - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Database\Query\SelectInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\entity\BundlePlugin\BundlePluginHandler; -use Drupal\entity\QueryAccess\Condition; -use Drupal\entity\QueryAccess\EntityQueryAlter; -use Drupal\entity\QueryAccess\ViewsQueryAlter; -use Drupal\views\Plugin\views\query\QueryPluginBase; -use Drupal\views\Plugin\views\query\Sql; -use Drupal\views\ViewExecutable; - -/** - * Implements hook_entity_operation(). - */ -function entity_entity_operation(EntityInterface $entity) { - $operations = []; - $entity_type = $entity->getEntityType(); - if ($entity_type->hasLinkTemplate('duplicate-form') && $entity->access('duplicate')) { - $operations['duplicate'] = [ - 'title' => t('Duplicate'), - 'weight' => 40, - 'url' => $entity->toUrl('duplicate-form'), - ]; - } - - return $operations; -} - -/** - * Gets the entity types which use bundle plugins. - * - * @return \Drupal\Core\Entity\EntityTypeInterface[] - * The entity types. - */ -function entity_get_bundle_plugin_entity_types() { - $entity_types = \Drupal::entityTypeManager()->getDefinitions(); - $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) { - return $entity_type->hasHandlerClass('bundle_plugin'); - }); - - return $entity_types; -} - -/** - * Implements hook_entity_type_build(). - */ -function entity_entity_type_build(array &$entity_types) { - foreach ($entity_types as $entity_type) { - if ($entity_type->get('bundle_plugin_type')) { - if (!$entity_type->hasKey('bundle')) { - throw new \LogicException(sprintf('The %s entity type uses a bundle plugin type but has no bundle key.', $entity_type->id())); - } - - if (!$entity_type->hasHandlerClass('bundle_plugin')) { - $entity_type->setHandlerClass('bundle_plugin', BundlePluginHandler::class); - } - } - } -} - -/** - * Implements hook_entity_type_alter(). - */ -function entity_entity_type_alter(array &$entity_types) { - /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - foreach ($entity_types as $entity_type_id => $entity_type) { - // Sets a default query_access handler for all entity types that have none. - if (!$entity_type->hasHandlerClass('query_access')) { - // Query access does not apply to config entities. - if (!$entity_type->entityClassImplements(ConfigEntityInterface::class)) { - // Query access only works for SQL storages. - if (is_subclass_of($entity_type->getStorageClass(), SqlEntityStorageInterface::class)) { - $entity_type->setHandlerClass('query_access', 'Drupal\entity\QueryAccess\EventOnlyQueryAccessHandler'); - } - } - } - } -} - -/** - * Implements hook_entity_bundle_info(). - */ -function entity_entity_bundle_info() { - $bundles = []; - foreach (entity_get_bundle_plugin_entity_types() as $entity_type) { - /** @var \Drupal\entity\BundlePlugin\BundlePluginHandler $bundle_handler */ - $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin'); - $bundles[$entity_type->id()] = $bundle_handler->getBundleInfo(); - } - return $bundles; -} - -/** - * Implements hook_entity_field_storage_info(). - */ -function entity_entity_field_storage_info(EntityTypeInterface $entity_type) { - if ($entity_type->hasHandlerClass('bundle_plugin')) { - /** @var \Drupal\entity\BundlePlugin\BundlePluginHandler $bundle_handler */ - $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin'); - return $bundle_handler->getFieldStorageDefinitions(); - } -} - -/** - * Implements hook_entity_bundle_field_info(). - */ -function entity_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle) { - if ($entity_type->hasHandlerClass('bundle_plugin')) { - /** @var \Drupal\entity\BundlePlugin\BundlePluginHandler $bundle_handler */ - $bundle_handler = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'bundle_plugin'); - return $bundle_handler->getFieldDefinitions($bundle); - } -} - -/** - * Implements hook_modules_installed(). - */ -function entity_modules_installed($modules) { - foreach (entity_get_bundle_plugin_entity_types() as $entity_type) { - \Drupal::service('entity.bundle_plugin_installer')->installBundles($entity_type, $modules); - } -} - -/** - * Implements hook_module_preuninstall(). - */ -function entity_module_preuninstall($module) { - foreach (entity_get_bundle_plugin_entity_types() as $entity_type) { - \Drupal::service('entity.bundle_plugin_installer')->uninstallBundles($entity_type, [$module]); - } -} - -/** - * Implements hook_query_TAG_alter(). - */ -function entity_query_entity_query_alter(SelectInterface $query) { - $entity_type_id = $query->getMetaData('entity_type'); - if ($query->hasTag($entity_type_id . '_access')) { - $entity_type_manager = \Drupal::entityTypeManager(); - $entity_type = $entity_type_manager->getDefinition($entity_type_id); - - \Drupal::service('class_resolver') - ->getInstanceFromDefinition(EntityQueryAlter::class) - ->alter($query, $entity_type); - } -} - -/** - * Implements hook_views_query_alter(). - */ -function entity_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { - if ($query instanceof Sql && empty($query->options['disable_sql_rewrite'])) { - \Drupal::service('class_resolver') - ->getInstanceFromDefinition(ViewsQueryAlter::class) - ->alter($query, $view); - } -} - -/** - * Implements hook_jsonapi_entity_filter_access(). - * - * Controls access to JSON:API filtering for entity types with a query_access - * handler. Only maps condition groups consisting of "owner" and/or "published" - * field conditions. - */ -function entity_jsonapi_entity_filter_access(EntityTypeInterface $entity_type, AccountInterface $account) { - if (!$entity_type->hasHandlerClass('query_access')) { - return []; - } - /** @var \Drupal\entity\QueryAccess\QueryAccessHandlerInterface $query_access */ - $query_access = \Drupal::entityTypeManager()->getHandler($entity_type->id(), 'query_access'); - $conditions = $query_access->getConditions('view', $account); - if ($conditions->isAlwaysFalse()) { - return []; - } - - $allowed = AccessResult::allowed()->addCacheableDependency($conditions); - $result = []; - if ($conditions->count() === 0) { - $result[JSONAPI_FILTER_AMONG_ALL] = $allowed; - } - elseif ($conditions->count() === 1 || $conditions->getConjunction() === 'OR') { - $published_key = $entity_type->getKey('published'); - $owner_key = $entity_type->getKey('owner'); - foreach ($conditions->getConditions() as $condition) { - if (!($condition instanceof Condition)) { - // Nested condition groups imply logic that is too complex to be mapped. - return []; - } - - if ($published_key && $condition->getField() === $published_key && $condition->getOperator() === '=' && (string) $condition->getValue() === '1') { - $result[JSONAPI_FILTER_AMONG_PUBLISHED] = $allowed; - } - elseif ($owner_key && $condition->getField() === $owner_key && $condition->getOperator() === '=' && $condition->getValue() === $account->id()) { - $result[JSONAPI_FILTER_AMONG_OWN] = $allowed; - } - else { - // Unsupported condition, no access can be granted. - return []; - } - } - } - - return $result; -} diff --git a/web/modules/entity/entity.permissions.yml b/web/modules/entity/entity.permissions.yml deleted file mode 100644 index 1676e880b4e3a9cb35b9f3f8835980a5547c06a4..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.permissions.yml +++ /dev/null @@ -1,2 +0,0 @@ -permission_callbacks: - - \Drupal\entity\EntityPermissions::buildPermissions diff --git a/web/modules/entity/entity.services.yml b/web/modules/entity/entity.services.yml deleted file mode 100644 index 3854921ba82c68fbc816f6dcc726b43b6a1ed6ba..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.services.yml +++ /dev/null @@ -1,26 +0,0 @@ -services: - access_checker.entity_revision: - class: \Drupal\entity\Access\EntityRevisionRouteAccessChecker - arguments: ['@entity_type.manager', '@current_route_match'] - tags: - - { name: access_check, applies_to: _entity_access_revision } - - entity.entity_duplicate_subscriber: - class: Drupal\entity\EventSubscriber\EntityDuplicateSubscriber - arguments: ['@entity.bundle_entity_duplicator'] - tags: - - { name: event_subscriber } - - entity.bundle_entity_duplicator: - class: Drupal\entity\BundleEntityDuplicator - arguments: ['@entity_type.manager'] - - entity.bundle_plugin_installer: - class: Drupal\entity\BundlePlugin\BundlePluginInstaller - arguments: ['@entity_type.manager', '@entity_bundle.listener', '@field_storage_definition.listener', '@field_definition.listener'] - - entity.bundle_plugin.uninstall_validator: - class: Drupal\entity\BundlePlugin\BundlePluginUninstallValidator - tags: - - { name: module_install.uninstall_validator } - arguments: ['@entity_type.manager', '@string_translation'] diff --git a/web/modules/entity/entity.views.inc b/web/modules/entity/entity.views.inc deleted file mode 100644 index 0ff16c5c5be26f183bb75371fc563dc03627244c..0000000000000000000000000000000000000000 --- a/web/modules/entity/entity.views.inc +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Implements hook_views_data(). - */ -function entity_views_data() { - $entity_types = \Drupal::entityTypeManager()->getDefinitions(); - $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) { - return $entity_type->entityClassImplements(ContentEntityInterface::class); - }); - - $data = []; - foreach ($entity_types as $entity_type) { - /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ - if ($entity_type->isRevisionable()) { - $entity_type_id = $entity_type->id(); - $revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable(); - - if ($entity_type->hasLinkTemplate('revision')) { - $data[$revision_table]['view_revision_' . $entity_type_id] = [ - 'field' => [ - 'title' => t('Link to revision'), - 'help' => t('Provide a simple link to the revision.'), - 'id' => 'entity_link_revision', - 'click sortable' => FALSE, - ], - ]; - } - if ($entity_type->hasLinkTemplate('revision-revert-form')) { - $data[$revision_table]['revert_revision_' . $entity_type_id] = [ - 'field' => [ - 'title' => t('Link to revert revision'), - 'help' => t('Provide a simple link to revert to the revision.'), - 'id' => 'entity_link_revision_revert', - 'click sortable' => FALSE, - ], - ]; - } - } - } - - return $data; -} diff --git a/web/modules/entity/src/Access/EntityRevisionRouteAccessChecker.php b/web/modules/entity/src/Access/EntityRevisionRouteAccessChecker.php deleted file mode 100644 index 799af140b1c1e5159194a3cfedb72ae59cc6429f..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Access/EntityRevisionRouteAccessChecker.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php - -namespace Drupal\entity\Access; - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Routing\Access\AccessInterface; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Session\AccountInterface; -use Symfony\Component\Routing\Route; - -/** - * Checks access to a entity revision. - */ -class EntityRevisionRouteAccessChecker implements AccessInterface { - - /** - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Stores calculated access check results. - * - * @var array - */ - protected $accessCache = []; - - /** - * The currently active route match object. - * - * @var \Drupal\Core\Routing\RouteMatchInterface - */ - protected $routeMatch; - - /** - * Creates a new EntityRevisionRouteAccessChecker instance. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity manager. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The currently active route match object. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match) { - $this->entityTypeManager = $entity_type_manager; - $this->routeMatch = $route_match; - } - - /** - * {@inheritdoc} - */ - public function access(Route $route, AccountInterface $account, RouteMatchInterface $route_match = NULL) { - if (empty($route_match)) { - $route_match = $this->routeMatch; - } - - $operation = $route->getRequirement('_entity_access_revision'); - list($entity_type_id, $operation) = explode('.', $operation, 2); - - if ($operation === 'list') { - $_entity = $route_match->getParameter($entity_type_id); - return AccessResult::allowedIf($this->checkAccess($_entity, $account, $operation))->cachePerPermissions(); - } - else { - $_entity_revision = $route_match->getParameter($entity_type_id . '_revision'); - return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions(); - } - } - - /** - * Performs access checks. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity for which to check access. - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to check access. - * @param string $operation - * The entity operation. Usually one of 'view', 'view label', 'update' or - * 'delete'. - * - * @return bool - * The access result. - */ - protected function checkAccess(ContentEntityInterface $entity, AccountInterface $account, $operation = 'view') { - $entity_type = $entity->getEntityType(); - $entity_type_id = $entity->getEntityTypeId(); - $entity_access = $this->entityTypeManager->getAccessControlHandler($entity_type_id); - - /** @var \Drupal\Core\Entity\EntityStorageInterface $entity_storage */ - $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); - - $map = [ - 'view' => "view all $entity_type_id revisions", - 'list' => "view all $entity_type_id revisions", - 'update' => "revert all $entity_type_id revisions", - 'delete' => "delete all $entity_type_id revisions", - ]; - $bundle = $entity->bundle(); - $type_map = [ - 'view' => "view $entity_type_id $bundle revisions", - 'list' => "view $entity_type_id $bundle revisions", - 'update' => "revert $entity_type_id $bundle revisions", - 'delete' => "delete $entity_type_id $bundle revisions", - ]; - - if (!$entity || !isset($map[$operation]) || !isset($type_map[$operation])) { - // If there was no node to check against, or the $op was not one of the - // supported ones, we return access denied. - return FALSE; - } - - // Statically cache access by revision ID, language code, user account ID, - // and operation. - $langcode = $entity->language()->getId(); - $cid = $entity->getRevisionId() . ':' . $langcode . ':' . $account->id() . ':' . $operation; - - if (!isset($this->accessCache[$cid])) { - $admin_permission = $entity_type->getAdminPermission(); - - // Perform basic permission checks first. - if (!$account->hasPermission($map[$operation]) && !$account->hasPermission($type_map[$operation]) && ($admin_permission && !$account->hasPermission($admin_permission))) { - $this->accessCache[$cid] = FALSE; - return FALSE; - } - - if (($admin_permission = $entity_type->getAdminPermission()) && $account->hasPermission($admin_permission)) { - $this->accessCache[$cid] = TRUE; - } - else { - // Entity access handlers are generally not aware of the "list" operation. - $operation = $operation == 'list' ? 'view' : $operation; - // First check the access to the default revision and finally, if the - // node passed in is not the default revision then access to that, too. - $this->accessCache[$cid] = $entity_access->access($entity_storage->load($entity->id()), $operation, $account) && ($entity->isDefaultRevision() || $entity_access->access($entity, $operation, $account)); - } - } - - return $this->accessCache[$cid]; - } - - /** - * Counts the number of revisions in the default language. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity. - * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage - * The entity storage. - * - * @return int - * The number of revisions in the default language. - */ - protected function countDefaultLanguageRevisions(ContentEntityInterface $entity, EntityStorageInterface $entity_storage) { - $entity_type = $entity->getEntityType(); - $count = $entity_storage->getQuery() - ->allRevisions() - ->condition($entity_type->getKey('id'), $entity->id()) - ->condition($entity_type->getKey('default_langcode'), 1) - ->count() - ->execute(); - return $count; - } - - /** - * Resets the access cache. - * - * @return $this - */ - public function resetAccessCache() { - $this->accessCache = []; - return $this; - } - -} diff --git a/web/modules/entity/src/BulkFormEntityListBuilder.php b/web/modules/entity/src/BulkFormEntityListBuilder.php deleted file mode 100644 index c94982a523f05accf9ba30465e54db5714a4dcc6..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BulkFormEntityListBuilder.php +++ /dev/null @@ -1,223 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityListBuilder; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Form\FormBuilderInterface; -use Drupal\Core\Form\FormInterface; -use Drupal\Core\Form\FormStateInterface; -use Drupal\system\ActionConfigEntityInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a list builder that allows using bulk actions. - */ -class BulkFormEntityListBuilder extends EntityListBuilder implements FormInterface { - - /** - * The key to use for the form element containing the entities. - * - * @var string - */ - protected $entitiesKey = 'entities'; - - /** - * The entities being listed. - * - * @var \Drupal\Core\Entity\EntityInterface[] - */ - protected $entities = []; - - /** - * The bulk operations. - * - * @todo Change the typehint to ActionConfigEntityInterface when - * https://www.drupal.org/project/drupal/issues/3017214 is in. - * - * @var \Drupal\system\Entity\Action[] - */ - protected $actions; - - /** - * The action storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $actionStorage; - - /** - * The form builder. - * - * @var \Drupal\Core\Form\FormBuilderInterface - */ - protected $formBuilder; - - /** - * Constructs a new BulkFormEntityListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage - * The entity storage. - * @param \Drupal\Core\Entity\EntityStorageInterface $action_storage - * The action storage. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $entity_storage, EntityStorageInterface $action_storage, FormBuilderInterface $form_builder) { - parent::__construct($entity_type, $entity_storage); - - $this->actionStorage = $action_storage; - $this->formBuilder = $form_builder; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity_type.manager')->getStorage($entity_type->id()), - $container->get('entity_type.manager')->getStorage('action'), - $container->get('form_builder') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return $this->entityTypeId . '_list'; - } - - /** - * {@inheritdoc} - */ - public function render() { - // Filter the actions to only include those for this entity type. - $entity_type_id = $this->entityTypeId; - $this->actions = array_filter($this->actionStorage->loadMultiple(), function (ActionConfigEntityInterface $action) use ($entity_type_id) { - return $action->getType() == $entity_type_id; - }); - $this->entities = $this->load(); - if ($this->entities) { - return $this->formBuilder->getForm($this); - } - - return parent::render(); - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form[$this->entitiesKey] = [ - '#type' => 'table', - '#header' => $this->buildHeader(), - '#empty' => $this->t('There are no @label yet.', ['@label' => $this->entityType->getPluralLabel()]), - '#tableselect' => TRUE, - '#attached' => [ - 'library' => ['core/drupal.tableselect'], - ], - ]; - - $this->entities = $this->load(); - foreach ($this->entities as $entity) { - $form[$this->entitiesKey][$entity->id()] = $this->buildRow($entity); - } - - $form['actions']['#type'] = 'actions'; - $form['actions']['submit'] = [ - '#type' => 'submit', - '#value' => $this->t('Apply to selected items'), - '#button_type' => 'primary', - ]; - - // Ensure a consistent container for filters/operations in the view header. - $form['header'] = [ - '#type' => 'container', - '#weight' => -100, - ]; - - $action_options = []; - foreach ($this->actions as $id => $action) { - $action_options[$id] = $action->label(); - } - $form['header']['action'] = [ - '#type' => 'select', - '#title' => $this->t('Action'), - '#options' => $action_options, - ]; - // Duplicate the form actions into the action container in the header. - $form['header']['actions'] = $form['actions']; - - // Only add the pager if a limit is specified. - if ($this->limit) { - $form['pager'] = [ - '#type' => 'pager', - ]; - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - $selected = array_filter($form_state->getValue($this->entitiesKey)); - if (empty($selected)) { - $form_state->setErrorByName($this->entitiesKey, $this->t('No items selected.')); - } - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $selected = array_filter($form_state->getValue($this->entitiesKey)); - $entities = []; - $action = $this->actions[$form_state->getValue('action')]; - $count = 0; - - foreach ($selected as $id) { - $entity = $this->entities[$id]; - // Skip execution if the user did not have access. - if (!$action->getPlugin()->access($entity)) { - $this->messenger()->addError($this->t('No access to execute %action on the @entity_type_label %entity_label.', [ - '%action' => $action->label(), - '@entity_type_label' => $entity->getEntityType()->getLabel(), - '%entity_label' => $entity->label(), - ])); - continue; - } - - $count++; - $entities[$id] = $entity; - } - - // Don't perform any action unless there are some elements affected. - // @see https://www.drupal.org/project/drupal/issues/3018148 - if (!$count) { - return; - } - - $action->execute($entities); - - $operation_definition = $action->getPluginDefinition(); - if (!empty($operation_definition['confirm_form_route_name'])) { - $options = [ - 'query' => $this->getDestinationArray(), - ]; - $form_state->setRedirect($operation_definition['confirm_form_route_name'], [], $options); - } - else { - $this->messenger()->addStatus($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', [ - '%action' => $action->label(), - ])); - } - } - -} diff --git a/web/modules/entity/src/BundleEntityAccessControlHandler.php b/web/modules/entity/src/BundleEntityAccessControlHandler.php deleted file mode 100644 index b42e14c6f53d6a2da93242794be3a37a80aef627..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundleEntityAccessControlHandler.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\EntityAccessControlHandler as CoreEntityAccessControlHandler; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Session\AccountInterface; - -/** - * Controls access to bundle entities. - * - * Allows the bundle entity label to be viewed if the account has - * access to view entities of that bundle. - */ -class BundleEntityAccessControlHandler extends CoreEntityAccessControlHandler { - - /** - * {@inheritdoc} - */ - protected $viewLabelOperation = TRUE; - - /** - * {@inheritdoc} - */ - protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { - if ($operation === 'view label') { - $bundle = $entity->id(); - $entity_type_id = $this->entityType->getBundleOf(); - $permissions = [ - $this->entityType->getAdminPermission() ?: "administer $entity_type_id", - // View permissions provided by EntityPermissionProvider. - "view $entity_type_id", - "view $bundle $entity_type_id", - // View permissions provided by UncacheableEntityPermissionProvider. - "view own $entity_type_id", - "view any $entity_type_id", - "view own $bundle $entity_type_id", - "view any $bundle $entity_type_id", - ]; - - return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR'); - } - else { - return parent::checkAccess($entity, $operation, $account); - } - } - -} diff --git a/web/modules/entity/src/BundleEntityDuplicator.php b/web/modules/entity/src/BundleEntityDuplicator.php deleted file mode 100644 index aa479997697880d52bedb2b5f02e22ef9bb356a0..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundleEntityDuplicator.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; - -class BundleEntityDuplicator implements BundleEntityDuplicatorInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs a new BundleEntityDuplicator object. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public function duplicate(ConfigEntityInterface $bundle_entity, array $values) { - $entity_type = $bundle_entity->getEntityType(); - if (!$entity_type->getBundleOf()) { - throw new \InvalidArgumentException(sprintf('The "%s" entity type is not a bundle entity type.', $entity_type->id())); - } - $id_key = $entity_type->getKey('id'); - if (empty($values[$id_key])) { - throw new \InvalidArgumentException(sprintf('The $values[\'%s\'] key is empty or missing.', $id_key)); - } - - $entity = $bundle_entity->createDuplicate(); - foreach ($values as $property_name => $value) { - $entity->set($property_name, $value); - } - $entity->save(); - $this->duplicateFields($bundle_entity, $entity->id()); - $this->duplicateDisplays($bundle_entity, $entity->id()); - - return $entity; - } - - /** - * {@inheritdoc} - */ - public function duplicateFields(ConfigEntityInterface $bundle_entity, $target_bundle_id) { - $entity_type = $bundle_entity->getEntityType(); - $bundle_of = $entity_type->getBundleOf(); - if (!$bundle_of) { - throw new \InvalidArgumentException(sprintf('The "%s" entity type is not a bundle entity type.', $entity_type->id())); - } - if (empty($target_bundle_id)) { - throw new \InvalidArgumentException('The $target_bundle_id must not be empty.'); - } - - $id_prefix = $bundle_of . '.' . $bundle_entity->id() . '.'; - $fields = $this->loadEntities('field_config', $id_prefix); - foreach ($fields as $field) { - /** @var \Drupal\Core\Field\FieldConfigInterface $field */ - $duplicate_field = $field->createDuplicate(); - $duplicate_field->set('id', $bundle_of . '.' . $target_bundle_id . '.' . $field->getName()); - $duplicate_field->set('bundle', $target_bundle_id); - $duplicate_field->save(); - } - } - - /** - * {@inheritdoc} - */ - public function duplicateDisplays(ConfigEntityInterface $bundle_entity, $target_bundle_id) { - $entity_type = $bundle_entity->getEntityType(); - $bundle_of = $entity_type->getBundleOf(); - if (!$bundle_of) { - throw new \InvalidArgumentException(sprintf('The "%s" entity type is not a bundle entity type.', $entity_type->id())); - } - if (empty($target_bundle_id)) { - throw new \InvalidArgumentException('The $target_bundle_id must not be empty.'); - } - - $id_prefix = $bundle_of . '.' . $bundle_entity->id() . '.'; - $form_displays = $this->loadEntities('entity_form_display', $id_prefix); - $view_displays = $this->loadEntities('entity_view_display', $id_prefix); - foreach ($form_displays as $form_display) { - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */ - $duplicate_form_display = $form_display->createDuplicate(); - $duplicate_form_display->set('id', $bundle_of . '.' . $target_bundle_id . '.' . $form_display->getMode()); - $duplicate_form_display->set('bundle', $target_bundle_id); - $duplicate_form_display->save(); - } - foreach ($view_displays as $view_display) { - /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */ - $duplicate_view_display = $view_display->createDuplicate(); - $duplicate_view_display->set('id', $bundle_of . '.' . $target_bundle_id . '.' . $view_display->getMode()); - $duplicate_view_display->set('bundle', $target_bundle_id); - $duplicate_view_display->save(); - } - } - - /** - * Loads config entities with the given ID prefix. - * - * @param string $entity_type_id - * The entity type ID. - * @param string $id_prefix - * The ID prefix. - * - * @return \Drupal\Core\Config\Entity\ConfigEntityInterface[] - * The loaded config entities. - */ - protected function loadEntities($entity_type_id, $id_prefix) { - $storage = $this->entityTypeManager->getStorage($entity_type_id); - $ids = $storage->getQuery() - ->condition('id', $id_prefix, 'STARTS_WITH') - ->execute(); - - return $ids ? $storage->loadMultiple($ids) : []; - } - -} diff --git a/web/modules/entity/src/BundleEntityDuplicatorInterface.php b/web/modules/entity/src/BundleEntityDuplicatorInterface.php deleted file mode 100644 index 836884fe6374b5093b10cfc67f97eecebb6677ee..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundleEntityDuplicatorInterface.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Config\Entity\ConfigEntityInterface; - -/** - * Duplicates bundle entities, their fields and displays. - */ -interface BundleEntityDuplicatorInterface { - - /** - * Duplicates the bundle entity, its fields and displays. - * - * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity - * The bundle entity. - * @param array $values - * An array of values to set, keyed by property name. Needs to at least - * contain a new ID. - * - * @return \Drupal\Core\Config\Entity\ConfigEntityInterface - * The new bundle entity, after it has been saved. - * - * @throws \InvalidArgumentException - * Thrown if the given entity is not a bundle entity, or if $values does - * not contain a new ID. - */ - public function duplicate(ConfigEntityInterface $bundle_entity, array $values); - - /** - * Duplicates the bundle entity's fields. - * - * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity - * The bundle entity. - * @param string $target_bundle_id - * The target bundle ID. - * - * @throws \InvalidArgumentException - * Thrown if the given entity is not a bundle entity. - */ - public function duplicateFields(ConfigEntityInterface $bundle_entity, $target_bundle_id); - - /** - * Duplicates the bundle entity's view/form displays. - * - * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity - * The bundle entity. - * @param string $target_bundle_id - * The target bundle ID. - * - * @throws \InvalidArgumentException - * Thrown if the given entity is not a bundle entity. - */ - public function duplicateDisplays(ConfigEntityInterface $bundle_entity, $target_bundle_id); - -} diff --git a/web/modules/entity/src/BundleFieldDefinition.php b/web/modules/entity/src/BundleFieldDefinition.php deleted file mode 100644 index 9da74c87b257b1910c05a5815fc8278b2ce1c321..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundleFieldDefinition.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Field\BaseFieldDefinition; - -/** - * Provides a field definition class for bundle fields. - * - * Core currently doesn't provide one, the hook_entity_bundle_field_info() - * example uses BaseFieldDefinition, which is wrong. Tracked in #2346347. - * - * Note that this class implements both FieldStorageDefinitionInterface and - * FieldDefinitionInterface. This is a simplification for DX reasons, - * allowing code to return just the bundle definitions instead of having to - * return both storage definitions and bundle definitions. - */ -class BundleFieldDefinition extends BaseFieldDefinition { - - /** - * {@inheritdoc} - */ - public function isBaseField() { - return FALSE; - } - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginHandler.php b/web/modules/entity/src/BundlePlugin/BundlePluginHandler.php deleted file mode 100644 index bd0ee7cba75429bf3932e8bfe5cb0850e0bc6ce0..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginHandler.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -class BundlePluginHandler implements BundlePluginHandlerInterface { - - /** - * The entity type. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - - /** - * The bundle plugin manager. - * - * @var \Drupal\Component\Plugin\PluginManagerInterface - */ - protected $pluginManager; - - /** - * Constructs a new BundlePluginHandler object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager - * The bundle plugin manager. - */ - public function __construct(EntityTypeInterface $entity_type, PluginManagerInterface $plugin_manager) { - $this->entityType = $entity_type; - $this->pluginManager = $plugin_manager; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('plugin.manager.' . $entity_type->get('bundle_plugin_type')) - ); - } - - /** - * {@inheritdoc} - */ - public function getBundleInfo() { - $bundles = []; - foreach ($this->pluginManager->getDefinitions() as $plugin_id => $definition) { - $bundles[$plugin_id] = [ - 'label' => $definition['label'], - 'description' => isset($definition['description']) ? $definition['description'] : '', - 'translatable' => $this->entityType->isTranslatable(), - 'provider' => $definition['provider'], - ]; - } - return $bundles; - } - - /** - * {@inheritdoc} - */ - public function getFieldStorageDefinitions() { - $definitions = []; - foreach (array_keys($this->pluginManager->getDefinitions()) as $plugin_id) { - $plugin = $this->pluginManager->createInstance($plugin_id); - assert($plugin instanceof BundlePluginInterface); - $definitions += $plugin->buildFieldDefinitions(); - } - // Ensure the presence of required keys which aren't set by the plugin. - foreach ($definitions as $field_name => $definition) { - $definition->setName($field_name); - $definition->setTargetEntityTypeId($this->entityType->id()); - $definitions[$field_name] = $definition; - } - - return $definitions; - } - - /** - * {@inheritdoc} - */ - public function getFieldDefinitions($bundle) { - $plugin = $this->pluginManager->createInstance($bundle); - assert($plugin instanceof BundlePluginInterface); - $definitions = $plugin->buildFieldDefinitions(); - // Ensure the presence of required keys which aren't set by the plugin. - foreach ($definitions as $field_name => $definition) { - $definition->setName($field_name); - $definition->setTargetEntityTypeId($this->entityType->id()); - $definition->setTargetBundle($bundle); - $definitions[$field_name] = $definition; - } - - return $definitions; - } - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginHandlerInterface.php b/web/modules/entity/src/BundlePlugin/BundlePluginHandlerInterface.php deleted file mode 100644 index 5702fb58c15426b38849bbc231bcc432a1303617..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginHandlerInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Core\Entity\EntityHandlerInterface; - -/** - * Handles plugin-provided bundles. - */ -interface BundlePluginHandlerInterface extends EntityHandlerInterface { - - /** - * Gets the bundle info. - * - * @return array - * An array of bundle information keyed by the bundle name. - * The format expected by hook_entity_bundle_info(). - */ - public function getBundleInfo(); - - /** - * Gets the field storage definitions. - */ - public function getFieldStorageDefinitions(); - - /** - * Gets the field definitions for a specific bundle. - * - * @param string $bundle - * The bundle name. - * - * @return \Drupal\entity\BundleFieldDefinition[] - * An array of bundle field definitions, keyed by field name. - */ - public function getFieldDefinitions($bundle); - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginInstaller.php b/web/modules/entity/src/BundlePlugin/BundlePluginInstaller.php deleted file mode 100644 index 1a08b0188af66c34ef5d1a7295131328184f6454..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginInstaller.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Core\Entity\EntityBundleListenerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Field\FieldDefinitionListenerInterface; -use Drupal\Core\Field\FieldStorageDefinitionListenerInterface; - -class BundlePluginInstaller implements BundlePluginInstallerInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The entity bundle listener. - * - * @var \Drupal\Core\Entity\EntityBundleListenerInterface - */ - protected $entityBundleListener; - - /** - * The field storage definition listener. - * - * @var \Drupal\Core\Field\FieldStorageDefinitionListenerInterface - */ - protected $fieldStorageDefinitionListener; - - /** - * The field definition listener. - * - * @var \Drupal\Core\Field\FieldDefinitionListenerInterface - */ - protected $fieldDefinitionListener; - - /** - * Constructs a new BundlePluginInstaller object. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Entity\EntityBundleListenerInterface $entity_bundle_listener - * The entity bundle listener. - * @param \Drupal\Core\Field\FieldStorageDefinitionListenerInterface $field_storage_definition_listener - * The field storage definition listener. - * @param \Drupal\Core\Field\FieldDefinitionListenerInterface $field_definition_listener - * The field definition listener. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityBundleListenerInterface $entity_bundle_listener, FieldStorageDefinitionListenerInterface $field_storage_definition_listener, FieldDefinitionListenerInterface $field_definition_listener) { - $this->entityTypeManager = $entity_type_manager; - $this->entityBundleListener = $entity_bundle_listener; - $this->fieldStorageDefinitionListener = $field_storage_definition_listener; - $this->fieldDefinitionListener = $field_definition_listener; - } - - /** - * {@inheritdoc} - */ - public function installBundles(EntityTypeInterface $entity_type, array $modules) { - $bundle_handler = $this->entityTypeManager->getHandler($entity_type->id(), 'bundle_plugin'); - $bundles = array_filter($bundle_handler->getBundleInfo(), function ($bundle_info) use ($modules) { - return in_array($bundle_info['provider'], $modules, TRUE); - }); - foreach (array_keys($bundles) as $bundle) { - $this->entityBundleListener->onBundleCreate($bundle, $entity_type->id()); - foreach ($bundle_handler->getFieldDefinitions($bundle) as $definition) { - $this->fieldStorageDefinitionListener->onFieldStorageDefinitionCreate($definition); - $this->fieldDefinitionListener->onFieldDefinitionCreate($definition); - } - } - } - - /** - * {@inheritdoc} - */ - public function uninstallBundles(EntityTypeInterface $entity_type, array $modules) { - $bundle_handler = $this->entityTypeManager->getHandler($entity_type->id(), 'bundle_plugin'); - $bundles = array_filter($bundle_handler->getBundleInfo(), function ($bundle_info) use ($modules) { - return in_array($bundle_info['provider'], $modules, TRUE); - }); - - /** - * We need to uninstall the field storage definitions in a separate loop. - * - * This way we can allow a module to re-use the same field within multiple - * bundles, allowing e.g to subclass a bundle plugin. - * - * @var \Drupal\entity\BundleFieldDefinition[] $field_storage_definitions - */ - $field_storage_definitions = []; - - foreach (array_keys($bundles) as $bundle) { - $this->entityBundleListener->onBundleDelete($bundle, $entity_type->id()); - foreach ($bundle_handler->getFieldDefinitions($bundle) as $definition) { - $this->fieldDefinitionListener->onFieldDefinitionDelete($definition); - $field_storage_definitions[$definition->getName()] = $definition; - } - } - - foreach ($field_storage_definitions as $definition) { - $this->fieldStorageDefinitionListener->onFieldStorageDefinitionDelete($definition); - } - } - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginInstallerInterface.php b/web/modules/entity/src/BundlePlugin/BundlePluginInstallerInterface.php deleted file mode 100644 index afeacee48d5b01b1575607ece25d7d43e33ed4ad..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginInstallerInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Installs and uninstalls bundle plugins. - * - * Ensures that the fields provided by the bundle plugins are created/deleted. - */ -interface BundlePluginInstallerInterface { - - /** - * Installs the bundle plugins provided by the specified modules. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param array $modules - * The modules. - */ - public function installBundles(EntityTypeInterface $entity_type, array $modules); - - /** - * Uninstalls the bundle plugins provided by the specified modules. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param array $modules - * The modules. - */ - public function uninstallBundles(EntityTypeInterface $entity_type, array $modules); - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginInterface.php b/web/modules/entity/src/BundlePlugin/BundlePluginInterface.php deleted file mode 100644 index b79e65f4038cc9b4dc4bdcbbc0880480e9af179a..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Component\Plugin\PluginInspectionInterface; - -/** - * Interface for plugins which act as entity bundles. - */ -interface BundlePluginInterface extends PluginInspectionInterface { - - /** - * Builds the field definitions for entities of this bundle. - * - * Important: - * Field names must be unique across all bundles. - * It is recommended to prefix them with the bundle name (plugin ID). - * - * @return \Drupal\entity\BundleFieldDefinition[] - * An array of bundle field definitions, keyed by field name. - */ - public function buildFieldDefinitions(); - -} diff --git a/web/modules/entity/src/BundlePlugin/BundlePluginUninstallValidator.php b/web/modules/entity/src/BundlePlugin/BundlePluginUninstallValidator.php deleted file mode 100644 index c21f625ac24f128419252f149529f5c054761d28..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/BundlePlugin/BundlePluginUninstallValidator.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Drupal\entity\BundlePlugin; - -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\ModuleUninstallValidatorInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; - -/** - * Prevents uninstalling modules with bundle plugins in case of found data. - */ -class BundlePluginUninstallValidator implements ModuleUninstallValidatorInterface { - - use StringTranslationTrait; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs the object. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation service. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) { - $this->entityTypeManager = $entity_type_manager; - $this->stringTranslation = $string_translation; - } - - /** - * {@inheritdoc} - */ - public function validate($module) { - $reasons = []; - - foreach (entity_get_bundle_plugin_entity_types() as $entity_type) { - /** @var \Drupal\entity\BundlePlugin\BundlePluginHandler $bundle_handler */ - $bundle_handler = $this->entityTypeManager->getHandler($entity_type->id(), 'bundle_plugin'); - $bundles = $bundle_handler->getBundleInfo(); - - // We find all bundles which have to be removed due to the uninstallation. - $bundles_filtered_by_module = array_filter($bundles, function ($bundle_info) use ($module) { - return $module === $bundle_info['provider']; - }); - - if (!empty($bundles_filtered_by_module)) { - $bundle_keys_with_content = array_filter(array_keys($bundles_filtered_by_module), function ($bundle) use ($entity_type) { - $result = $this->entityTypeManager->getStorage($entity_type->id())->getQuery() - ->condition($entity_type->getKey('bundle'), $bundle) - ->range(0, 1) - ->execute(); - return !empty($result); - }); - - $bundles_with_content = array_intersect_key($bundles_filtered_by_module, array_flip($bundle_keys_with_content)); - - foreach ($bundles_with_content as $bundle) { - $reasons[] = $this->t('There is data for the bundle @bundle on the entity type @entity_type. Please remove all content before uninstalling the module.', [ - '@bundle' => $bundle['label'], - '@entity_type' => $entity_type->getLabel(), - ]); - } - } - } - - return $reasons; - } - -} diff --git a/web/modules/entity/src/Controller/EntityDuplicateController.php b/web/modules/entity/src/Controller/EntityDuplicateController.php deleted file mode 100644 index ca0edc6afa3e890885e97d81abd4e4692a444b3d..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Controller/EntityDuplicateController.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php - -namespace Drupal\entity\Controller; - -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityRepositoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Form\FormBuilderInterface; -use Drupal\Core\Form\FormState; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -class EntityDuplicateController implements ContainerInjectionInterface { - - use StringTranslationTrait; - - /** - * The entity repository. - * - * @var \Drupal\Core\Entity\EntityRepositoryInterface - */ - protected $entityRepository; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The form builder. - * - * @var \Drupal\Core\Form\FormBuilderInterface - */ - protected $formBuilder; - - /** - * Constructs a new EntityDuplicateController object. - * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository - * The entity repository. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation. - */ - public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeManagerInterface $entity_type_manager, FormBuilderInterface $form_builder, TranslationInterface $string_translation) { - $this->entityRepository = $entity_repository; - $this->entityTypeManager = $entity_type_manager; - $this->formBuilder = $form_builder; - $this->stringTranslation = $string_translation; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.repository'), - $container->get('entity_type.manager'), - $container->get('form_builder'), - $container->get('string_translation') - ); - } - - /** - * Builds the duplicate form. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * - * @return array - * The rendered form. - */ - public function form(RouteMatchInterface $route_match) { - $entity_type_id = $route_match->getRouteObject()->getDefault('entity_type_id'); - $source_entity = $route_match->getParameter($entity_type_id); - $entity = $source_entity->createDuplicate(); - /** @var \Drupal\entity\Form\EntityDuplicateFormInterface $form_object */ - $form_object = $this->entityTypeManager->getFormObject($entity_type_id, 'duplicate'); - $form_object->setEntity($entity); - $form_object->setSourceEntity($source_entity); - $form_state = new FormState(); - - return $this->formBuilder->buildForm($form_object, $form_state); - } - - /** - * Provides the duplicate form title. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * - * @return string - * The duplicate form title. - */ - public function title(RouteMatchInterface $route_match) { - $entity_type_id = $route_match->getRouteObject()->getDefault('entity_type_id'); - $source_entity = $route_match->getParameter($entity_type_id); - $source_entity = $this->entityRepository->getTranslationFromContext($source_entity); - - return $this->t('Duplicate %label', ['%label' => $source_entity->label()]); - } - -} diff --git a/web/modules/entity/src/Controller/RevisionControllerTrait.php b/web/modules/entity/src/Controller/RevisionControllerTrait.php deleted file mode 100644 index a632d331fd93626fee9d0d7470551e7ae58ae896..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Controller/RevisionControllerTrait.php +++ /dev/null @@ -1,193 +0,0 @@ -<?php - -namespace Drupal\entity\Controller; - -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Entity\EntityInterface; - -/** - * Defines a trait for common revision UI functionality. - */ -trait RevisionControllerTrait { - - /** - * Returns the entity type manager. - * - * @return \Drupal\Core\Entity\EntityTypeManagerInterface - */ - abstract protected function entityTypeManager(); - - /** - * Returns the langauge manager. - * - * @return \Drupal\Core\Language\LanguageManagerInterface - */ - abstract public function languageManager(); - - /** - * Determines if the user has permission to revert revisions. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to check revert access for. - * - * @return bool - * TRUE if the user has revert access. - */ - abstract protected function hasRevertRevisionAccess(EntityInterface $entity); - - /** - * Determines if the user has permission to delete revisions. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to check delete revision access for. - * - * @return bool - * TRUE if the user has delete revision access. - */ - abstract protected function hasDeleteRevisionAccess(EntityInterface $entity); - - /** - * Builds a link to revert an entity revision. - * - * @param \Drupal\Core\Entity\EntityInterface $entity_revision - * The entity to build a revert revision link for. - * - * @return array - * A link render array. - */ - abstract protected function buildRevertRevisionLink(EntityInterface $entity_revision); - - /** - * Builds a link to delete an entity revision. - * - * @param \Drupal\Core\Entity\EntityInterface $entity_revision - * The entity to build a delete revision link for. - * - * @return array - * A link render array. - */ - abstract protected function buildDeleteRevisionLink(EntityInterface $entity_revision); - - /** - * Returns a string providing details of the revision. - * - * E.g. Node describes its revisions using {date} by {username}. For the - * non-current revision, it also provides a link to view that revision. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $revision - * The entity revision. - * @param bool $is_current - * TRUE if the revision is the current revision. - * - * @return string - * Returns a string to provide the details of the revision. - */ - abstract protected function getRevisionDescription(ContentEntityInterface $revision, $is_current = FALSE); - - /** - * Loads all revision IDs of an entity sorted by revision ID descending. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity. - * - * @return mixed[] - */ - protected function revisionIds(ContentEntityInterface $entity) { - $entity_type = $entity->getEntityType(); - $result = $this->entityTypeManager()->getStorage($entity_type->id())->getQuery() - ->allRevisions() - ->condition($entity_type->getKey('id'), $entity->id()) - ->sort($entity_type->getKey('revision'), 'DESC') - ->execute(); - return array_keys($result); - } - - /** - * Generates an overview table of older revisions of an entity. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * An entity object. - * - * @return array - * A render array. - */ - protected function revisionOverview(ContentEntityInterface $entity) { - $langcode = $this->languageManager() - ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT) - ->getId(); - /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $entity_storage */ - $entity_storage = $this->entityTypeManager()->getStorage($entity->getEntityTypeId()); - $revision_ids = $this->revisionIds($entity); - $entity_revisions = $entity_storage->loadMultipleRevisions($revision_ids); - $translatable = $entity->getEntityType()->isTranslatable(); - - $header = [$this->t('Revision'), $this->t('Operations')]; - $rows = []; - foreach ($entity_revisions as $revision) { - $row = []; - /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */ - if (!$translatable || ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected())) { - $row[] = $this->getRevisionDescription($revision, $revision->isDefaultRevision()); - - if ($revision->isDefaultRevision()) { - $row[] = [ - 'data' => [ - '#prefix' => '<em>', - '#markup' => $this->t('Current revision'), - '#suffix' => '</em>', - ], - ]; - foreach ($row as &$current) { - $current['class'] = ['revision-current']; - } - } - else { - $links = $this->getOperationLinks($revision); - $row[] = [ - 'data' => [ - '#type' => 'operations', - '#links' => $links, - ], - ]; - } - } - - $rows[] = $row; - } - - $build[$entity->getEntityTypeId() . '_revisions_table'] = [ - '#theme' => 'table', - '#rows' => $rows, - '#header' => $header, - ]; - - // We have no clue about caching yet. - $build['#cache']['max-age'] = 0; - - return $build; - } - - /** - * Get the links of the operations for an entity revision. - * - * @param \Drupal\Core\Entity\EntityInterface $entity_revision - * The entity to build the revision links for. - * - * @return array - * The operation links. - */ - protected function getOperationLinks(EntityInterface $entity_revision) { - $links = []; - if ($this->hasRevertRevisionAccess($entity_revision)) { - $links['revert'] = $this->buildRevertRevisionLink($entity_revision); - } - - if ($this->hasDeleteRevisionAccess($entity_revision)) { - $links['delete'] = $this->buildDeleteRevisionLink($entity_revision); - } - - return array_filter($links); - } - -} diff --git a/web/modules/entity/src/Controller/RevisionOverviewController.php b/web/modules/entity/src/Controller/RevisionOverviewController.php deleted file mode 100644 index c80dfcd431b6323d5461575c6f4206091162de85..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Controller/RevisionOverviewController.php +++ /dev/null @@ -1,160 +0,0 @@ -<?php - -namespace Drupal\entity\Controller; - -use Drupal\Component\Utility\Xss; -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Entity\RevisionLogInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a controller which shows the revision history. - * - * This controller leverages the revision controller trait, which is agnostic to - * any entity type, by using \Drupal\Core\Entity\RevisionLogInterface. - */ -class RevisionOverviewController extends ControllerBase { - - use RevisionControllerTrait; - - /** - * The date formatter. - * - * @var \Drupal\Core\Datetime\DateFormatterInterface - */ - protected $dateFormatter; - - /** - * The renderer. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * Creates a new RevisionOverviewController instance. - * - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter - * The date formatter. - */ - public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer) { - $this->dateFormatter = $date_formatter; - $this->renderer = $renderer; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static($container->get('date.formatter'), $container->get('renderer')); - } - - /** - * {@inheritdoc} - */ - protected function hasDeleteRevisionAccess(EntityInterface $entity) { - return $this->currentUser()->hasPermission("delete all {$entity->getEntityTypeId()} revisions"); - } - - /** - * {@inheritdoc} - */ - protected function buildRevertRevisionLink(EntityInterface $entity_revision) { - if ($entity_revision->hasLinkTemplate('revision-revert-form')) { - return [ - 'title' => $this->t('Revert'), - 'url' => $entity_revision->toUrl('revision-revert-form'), - ]; - } - } - - /** - * {@inheritdoc} - */ - protected function buildDeleteRevisionLink(EntityInterface $entity_revision) { - if ($entity_revision->hasLinkTemplate('revision-delete-form')) { - return [ - 'title' => $this->t('Delete'), - 'url' => $entity_revision->toUrl('revision-delete-form'), - ]; - } - } - - /** - * Generates an overview table of older revisions of an entity. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * - * @return array - * A render array. - */ - public function revisionOverviewController(RouteMatchInterface $route_match) { - return $this->revisionOverview($route_match->getParameter($route_match->getRouteObject()->getOption('entity_type_id'))); - } - - /** - * {@inheritdoc} - */ - protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE) { - /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */ - if ($revision instanceof RevisionLogInterface) { - // Use revision link to link to revisions that are not active. - $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short'); - $link = $revision->toLink($date, 'revision'); - - // @todo: Simplify this when https://www.drupal.org/node/2334319 lands. - $username = [ - '#theme' => 'username', - '#account' => $revision->getRevisionUser(), - ]; - $username = $this->renderer->render($username); - } - else { - $link = $revision->toLink($revision->label(), 'revision'); - $username = ''; - - } - - $markup = ''; - if ($revision instanceof RevisionLogInterface) { - $markup = $revision->getRevisionLogMessage(); - } - - if ($username) { - $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}'; - } - else { - $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}'; - } - - $column = [ - 'data' => [ - '#type' => 'inline_template', - '#template' => $template, - '#context' => [ - 'date' => $link->toString(), - 'username' => $username, - 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()], - ], - ], - ]; - return $column; - } - - /** - * {@inheritdoc} - */ - protected function hasRevertRevisionAccess(EntityInterface $entity) { - return AccessResult::allowedIfHasPermission($this->currentUser(), "revert all {$entity->getEntityTypeId()} revisions")->orIf( - AccessResult::allowedIfHasPermission($this->currentUser(), "revert {$entity->bundle()} {$entity->getEntityTypeId()} revisions") - ); - } - -} diff --git a/web/modules/entity/src/Entity/RevisionableEntityBundleInterface.php b/web/modules/entity/src/Entity/RevisionableEntityBundleInterface.php deleted file mode 100644 index 18d392a06f5d131e96457e28e20695fe6ac306a4..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Entity/RevisionableEntityBundleInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace Drupal\entity\Entity; - -use Drupal\Core\Entity\RevisionableEntityBundleInterface as CoreRevisionableEntityBundleInterface; - -@trigger_error('\Drupal\entity\Entity\RevisionableEntityBundleInterface has been deprecated in favor of \Drupal\Core\Entity\RevisionableEntityBundleInterface. Use that instead.'); - -/** - * @deprecated in favor of - * \Drupal\Core\Entity\RevisionableEntityBundleInterface. Use that instead. - */ -interface RevisionableEntityBundleInterface extends CoreRevisionableEntityBundleInterface { -} diff --git a/web/modules/entity/src/EntityAccessControlHandler.php b/web/modules/entity/src/EntityAccessControlHandler.php deleted file mode 100644 index 01f8fd6f59c522ac9aed8fc306d5d36e96eb3f0d..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityAccessControlHandler.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Session\AccountInterface; - -/** - * Controls access based on the generic entity permissions. - * - * @see \Drupal\entity\UncacheableEntityPermissionProvider - */ -class EntityAccessControlHandler extends EntityAccessControlHandlerBase { - - /** - * {@inheritdoc} - */ - public function __construct(EntityTypeInterface $entity_type) { - parent::__construct($entity_type); - - if (!$entity_type->hasHandlerClass('permission_provider') || !is_a($entity_type->getHandlerClass('permission_provider'), EntityPermissionProvider::class, TRUE)) { - throw new \Exception('\Drupal\entity\EntityAccessControlHandler requires the \Drupal\entity\EntityPermissionProvider permission provider.'); - } - } - - /** - * {@inheritdoc} - */ - protected function checkEntityOwnerPermissions(EntityInterface $entity, $operation, AccountInterface $account) { - /** @var \Drupal\user\EntityOwnerInterface $entity */ - if ($operation === 'view') { - if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) { - if ($account->id() != $entity->getOwnerId()) { - // There's no permission for viewing other user's unpublished entity. - return AccessResult::neutral()->cachePerUser(); - } - - $permissions = [ - "view own unpublished {$entity->getEntityTypeId()}", - ]; - $result = AccessResult::allowedIfHasPermissions($account, $permissions)->cachePerUser(); - } - else { - $result = AccessResult::allowedIfHasPermissions($account, [ - "view {$entity->getEntityTypeId()}", - "view {$entity->bundle()} {$entity->getEntityTypeId()}", - ], 'OR'); - } - } - else { - $result = parent::checkEntityOwnerPermissions($entity, $operation, $account); - } - - return $result; - } - -} diff --git a/web/modules/entity/src/EntityAccessControlHandlerBase.php b/web/modules/entity/src/EntityAccessControlHandlerBase.php deleted file mode 100644 index 3d007ace2630a1cb078315c79c17d5abb85df275..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityAccessControlHandlerBase.php +++ /dev/null @@ -1,121 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\EntityAccessControlHandler as CoreEntityAccessControlHandler; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\user\EntityOwnerInterface; - -/** - * @internal - */ -class EntityAccessControlHandlerBase extends CoreEntityAccessControlHandler { - - /** - * {@inheritdoc} - */ - protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { - $account = $this->prepareUser($account); - /** @var \Drupal\Core\Access\AccessResult $result */ - $result = parent::checkAccess($entity, $operation, $account); - - if ($result->isNeutral()) { - if ($entity instanceof EntityOwnerInterface) { - $result = $this->checkEntityOwnerPermissions($entity, $operation, $account); - } - else { - $result = $this->checkEntityPermissions($entity, $operation, $account); - } - } - - // Ensure that access is evaluated again when the entity changes. - return $result->addCacheableDependency($entity); - } - - /** - * Checks the entity operation and bundle permissions. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity for which to check access. - * @param string $operation - * The entity operation. Usually one of 'view', 'view label', 'update', - * 'duplicate' or 'delete'. - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to check access. - * - * @return \Drupal\Core\Access\AccessResultInterface - * The access result. - */ - protected function checkEntityPermissions(EntityInterface $entity, $operation, AccountInterface $account) { - $permissions = [ - "$operation {$entity->getEntityTypeId()}", - "$operation {$entity->bundle()} {$entity->getEntityTypeId()}", - ]; - - return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR'); - } - - /** - * Checks the entity operation and bundle permissions, with owners. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity for which to check access. - * @param string $operation - * The entity operation. Usually one of 'view', 'view label', 'update', - * 'duplicate' or 'delete'. - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to check access. - * - * @return \Drupal\Core\Access\AccessResultInterface - * The access result. - */ - protected function checkEntityOwnerPermissions(EntityInterface $entity, $operation, AccountInterface $account) { - /** @var \Drupal\user\EntityOwnerInterface $entity */ - // The "any" permission grants access regardless of the entity owner. - $any_result = AccessResult::allowedIfHasPermissions($account, [ - "$operation any {$entity->getEntityTypeId()}", - "$operation any {$entity->bundle()} {$entity->getEntityTypeId()}", - ], 'OR'); - - if ($any_result->isAllowed()) { - return $any_result; - } - - if ($account->id() == $entity->getOwnerId()) { - $own_result = AccessResult::allowedIfHasPermissions($account, [ - "$operation own {$entity->getEntityTypeId()}", - "$operation own {$entity->bundle()} {$entity->getEntityTypeId()}", - ], 'OR'); - } - else { - $own_result = AccessResult::neutral()->cachePerPermissions(); - } - - // The "own" permission is based on the current user's ID, so the result - // must be cached per user. - return $own_result->cachePerUser(); - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - $result = parent::checkCreateAccess($account, $context, $entity_bundle); - if ($result->isNeutral()) { - $permissions = [ - $this->entityType->getAdminPermission() ?: 'administer ' . $this->entityTypeId, - 'create ' . $this->entityTypeId, - ]; - if ($entity_bundle) { - $permissions[] = 'create ' . $entity_bundle . ' ' . $this->entityTypeId; - } - - $result = AccessResult::allowedIfHasPermissions($account, $permissions, 'OR'); - } - - return $result; - } - -} diff --git a/web/modules/entity/src/EntityPermissionProvider.php b/web/modules/entity/src/EntityPermissionProvider.php deleted file mode 100644 index 2803b1e886aafe991746eb1a6342a624755ad786..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityPermissionProvider.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Provides generic entity permissions. - * - * Intended for content entity types, since config entity types usually rely - * on a single "administer" permission. - * - * Provided permissions: - * - The declared "admin_permission" of the entity type (or - * "administer $entity_type" if the entity type does not declare an - * administrative permission) - * - access $entity_type overview - * - view own unpublished $entity_type - * - view ($bundle) $entity_type - * - update (own|any) ($bundle) $entity_type - * - duplicate (own|any) ($bundle) $entity_type - * - delete (own|any) ($bundle) $entity_type - * - create $bundle $entity_type - * - * Does not provide "view own ($bundle) $entity_type" permissions, because - * they require caching pages per user. Please use - * \Drupal\entity\UncacheableEntityPermissionProvider if those permissions - * are necessary. - * - * Example annotation: - * @code - * handlers = { - * "access" = "Drupal\entity\EntityAccessControlHandler", - * "permission_provider" = "Drupal\entity\EntityPermissionProvider", - * } - * @endcode - * - * @see \Drupal\entity\EntityAccessControlHandler - * @see \Drupal\entity\EntityPermissions - */ -class EntityPermissionProvider extends EntityPermissionProviderBase { - - /** - * Builds permissions for the entity_type granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildEntityTypePermissions(EntityTypeInterface $entity_type) { - $permissions = parent::buildEntityTypePermissions($entity_type); - $entity_type_id = $entity_type->id(); - $plural_label = $entity_type->getPluralLabel(); - - $permissions["view {$entity_type_id}"] = [ - 'title' => $this->t('View @type', [ - '@type' => $plural_label, - ]), - ]; - - return $permissions; - } - - /** - * Builds permissions for the bundle granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildBundlePermissions(EntityTypeInterface $entity_type) { - $permissions = parent::buildBundlePermissions($entity_type); - $entity_type_id = $entity_type->id(); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - $plural_label = $entity_type->getPluralLabel(); - - $permissions["view {$entity_type_id}"] = [ - 'title' => $this->t('View @type', [ - '@type' => $plural_label, - ]), - ]; - foreach ($bundles as $bundle_name => $bundle_info) { - $permissions["view {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: View @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - - return $permissions; - } - -} diff --git a/web/modules/entity/src/EntityPermissionProviderBase.php b/web/modules/entity/src/EntityPermissionProviderBase.php deleted file mode 100644 index 4ccb9ca9843d8ccdc386e5b397f8559e7f529174..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityPermissionProviderBase.php +++ /dev/null @@ -1,278 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityHandlerInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\user\EntityOwnerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * @internal - */ -class EntityPermissionProviderBase implements EntityPermissionProviderInterface, EntityHandlerInterface { - - use StringTranslationTrait; - - /** - * The entity type bundle info. - * - * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface - */ - protected $entityTypeBundleInfo; - - /** - * Constructs a new EntityPermissionProvider object. - * - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info - * The entity type bundle info. - */ - public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info) { - $this->entityTypeBundleInfo = $entity_type_bundle_info; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $container->get('entity_type.bundle.info') - ); - } - - /** - * {@inheritdoc} - */ - public function buildPermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - - $admin_permission = $entity_type->getAdminPermission() ?: "administer {$entity_type_id}"; - $permissions[$admin_permission] = [ - 'title' => $this->t('Administer @type', ['@type' => $plural_label]), - 'restrict access' => TRUE, - ]; - if ($entity_type->hasLinkTemplate('collection')) { - $permissions["access {$entity_type_id} overview"] = [ - 'title' => $this->t('Access the @type overview page', ['@type' => $plural_label]), - ]; - } - if ($has_owner && $entity_type->entityClassImplements(EntityPublishedInterface::class)) { - $permissions["view own unpublished {$entity_type_id}"] = [ - 'title' => $this->t('View own unpublished @type', [ - '@type' => $plural_label, - ]), - ]; - } - - // Generate the other permissions based on granularity. - if ($entity_type->getPermissionGranularity() === 'entity_type') { - $permissions += $this->buildEntityTypePermissions($entity_type); - } - else { - $permissions += $this->buildBundlePermissions($entity_type); - } - - return $this->processPermissions($permissions, $entity_type); - } - - /** - * Adds the provider and converts the titles to strings to allow sorting. - * - * @param array $permissions - * The array of permissions. - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * An array of processed permissions. - */ - protected function processPermissions(array $permissions, EntityTypeInterface $entity_type) { - foreach ($permissions as $name => $permission) { - // Permissions are grouped by provider on admin/people/permissions. - $permissions[$name]['provider'] = $entity_type->getProvider(); - // TranslatableMarkup objects don't sort properly. - $permissions[$name]['title'] = (string) $permission['title']; - } - return $permissions; - } - - /** - * Builds permissions for the entity_type granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildEntityTypePermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $has_duplicate_form = $entity_type->hasLinkTemplate('duplicate-form'); - $singular_label = $entity_type->getSingularLabel(); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - $permissions["create {$entity_type_id}"] = [ - 'title' => $this->t('Create @type', [ - '@type' => $plural_label, - ]), - ]; - if ($has_owner) { - $permissions["update any {$entity_type_id}"] = [ - 'title' => $this->t('Update any @type', [ - '@type' => $singular_label, - ]), - ]; - $permissions["update own {$entity_type_id}"] = [ - 'title' => $this->t('Update own @type', [ - '@type' => $plural_label, - ]), - ]; - if ($has_duplicate_form) { - $permissions["duplicate any {$entity_type_id}"] = [ - 'title' => $this->t('Duplicate any @type', [ - '@type' => $singular_label, - ]), - ]; - $permissions["duplicate own {$entity_type_id}"] = [ - 'title' => $this->t('Duplicate own @type', [ - '@type' => $plural_label, - ]), - ]; - } - $permissions["delete any {$entity_type_id}"] = [ - 'title' => $this->t('Delete any @type', [ - '@type' => $singular_label, - ]), - ]; - $permissions["delete own {$entity_type_id}"] = [ - 'title' => $this->t('Delete own @type', [ - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["update {$entity_type_id}"] = [ - 'title' => $this->t('Update @type', [ - '@type' => $plural_label, - ]), - ]; - if ($has_duplicate_form) { - $permissions["duplicate {$entity_type_id}"] = [ - 'title' => $this->t('Duplicate @type', [ - '@type' => $plural_label, - ]), - ]; - } - $permissions["delete {$entity_type_id}"] = [ - 'title' => $this->t('Delete @type', [ - '@type' => $plural_label, - ]), - ]; - } - - return $permissions; - } - - /** - * Builds permissions for the bundle granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildBundlePermissions(EntityTypeInterface $entity_type) { - $entity_type_id = $entity_type->id(); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $has_duplicate_form = $entity_type->hasLinkTemplate('duplicate-form'); - $singular_label = $entity_type->getSingularLabel(); - $plural_label = $entity_type->getPluralLabel(); - - $permissions = []; - foreach ($bundles as $bundle_name => $bundle_info) { - $permissions["create {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Create @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - - if ($has_owner) { - $permissions["update any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $singular_label, - ]), - ]; - $permissions["update own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - if ($has_duplicate_form) { - $permissions["duplicate any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Duplicate any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $singular_label, - ]), - ]; - $permissions["duplicate own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Duplicate own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - $permissions["delete any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $singular_label, - ]), - ]; - $permissions["delete own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["update {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Update @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - if ($has_duplicate_form) { - $permissions["duplicate {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Duplicate @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - $permissions["delete {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: Delete @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - } - - return $permissions; - } - -} diff --git a/web/modules/entity/src/EntityPermissionProviderInterface.php b/web/modules/entity/src/EntityPermissionProviderInterface.php deleted file mode 100644 index 50f3ccaa9490a83f16905d186979d7a1be0bcedd..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityPermissionProviderInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Allows entity types to provide permissions. - */ -interface EntityPermissionProviderInterface { - - /** - * Builds permissions for the given entity type. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - public function buildPermissions(EntityTypeInterface $entity_type); - -} diff --git a/web/modules/entity/src/EntityPermissions.php b/web/modules/entity/src/EntityPermissions.php deleted file mode 100644 index c2c13a562e6e710d454dcc6233fd4404afe4935b..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityPermissions.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Generates entity permissions via their permission providers. - * - * @see \Drupal\entity\EntityPermissionProvider - * @see \Drupal\entity\UncacheableEntityPermissionProvider - */ -class EntityPermissions implements ContainerInjectionInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs a new EntityPermissions object. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_type.manager') - ); - } - - /** - * Builds a list of permissions for the participating entity types. - * - * @return array - * The permissions. - */ - public function buildPermissions() { - $permissions = []; - /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ - foreach ($this->entityTypeManager->getDefinitions() as $entity_type) { - if ($entity_type->hasHandlerClass('permission_provider')) { - $permission_provider_class = $entity_type->getHandlerClass('permission_provider'); - $permission_provider = $this->entityTypeManager->createHandlerInstance($permission_provider_class, $entity_type); - $permissions += $permission_provider->buildPermissions($entity_type); - } - } - - return $permissions; - } - -} diff --git a/web/modules/entity/src/EntityViewBuilder.php b/web/modules/entity/src/EntityViewBuilder.php deleted file mode 100644 index 1efe0ebe6a9ce85351c59f87d7eb09c031390eb9..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityViewBuilder.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityViewBuilder as CoreEntityViewBuilder; - -@trigger_error('\Drupal\entity\EntityViewBuilder has been deprecated in favor of \Drupal\Core\Entity\EntityViewBuilder. Use that instead.'); - -/** - * Provides a entity view builder with contextual links support. - * - * @deprecated in favor of \Drupal\Core\Entity\EntityViewBuilder. Use that - * instead. - */ -class EntityViewBuilder extends CoreEntityViewBuilder { - -} diff --git a/web/modules/entity/src/EntityViewsData.php b/web/modules/entity/src/EntityViewsData.php deleted file mode 100644 index 4bad6a7dd86b57d9f7b5ac42e3edffe846794158..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EntityViewsData.php +++ /dev/null @@ -1,441 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\ContentEntityType; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\Sql\TableMappingInterface; -use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\views\EntityViewsData as CoreEntityViewsData; - -/** - * Provides improvements to core's generic views integration for entities. - * - * Contains special handling for the following base field types: - * - datetime - * - list_float, list_integer, list_string - * Workaround for core issue #2337515. - * - * Provides views data for bundle plugin fields, - * as a workaround for core issue #2898635. - * - * Provides the missing delta field for multi-value fields, - * as a workaround for core issue #3097568. - * - * Fixes handling of fields with multiple properties, - * as a workaround for core issue #3097636. - * - * Provides reverse relationships for base entity_reference fields, - * as a workaround for core issue #2706431. - */ -class EntityViewsData extends CoreEntityViewsData { - - /** - * The table mapping. - * - * @var \Drupal\Core\Entity\Sql\DefaultTableMapping - */ - protected $tableMapping; - - /** - * {@inheritdoc} - */ - public function getViewsData() { - $data = parent::getViewsData(); - - $this->tableMapping = $this->storage->getTableMapping(); - $entity_type_id = $this->entityType->id(); - // Workaround for core issue #3004300. - if ($this->entityType->isRevisionable()) { - $revision_table = $this->tableMapping->getRevisionTable(); - $data[$revision_table]['table']['entity revision'] = TRUE; - } - // Add missing reverse relationships. Workaround for core issue #2706431. - $base_fields = $this->getEntityFieldManager()->getBaseFieldDefinitions($entity_type_id); - $entity_reference_fields = array_filter($base_fields, function (BaseFieldDefinition $field) { - return $field->getType() == 'entity_reference'; - }); - $this->addReverseRelationships($data, $entity_reference_fields); - // Add views integration for bundle plugin fields. - // Workaround for core issue #2898635. - if ($this->entityType->hasHandlerClass('bundle_plugin')) { - $bundles = $this->getEntityTypeBundleInfo()->getBundleInfo($entity_type_id); - foreach (array_keys($bundles) as $bundle) { - $field_definitions = $this->getEntityFieldManager()->getFieldDefinitions($entity_type_id, $bundle); - foreach ($field_definitions as $field_definition) { - if ($field_definition instanceof BundleFieldDefinition) { - $this->addBundleFieldData($data, $field_definition); - } - } - } - } - - return $data; - } - - /** - * Adds views data for the given bundle field. - * - * Based on views_field_default_views_data(), which is only invoked - * for configurable fields. - * - * Assumes that the bundle field is not shared between bundles, since - * the bundle plugin API doesn't support that. - * - * @param array $data - * The views data. - * @param \Drupal\entity\BundleFieldDefinition $bundle_field - * The bundle field. - */ - protected function addBundleFieldData(array &$data, BundleFieldDefinition $bundle_field) { - $field_name = $bundle_field->getName(); - $entity_type_id = $this->entityType->id(); - $base_table = $this->getViewsTableForEntityType($this->entityType); - $revision_table = ''; - if ($this->entityType->isRevisionable()) { - $revision_table = $this->tableMapping->getRevisionDataTable(); - if (!$revision_table) { - $revision_table = $this->tableMapping->getRevisionTable(); - } - } - - $field_tables = []; - $field_tables[EntityStorageInterface::FIELD_LOAD_CURRENT] = [ - 'table' => $this->tableMapping->getDedicatedDataTableName($bundle_field), - 'alias' => "{$entity_type_id}__{$field_name}", - ]; - if ($this->entityType->isRevisionable()) { - $field_tables[EntityStorageInterface::FIELD_LOAD_REVISION] = [ - 'table' => $this->tableMapping->getDedicatedRevisionTableName($bundle_field), - 'alias' => "{$entity_type_id}_revision__{$field_name}", - ]; - } - - $table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_CURRENT]['alias']; - $data[$table_alias]['table']['group'] = $this->entityType->getLabel(); - $data[$table_alias]['table']['join'][$base_table] = [ - 'table' => $this->tableMapping->getDedicatedDataTableName($bundle_field), - 'left_field' => $this->entityType->getKey('id'), - 'field' => 'entity_id', - 'extra' => [ - ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE], - ], - ]; - if ($bundle_field->isTranslatable()) { - $data[$table_alias]['table']['join'][$base_table]['extra'][] = [ - 'left_field' => 'langcode', - 'field' => 'langcode', - ]; - } - - if ($this->entityType->isRevisionable()) { - $table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_REVISION]['alias']; - $data[$table_alias]['table']['group'] = $this->t('@group (historical data)', [ - '@group' => $this->entityType->getLabel(), - ]); - $data[$table_alias]['table']['join'][$revision_table] = [ - 'table' => $this->tableMapping->getDedicatedRevisionTableName($bundle_field), - 'left_field' => $this->entityType->getKey('revision'), - 'field' => 'revision_id', - 'extra' => [ - ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE], - ], - ]; - if ($bundle_field->isTranslatable()) { - $data[$table_alias]['table']['join'][$revision_table]['extra'][] = [ - 'left_field' => 'langcode', - 'field' => 'langcode', - ]; - } - } - - foreach ($field_tables as $type => $table_info) { - $table_alias = $table_info['alias']; - $data[$table_alias]['table']['title'] = $bundle_field->getLabel(); - $data[$table_alias]['table']['help'] = $bundle_field->getDescription(); - $data[$table_alias]['table']['entity type'] = $this->entityType->id(); - $data[$table_alias]['table']['provider'] = $this->entityType->getProvider(); - - $this->mapFieldDefinition($table_info['table'], $field_name, $bundle_field, $this->tableMapping, $data[$table_alias]); - } - } - - /** - * {@inheritDoc} - */ - protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterface $field_definition, TableMappingInterface $table_mapping, &$table_data) { - $field_column_mapping = $table_mapping->getColumnNames($field_name); - $field_storage = $this->getFieldStorageDefinitions()[$field_name]; - $field_schema = $field_storage->getSchema(); - - $field_definition_type = $field_definition->getType(); - // Add all properties to views table data. We need an entry for each - // column of each field, with the main one given special treatment. - $main_property = $field_storage->getMainPropertyName(); - if (!$main_property) { - // The mapSingleFieldViewsData() method always expects a main property, - // so there must be a fallback to the first defined property. - // See #2337517 for the related core issue. - $property_names = array_keys($field_column_mapping); - $main_property = reset($property_names); - } - foreach ($field_column_mapping as $field_column_name => $schema_field_name) { - $first = ($main_property == $field_column_name); - $table_data[$schema_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $field_definition_type, $field_column_name, $field_schema['columns'][$field_column_name]['type'], $first, $field_definition); - $table_data[$schema_field_name]['entity field'] = $field_name; - // By default core makes every property render the entire field, which - // confuses users. Fix that so only the property itself is rendered. - // Workaround for core issue #3097636. - if (!$first && $table_data[$schema_field_name]['field']['id'] == 'field') { - $table_data[$schema_field_name]['field']['id'] = 'standard'; - } - // Many handlers (datetime, list) crash without the field_name defined. - foreach (['argument', 'filter', 'sort'] as $handler_type) { - if (isset($table_data[$schema_field_name][$handler_type])) { - $table_data[$schema_field_name][$handler_type]['field_name'] = $field_name; - } - } - } - - // Expose additional delta column for multiple value fields. - // Workaround for core issue #3097568. - if ($field_storage->isMultiple()) { - $label = $field_definition->getLabel(); - - $table_data['delta'] = [ - 'title' => t('@label (@name:delta)', ['@label' => $label, '@name' => $field_name]), - 'title short' => t('@label:delta', ['@label' => $label]), - ]; - $table_data['delta']['field'] = [ - 'id' => 'numeric', - ]; - $table_data['delta']['argument'] = [ - 'field' => 'delta', - 'table' => $table, - 'id' => 'numeric', - 'empty field name' => $this->t('- No value -'), - 'field_name' => $field_name, - 'entity_type' => $this->entityType->id(), - ]; - $table_data['delta']['filter'] = [ - 'field' => 'delta', - 'table' => $table, - 'id' => 'numeric', - 'field_name' => $field_name, - 'entity_type' => $this->entityType->id(), - 'allow empty' => TRUE, - ]; - $table_data['delta']['sort'] = [ - 'field' => 'delta', - 'table' => $table, - 'id' => 'standard', - 'field_name' => $field_name, - 'entity_type' => $this->entityType->id(), - ]; - } - } - - /** - * Corrects the views data for datetime base fields. - * - * Based on datetime_field_views_data(). - * - * @param string $table - * The table name. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The field definition. - * @param array $views_field - * The views field data. - * @param string $field_column_name - * The field column being processed. - */ - protected function processViewsDataForDatetime($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) { - if ($field_column_name == 'value') { - $views_field['filter']['id'] = 'datetime'; - $views_field['argument']['id'] = 'datetime'; - $views_field['sort']['id'] = 'datetime'; - } - } - - /** - * Corrects the views data for list_float base fields. - * - * Based on options_field_views_data(). - * - * @param string $table - * The table name. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The field definition. - * @param array $views_field - * The views field data. - * @param string $field_column_name - * The field column being processed. - */ - protected function processViewsDataForListFloat($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) { - $this->processViewsDataForListInteger($table, $field_definition, $views_field, $field_column_name); - } - - /** - * Corrects the views data for list_integer base fields. - * - * Based on options_field_views_data(). - * - * @param string $table - * The table name. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The field definition. - * @param array $views_field - * The views field data. - * @param string $field_column_name - * The field column being processed. - */ - protected function processViewsDataForListInteger($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) { - if ($field_column_name == 'value') { - $views_field['filter']['id'] = 'list_field'; - $views_field['argument']['id'] = 'number_list_field'; - } - } - - /** - * Corrects the views data for list_string base fields. - * - * Based on options_field_views_data(). - * - * @param string $table - * The table name. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The field definition. - * @param array $views_field - * The views field data. - * @param string $field_column_name - * The field column being processed. - */ - protected function processViewsDataForListString($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) { - if ($field_column_name == 'value') { - $views_field['filter']['id'] = 'list_field'; - $views_field['argument']['id'] = 'string_list_field'; - } - } - - /** - * Adds reverse relationships for the base entity reference fields. - * - * @param array $data - * The views data. - * @param \Drupal\Core\Field\BaseFieldDefinition[] $fields - * The entity reference fields. - */ - protected function addReverseRelationships(array &$data, array $fields) { - $entity_type_id = $this->entityType->id(); - $base_table = $this->getViewsTableForEntityType($this->entityType); - assert($this->entityType instanceof ContentEntityType); - $revision_metadata_field_names = array_flip($this->entityType->getRevisionMetadataKeys()); - - foreach ($fields as $field) { - $target_entity_type_id = $field->getSettings()['target_type']; - $target_entity_type = $this->getEntityTypeManager()->getDefinition($target_entity_type_id); - if (!($target_entity_type instanceof ContentEntityType)) { - continue; - } - $target_table = $this->getViewsTableForEntityType($target_entity_type); - $field_name = $field->getName(); - $field_storage = $field->getFieldStorageDefinition(); - - $args = [ - '@label' => $target_entity_type->getSingularLabel(), - '@entity' => $this->entityType->getLabel(), - '@field_name' => $field_name, - ]; - $pseudo_field_name = 'reverse__' . $entity_type_id . '__' . $field_name; - $relationship_data = [ - 'label' => $this->entityType->getLabel(), - 'group' => $target_entity_type->getLabel(), - 'entity_type' => $entity_type_id, - ]; - if ($this->tableMapping->requiresDedicatedTableStorage($field_storage)) { - $data[$target_table][$pseudo_field_name]['relationship'] = [ - 'id' => 'entity_reverse', - 'title' => $this->t('@entity using @field_name', $args), - 'help' => $this->t('Relate each @entity with a @field_name field set to the @label.', $args), - 'base' => $base_table, - 'base field' => $this->entityType->getKey('id'), - 'field_name' => $field_name, - 'field table' => $this->tableMapping->getFieldTableName($field_name), - 'field field' => $this->tableMapping->getFieldColumnName($field_storage, 'target_id'), - ] + $relationship_data; - } - elseif (isset($revision_metadata_field_names[$field_name])) { - // Revision metadata fields exist only on the revision table, so the - // relationship has to be to that rather than to the base table. - $revision_table = $this->tableMapping->getRevisionTable(); - - $data[$target_table][$pseudo_field_name]['relationship'] = [ - 'id' => 'standard', - 'title' => $this->t('@entity revision using @field_name', $args), - 'help' => $this->t('Relate each @entity revision with a @field_name field set to the @label.', $args), - 'base' => $revision_table, - 'base field' => $this->tableMapping->getFieldColumnName($field_storage, 'target_id'), - 'relationship field' => $target_entity_type->getKey('id'), - ] + $relationship_data; - } - else { - // The data is on the base table. - $data[$target_table][$pseudo_field_name]['relationship'] = [ - 'id' => 'standard', - 'title' => $this->t('@entity using @field_name', $args), - 'help' => $this->t('Relate each @entity with a @field_name field set to the @label.', $args), - 'base' => $base_table, - 'base field' => $this->tableMapping->getFieldColumnName($field_storage, 'target_id'), - 'relationship field' => $target_entity_type->getKey('id'), - ] + $relationship_data; - } - } - } - - /** - * Gets the entity field manager. - * - * @todo Remove when support for Drupal 8.7 is dropped. - * - * @return \Drupal\Core\Entity\EntityFieldManagerInterface - * The entity field manager. - */ - protected function getEntityFieldManager() { - if (!isset($this->entityFieldManager)) { - return \Drupal::service('entity_field.manager'); - } - return $this->entityFieldManager; - } - - /** - * Gets the entity type bundle info. - * - * @todo Remove when support for Drupal 8.7 is dropped. - * - * @return \Drupal\Core\Entity\EntityTypeBundleInfoInterface - * The entity type bundle info. - */ - protected function getEntityTypeBundleInfo() { - if (!isset($this->entityTypeBundleInfo)) { - return \Drupal::service('entity_type.bundle.info'); - } - return $this->entityTypeBundleInfo; - } - - /** - * Gets the entity type manager. - * - * @todo Remove when support for Drupal 8.7 is dropped. - * - * @return \Drupal\Core\Entity\EntityTypeManagerInterface - * The entity type manager. - */ - protected function getEntityTypeManager() { - if (!isset($this->entityTypeManager)) { - return \Drupal::entityTypeManager(); - } - return $this->entityTypeManager; - } - -} diff --git a/web/modules/entity/src/Event/EntityDuplicateEvent.php b/web/modules/entity/src/Event/EntityDuplicateEvent.php deleted file mode 100644 index 5c78b831c2037ae7fecab0102376ad48c39fd3cc..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Event/EntityDuplicateEvent.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -namespace Drupal\entity\Event; - -use Drupal\Core\Entity\EntityInterface; -use Symfony\Component\EventDispatcher\Event; - -/** - * Defines the entity duplicate event. - * - * @see \Drupal\entity\Event\EntityEvents - */ -class EntityDuplicateEvent extends Event { - - /** - * The entity. - * - * @var \Drupal\Core\Entity\EntityInterface - */ - protected $entity; - - /** - * The source entity. - * - * @var \Drupal\Core\Entity\EntityInterface - */ - protected $sourceEntity; - - /** - * Constructs a new EntityDuplicateEvent object. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity. - * @param \Drupal\Core\Entity\EntityInterface $source_entity - * The source entity. - */ - public function __construct(EntityInterface $entity, EntityInterface $source_entity) { - $this->entity = $entity; - $this->sourceEntity = $source_entity; - } - - /** - * Gets the entity. - * - * @return \Drupal\Core\Entity\EntityInterface - * The entity. - */ - public function getEntity() { - return $this->entity; - } - - /** - * Gets the source entity. - * - * @return \Drupal\Core\Entity\EntityInterface - * The source entity. - */ - public function getSourceEntity() { - return $this->sourceEntity; - } - -} diff --git a/web/modules/entity/src/Event/EntityEvents.php b/web/modules/entity/src/Event/EntityEvents.php deleted file mode 100644 index f8332918a179b81577f5d1e9ae514e40463780e6..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Event/EntityEvents.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace Drupal\entity\Event; - -/** - * Defines events for the Entity module. - */ -final class EntityEvents { - - /** - * Name of the event fired after saving a duplicated entity. - * - * @Event - * - * @see \Drupal\entity\Event\EntityDuplicateEvent - */ - const ENTITY_DUPLICATE = 'entity.duplicate'; - -} diff --git a/web/modules/entity/src/EventSubscriber/EntityDuplicateSubscriber.php b/web/modules/entity/src/EventSubscriber/EntityDuplicateSubscriber.php deleted file mode 100644 index 65fb67f636d522f02fa67323c777953c2be3e484..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/EventSubscriber/EntityDuplicateSubscriber.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -namespace Drupal\entity\EventSubscriber; - -use Drupal\entity\BundleEntityDuplicatorInterface; -use Drupal\entity\Event\EntityDuplicateEvent; -use Drupal\entity\Event\EntityEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -class EntityDuplicateSubscriber implements EventSubscriberInterface { - - /** - * The bundle entity duplicator. - * - * @var \Drupal\entity\BundleEntityDuplicatorInterface - */ - protected $bundleEntityDuplicator; - - /** - * Constructs a new EntityDuplicateSubscriber object. - * - * @param \Drupal\entity\BundleEntityDuplicatorInterface $bundle_entity_duplicator - * The bundle entity duplicator. - */ - public function __construct(BundleEntityDuplicatorInterface $bundle_entity_duplicator) { - $this->bundleEntityDuplicator = $bundle_entity_duplicator; - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events = [ - EntityEvents::ENTITY_DUPLICATE => ['onEntityDuplicate'], - ]; - return $events; - } - - /** - * Duplicates bundle fields and displays. - * - * @param \Drupal\entity\Event\EntityDuplicateEvent $event - * The entity duplicate event. - */ - public function onEntityDuplicate(EntityDuplicateEvent $event) { - $entity = $event->getEntity(); - if ($entity->getEntityType()->getBundleOf()) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $source_entity */ - $source_entity = $event->getSourceEntity(); - $this->bundleEntityDuplicator->duplicateFields($source_entity, $entity->id()); - $this->bundleEntityDuplicator->duplicateDisplays($source_entity, $entity->id()); - } - } - -} diff --git a/web/modules/entity/src/Form/DeleteMultipleForm.php b/web/modules/entity/src/Form/DeleteMultipleForm.php deleted file mode 100644 index 2a7dbc2dff88b91c8aee7177316faa8e971f8c76..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Form/DeleteMultipleForm.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace Drupal\entity\Form; - -use Drupal\Core\Entity\Form\DeleteMultipleForm as CoreDeleteMultipleForm; - -@trigger_error('\Drupal\entity\Form\DeleteMultipleForm has been deprecated in favor of \Drupal\Core\Entity\Form\DeleteMultipleForm. Use that instead.'); - -/** - * Provides an entities deletion confirmation form. - * - * @deprecated Use \Drupal\Core\Entity\Form\DeleteMultipleForm instead. - */ -class DeleteMultipleForm extends CoreDeleteMultipleForm {} diff --git a/web/modules/entity/src/Form/EntityDuplicateFormInterface.php b/web/modules/entity/src/Form/EntityDuplicateFormInterface.php deleted file mode 100644 index 94a5803f6eade6517a844807e759ae2d42d49750..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Form/EntityDuplicateFormInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -namespace Drupal\entity\Form; - -use Drupal\Core\Entity\EntityFormInterface; -use Drupal\Core\Entity\EntityInterface; - -/** - * Defines an interface for entity duplicate forms. - */ -interface EntityDuplicateFormInterface extends EntityFormInterface { - - /** - * Gets the source entity. - * - * This is the entity that was duplicated to populate the form entity. - * - * @return \Drupal\Core\Entity\EntityInterface - * The source entity. - */ - public function getSourceEntity(); - - /** - * Sets the source entity. - * - * @param \Drupal\Core\Entity\EntityInterface $source_entity - * The source entity. - * - * @return $this - */ - public function setSourceEntity(EntityInterface $source_entity); - -} diff --git a/web/modules/entity/src/Form/EntityDuplicateFormTrait.php b/web/modules/entity/src/Form/EntityDuplicateFormTrait.php deleted file mode 100644 index c459896d889b47a145483b84c4c75c2a8c2c81a2..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Form/EntityDuplicateFormTrait.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Drupal\entity\Form; - -use Drupal\Core\Entity\EntityInterface; -use Drupal\entity\Event\EntityDuplicateEvent; -use Drupal\entity\Event\EntityEvents; - -/** - * Allows forms to implement EntityDuplicateFormInterface. - * - * Forms are expected to call $this->postSave() after the entity is saved. - * This works around core issue #3040556. - */ -trait EntityDuplicateFormTrait { - - /** - * The source entity. - * - * @var \Drupal\Core\Entity\EntityInterface - */ - protected $sourceEntity; - - /** - * {@inheritdoc} - */ - public function getSourceEntity() { - return $this->sourceEntity; - } - - /** - * {@inheritdoc} - */ - public function setSourceEntity(EntityInterface $source_entity) { - $this->sourceEntity = $source_entity; - return $this; - } - - /** - * Invokes entity duplicate hooks after the entity has been duplicated. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The saved entity. - * @param string $operation - * The form operation. - */ - protected function postSave(EntityInterface $entity, $operation) { - if ($operation == 'duplicate') { - // An event is used instead of a hook to prevent a conflict with core - // once hook_entity_duplicate() is introduced there. - $event = new EntityDuplicateEvent($entity, $this->sourceEntity); - /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */ - $event_dispatcher = \Drupal::service('event_dispatcher'); - $event_dispatcher->dispatch(EntityEvents::ENTITY_DUPLICATE, $event); - } - } - -} diff --git a/web/modules/entity/src/Form/RevisionRevertForm.php b/web/modules/entity/src/Form/RevisionRevertForm.php deleted file mode 100644 index 43d18a3dcb38181f2ed86fb6669c63fed8b15ee0..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Form/RevisionRevertForm.php +++ /dev/null @@ -1,174 +0,0 @@ -<?php - -namespace Drupal\entity\Form; - -use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Entity\RevisionableInterface; -use Drupal\Core\Form\ConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Entity\RevisionLogInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; - -class RevisionRevertForm extends ConfirmFormBase { - - /** - * The entity revision. - * - * @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\RevisionLogInterface - */ - protected $revision; - - /** - * The date formatter. - * - * @var \Drupal\Core\Datetime\DateFormatterInterface - */ - protected $dateFormatter; - - /** - * The entity bundle information. - * - * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface - */ - protected $bundleInformation; - - /** - * Creates a new RevisionRevertForm instance. - * - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter - * The date formatter. - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_information - * The bundle information. - */ - public function __construct(DateFormatterInterface $date_formatter, EntityTypeBundleInfoInterface $bundle_information) { - $this->dateFormatter = $date_formatter; - $this->bundleInformation = $bundle_information; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('date.formatter'), - $container->get('entity_type.bundle.info') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'entity_revision_revert_confirm'; - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - if ($this->revision instanceof RevisionLogInterface) { - return $this->t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); - } - return $this->t('Are you sure you want to revert the revision?'); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - if ($this->revision->getEntityType()->hasLinkTemplate('version-history')) { - return $this->revision->toUrl('version-history'); - } - return $this->revision->toUrl(); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Revert'); - } - - /** - * {@inheritdoc} - */ - public function getDescription() { - return ''; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $_entity_revision = NULL, Request $request = NULL) { - $this->revision = $_entity_revision; - $form = parent::buildForm($form, $form_state); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - // The revision timestamp will be updated when the revision is saved. Keep - // the original one for the confirmation message. - $this->revision = $this->prepareRevision($this->revision); - if ($this->revision instanceof RevisionLogInterface) { - $original_revision_timestamp = $this->revision->getRevisionCreationTime(); - - $this->revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)])); - $this->messenger()->addStatus(t('@type %title has been reverted to the revision from %revision-date.', [ - '@type' => $this->getBundleLabel($this->revision), - '%title' => $this->revision->label(), - '%revision-date' => $this->dateFormatter->format($original_revision_timestamp), - ])); - } - else { - $this->messenger()->addStatus(t('@type %title has been reverted', [ - '@type' => $this->getBundleLabel($this->revision), - '%title' => $this->revision->label(), - ])); - } - - $this->revision->save(); - - $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); - $form_state->setRedirect( - "entity.{$this->revision->getEntityTypeId()}.version_history", - [$this->revision->getEntityTypeId() => $this->revision->id()] - ); - } - - /** - * Prepares a revision to be reverted. - * - * @param \Drupal\Core\Entity\RevisionableInterface $revision - * The revision to be reverted. - * - * @return \Drupal\Core\Entity\RevisionableInterface - * The prepared revision ready to be stored. - */ - protected function prepareRevision(RevisionableInterface $revision) { - $revision->setNewRevision(); - $revision->isDefaultRevision(TRUE); - - return $revision; - } - - /** - * Returns a bundle label. - * - * @param \Drupal\Core\Entity\RevisionableInterface $revision - * The entity revision. - * - * @return string - */ - protected function getBundleLabel(RevisionableInterface $revision) { - /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface $revision */ - $bundle_info = $this->bundleInformation->getBundleInfo($revision->getEntityTypeId()); - return $bundle_info[$revision->bundle()]['label']; - } - -} diff --git a/web/modules/entity/src/Form/RevisionableContentEntityForm.php b/web/modules/entity/src/Form/RevisionableContentEntityForm.php deleted file mode 100644 index 6e7d8c7f45d40a5351144ee928da2346767adf51..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Form/RevisionableContentEntityForm.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php - -namespace Drupal\entity\Form; - -use Drupal\Core\Entity\ContentEntityForm; -use Drupal\Core\Entity\RevisionableEntityBundleInterface; -use Drupal\Core\Form\FormStateInterface; - -@trigger_error('\Drupal\entity\Form\RevisionableContentEntityForm has been deprecated in favor of \Drupal\Core\Entity\ContentEntityForm. Use that instead.'); - -/** - * Extends the base entity form with revision support in the UI. - * - * @deprecated Use \Drupal\Core\Entity\ContentEntityForm instead. - */ -class RevisionableContentEntityForm extends ContentEntityForm { - - /** - * The entity being used by this form. - * - * @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\RevisionLogInterface - */ - protected $entity; - - /** - * {@inheritdoc} - */ - protected function prepareEntity() { - parent::prepareEntity(); - - $bundle_entity = $this->getBundleEntity(); - - // Set up default values, if required. - if (!$this->entity->isNew()) { - $this->entity->setRevisionLogMessage(NULL); - } - - if ($bundle_entity instanceof RevisionableEntityBundleInterface) { - // Always use the default revision setting. - $this->entity->setNewRevision($bundle_entity && $bundle_entity->shouldCreateNewRevision()); - } - } - - /** - * Gets the bundle entity of the current entity. - * - * @return \Drupal\Core\Entity\EntityInterface|null - * The bundle entity, or NULL if there is none. - */ - protected function getBundleEntity() { - if ($this->entity->getEntityType()->getBundleEntityType()) { - $bundle_key = $this->entity->getEntityType()->getKey('bundle'); - return $this->entity->{$bundle_key}->referencedEntities()[0]; - } - return NULL; - } - - /** - * {@inheritdoc} - */ - public function form(array $form, FormStateInterface $form_state) { - $entity_type = $this->entity->getEntityType(); - $bundle_entity = $this->getBundleEntity(); - $account = $this->currentUser(); - - if ($this->operation == 'edit') { - $form['#title'] = $this->t('Edit %bundle_label @label', [ - '%bundle_label' => $bundle_entity ? $bundle_entity->label() : '', - '@label' => $this->entity->label(), - ]); - } - - $form['advanced'] = [ - '#type' => 'vertical_tabs', - '#weight' => 99, - ]; - - // Add a log field if the "Create new revision" option is checked, or if the - // current user has the ability to check that option. - // @todo Could we autogenerate this form by using some widget on the - // revision info field. - $form['revision_information'] = [ - '#type' => 'details', - '#title' => $this->t('Revision information'), - // Open by default when "Create new revision" is checked. - '#open' => $this->entity->isNewRevision(), - '#group' => 'advanced', - '#weight' => 20, - '#access' => $this->entity->isNewRevision() || $account->hasPermission($entity_type->get('admin_permission')), - ]; - - $form['revision_information']['revision'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Create new revision'), - '#default_value' => $this->entity->isNewRevision(), - '#access' => $account->hasPermission($entity_type->get('admin_permission')), - ]; - - // Check the revision log checkbox when the log textarea is filled in. - // This must not happen if "Create new revision" is enabled by default, - // since the state would auto-disable the checkbox otherwise. - if (!$this->entity->isNewRevision()) { - $form['revision_information']['revision']['#states'] = [ - 'checked' => [ - 'textarea[name="revision_log"]' => ['empty' => FALSE], - ], - ]; - } - - $form['revision_information']['revision_log'] = [ - '#type' => 'textarea', - '#title' => $this->t('Revision log message'), - '#rows' => 4, - '#default_value' => $this->entity->getRevisionLogMessage(), - '#description' => $this->t('Briefly describe the changes you have made.'), - ]; - - return parent::form($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - // Save as a new revision if requested to do so. - if (!$form_state->isValueEmpty('revision')) { - $this->entity->setNewRevision(); - } - - $insert = $this->entity->isNew(); - $this->entity->save(); - $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()]; - $logger = $this->logger('content'); - $bundle_entity = $this->getBundleEntity(); - $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()]; - - if ($insert) { - $logger->notice('@type: added %info.', $context); - drupal_set_message($this->t('@type %info has been created.', $t_args)); - } - else { - $logger->notice('@type: updated %info.', $context); - drupal_set_message($this->t('@type %info has been updated.', $t_args)); - } - - if ($this->entity->id()) { - $form_state->setValue('id', $this->entity->id()); - $form_state->set('id', $this->entity->id()); - - if ($this->entity->getEntityType()->hasLinkTemplate('collection')) { - $form_state->setRedirectUrl($this->entity->toUrl('collection')); - } - else { - $form_state->setRedirectUrl($this->entity->toUrl('canonical')); - } - } - else { - // In the unlikely case something went wrong on save, the entity will be - // rebuilt and entity form redisplayed. - drupal_set_message($this->t('The entity could not be saved.'), 'error'); - $form_state->setRebuild(); - } - } - -} diff --git a/web/modules/entity/src/Menu/DefaultEntityLocalTaskProvider.php b/web/modules/entity/src/Menu/DefaultEntityLocalTaskProvider.php deleted file mode 100644 index e0dc0ae7be8c38f7cd141cbf890f5dd47adb48ff..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Menu/DefaultEntityLocalTaskProvider.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php - -namespace Drupal\entity\Menu; - -use Drupal\Core\Entity\EntityHandlerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a set of tasks to view, edit and duplicate an entity. - */ -class DefaultEntityLocalTaskProvider implements EntityLocalTaskProviderInterface, EntityHandlerInterface { - - use StringTranslationTrait; - - /** - * Constructs a DefaultEntityLocalTaskProvider object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation. - */ - public function __construct(EntityTypeInterface $entity_type, TranslationInterface $string_translation) { - $this->setStringTranslation($string_translation); - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static($entity_type, $container->get('string_translation')); - } - - /** - * {@inheritdoc} - */ - public function buildLocalTasks(EntityTypeInterface $entity_type) { - // Note: delete-form was intentionally omitted, to match core. See #1834002. - $link_templates = []; - foreach (['canonical', 'edit-form', 'duplicate-form', 'version-history'] as $rel) { - if ($entity_type->hasLinkTemplate($rel)) { - $link_templates[] = str_replace('-', '_', $rel); - } - } - - $tasks = []; - if (count($link_templates) > 1) { - $entity_type_id = $entity_type->id(); - $base = reset($link_templates); - - $titles = [ - 'canonical' => $this->t('View'), - 'edit_form' => $this->t('Edit'), - 'duplicate_form' => $this->t('Duplicate'), - 'version_history' => $this->t('Revisions'), - ]; - - $weight = 0; - foreach ($link_templates as $rel) { - $route_name = "entity.$entity_type_id.$rel"; - $tasks[$route_name] = [ - 'title' => $titles[$rel], - 'route_name' => $route_name, - 'base_route' => "entity.$entity_type_id.$base", - 'weight' => $weight, - ]; - - $weight += 10; - } - } - return $tasks; - } - -} diff --git a/web/modules/entity/src/Menu/EntityCollectionLocalActionProvider.php b/web/modules/entity/src/Menu/EntityCollectionLocalActionProvider.php deleted file mode 100644 index 4acad31dc4e7319a16e910e2f929807d5c9804b1..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Menu/EntityCollectionLocalActionProvider.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php - -namespace Drupal\entity\Menu; - -use Drupal\Core\Entity\EntityHandlerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a action link to the add page or add form on the collection. - */ -class EntityCollectionLocalActionProvider implements EntityLocalActionProviderInterface, EntityHandlerInterface { - - use StringTranslationTrait; - - /** - * Constructs a new EntityCollectionLocalActionProvider object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation. - */ - public function __construct(EntityTypeInterface $entity_type, TranslationInterface $string_translation) { - $this->setStringTranslation($string_translation); - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static($entity_type, $container->get('string_translation')); - } - - /** - * {@inheritdoc} - */ - public function buildLocalActions(EntityTypeInterface $entity_type) { - $actions = []; - if ($entity_type->hasLinkTemplate('collection')) { - $entity_type_id = $entity_type->id(); - - if ($entity_type->hasLinkTemplate('add-page')) { - $route_name = "entity.$entity_type_id.add_page"; - } - elseif ($entity_type->hasLinkTemplate('add-form')) { - $route_name = "entity.$entity_type_id.add_form"; - } - - if (isset($route_name)) { - $actions[$route_name] = [ - 'title' => $this->t('Add @entity', [ - '@entity' => $entity_type->getSingularLabel(), - ]), - 'route_name' => $route_name, - 'options' => [ - // Redirect back to the collection after form submission. - 'query' => [ - 'destination' => $entity_type->getLinkTemplate('collection'), - ], - ], - 'appears_on' => ["entity.$entity_type_id.collection"], - ]; - } - } - return $actions; - } - -} diff --git a/web/modules/entity/src/Menu/EntityLocalActionProviderInterface.php b/web/modules/entity/src/Menu/EntityLocalActionProviderInterface.php deleted file mode 100644 index bba16c3282e820a087ce912fa82f30a7ef07a071..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Menu/EntityLocalActionProviderInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\entity\Menu; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Provides an interface for entity local action providers. - */ -interface EntityLocalActionProviderInterface { - - /** - * Builds local actions for the given entity type. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array[] - * An array of local action definitions. - */ - public function buildLocalActions(EntityTypeInterface $entity_type); - -} diff --git a/web/modules/entity/src/Menu/EntityLocalTaskProviderInterface.php b/web/modules/entity/src/Menu/EntityLocalTaskProviderInterface.php deleted file mode 100644 index 6d6c1b27d2e028613f529367aa4098dfd769a9e6..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Menu/EntityLocalTaskProviderInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\entity\Menu; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Provides an interface for entity local task providers. - */ -interface EntityLocalTaskProviderInterface { - - /** - * Builds local tasks for the given entity type. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array[] - * An array of local task definitions. - */ - public function buildLocalTasks(EntityTypeInterface $entity_type); - -} diff --git a/web/modules/entity/src/Plugin/Action/DeleteAction.php b/web/modules/entity/src/Plugin/Action/DeleteAction.php deleted file mode 100644 index 68a8bc5246fedeb016802abf054d98b910614829..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/Action/DeleteAction.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\Action; - -use Drupal\Core\Action\Plugin\Action\DeleteAction as CoreDeleteAction; - -@trigger_error('\Drupal\entity\Plugin\Action\DeleteAction has been deprecated in favor of \Drupal\Core\Action\Plugin\Action\DeleteAction. Use that instead.'); - -/** - * Redirects to an entity deletion form. - * - * @deprecated Use "entity:delete_action" instead. - * - * @Action( - * id = "entity_delete_action", - * label = @Translation("Delete entity"), - * deriver = "Drupal\entity\Plugin\Action\Derivative\DeleteActionDeriver", - * ) - */ -class DeleteAction extends CoreDeleteAction {} diff --git a/web/modules/entity/src/Plugin/Action/Derivative/DeleteActionDeriver.php b/web/modules/entity/src/Plugin/Action/Derivative/DeleteActionDeriver.php deleted file mode 100644 index 05bd282049c8bb243e5dbe028f17715ac544322a..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/Action/Derivative/DeleteActionDeriver.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\Action\Derivative; - -use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a delete action for each content entity type. - * - * @deprecated - */ -class DeleteActionDeriver extends DeriverBase implements ContainerDeriverInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs a new DeleteActionDeriver object. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static($container->get('entity_type.manager')); - } - - /** - * {@inheritdoc} - */ - public function getDerivativeDefinitions($base_plugin_definition) { - if (empty($this->derivatives)) { - $definitions = []; - foreach ($this->getParticipatingEntityTypes() as $entity_type_id => $entity_type) { - $definition = $base_plugin_definition; - $definition['label'] = t('Delete @entity_type (Deprecated)', ['@entity_type' => $entity_type->getSingularLabel()]); - $definition['type'] = $entity_type_id; - $definition['confirm_form_route_name'] = 'entity.' . $entity_type_id . '.delete_multiple_form'; - $definitions[$entity_type_id] = $definition; - } - $this->derivatives = $definitions; - } - - return parent::getDerivativeDefinitions($base_plugin_definition); - } - - /** - * Gets a list of participating entity types. - * - * The list consists of all content entity types with a delete-multiple-form - * link template. - * - * @return \Drupal\Core\Entity\EntityTypeInterface[] - * The participating entity types, keyed by entity type id. - */ - protected function getParticipatingEntityTypes() { - $entity_types = $this->entityTypeManager->getDefinitions(); - $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) { - // Core requires a "delete-multiple-confirm" form to be declared as well, - // if it's missing, it's safe to assume that the entity type is still - // relying on previous Entity API contrib behavior. - return $entity_type->hasLinkTemplate('delete-multiple-form') && !$entity_type->hasHandlerClass('form', 'delete-multiple-confirm'); - }); - - return $entity_types; - } - -} diff --git a/web/modules/entity/src/Plugin/Derivative/EntityActionsDeriver.php b/web/modules/entity/src/Plugin/Derivative/EntityActionsDeriver.php deleted file mode 100644 index 568ad7e872be801b1f16067ab5bacef5535b45b4..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/Derivative/EntityActionsDeriver.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\Derivative; - -use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Derives local actions for entity types. - */ -class EntityActionsDeriver extends DeriverBase implements ContainerDeriverInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs an entity local actions deriver. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static($container->get('entity_type.manager')); - } - - /** - * {@inheritdoc} - */ - public function getDerivativeDefinitions($base_plugin_definition) { - if (!$this->derivatives) { - foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { - $handlers = $entity_type->getHandlerClasses(); - if (isset($handlers['local_action_provider'])) { - foreach ($handlers['local_action_provider'] as $class) { - /** @var \Drupal\entity\Menu\EntityLocalActionProviderInterface $handler */ - $handler = $this->entityTypeManager->createHandlerInstance($class, $entity_type); - $this->derivatives += $handler->buildLocalActions($entity_type); - } - } - } - } - return $this->derivatives; - } - -} diff --git a/web/modules/entity/src/Plugin/Derivative/EntityTasksDeriver.php b/web/modules/entity/src/Plugin/Derivative/EntityTasksDeriver.php deleted file mode 100644 index 5d1123501fb12f5cc14841ade3f68c89a6d7f97e..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/Derivative/EntityTasksDeriver.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\Derivative; - -use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Derives local tasks for entity types. - */ -class EntityTasksDeriver extends DeriverBase implements ContainerDeriverInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs an entity local tasks deriver. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static($container->get('entity_type.manager')); - } - - /** - * {@inheritdoc} - */ - public function getDerivativeDefinitions($base_plugin_definition) { - if (!$this->derivatives) { - foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { - $handlers = $entity_type->getHandlerClasses(); - if (isset($handlers['local_task_provider'])) { - foreach ($handlers['local_task_provider'] as $class) { - /** @var \Drupal\entity\Menu\EntityLocalTaskProviderInterface $handler */ - $handler = $this->entityTypeManager->createHandlerInstance($class, $entity_type); - $this->derivatives += $handler->buildLocalTasks($entity_type); - } - } - } - } - return $this->derivatives; - } - -} diff --git a/web/modules/entity/src/Plugin/views/field/EntityLinkRevision.php b/web/modules/entity/src/Plugin/views/field/EntityLinkRevision.php deleted file mode 100644 index c3819d34297973b900281c86aea0319a1f83de7c..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/views/field/EntityLinkRevision.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\views\field; - -use Drupal\views\Plugin\views\field\EntityLink; - -/** - * Field handler to present a link to an entity revision. - * - * @ingroup views_field_handlers - * - * @ViewsField("entity_link_revision") - */ -class EntityLinkRevision extends EntityLink { - - /** - * {@inheritdoc} - */ - protected function getEntityLinkTemplate() { - return 'revision'; - } - -} diff --git a/web/modules/entity/src/Plugin/views/field/EntityLinkRevisionRevert.php b/web/modules/entity/src/Plugin/views/field/EntityLinkRevisionRevert.php deleted file mode 100644 index 1d0c7958d18126b32f2d0c51db405c04c753276e..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Plugin/views/field/EntityLinkRevisionRevert.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace Drupal\entity\Plugin\views\field; - -use Drupal\views\Plugin\views\field\EntityLink; -use Drupal\views\ResultRow; - -/** - * Field handler to present a link to revert an entity to a revision. - * - * @ingroup views_field_handlers - * - * @ViewsField("entity_link_revision_revert") - */ -class EntityLinkRevisionRevert extends EntityLink { - - /** - * {@inheritdoc} - */ - protected function getEntityLinkTemplate() { - return 'revision-revert-form'; - } - - /** - * {@inheritdoc} - */ - protected function renderLink(ResultRow $row) { - $this->options['alter']['query'] = $this->getDestinationArray(); - return parent::renderLink($row); - } - - /** - * {@inheritdoc} - */ - protected function getDefaultLabel() { - return $this->t('revert'); - } - -} diff --git a/web/modules/entity/src/QueryAccess/Condition.php b/web/modules/entity/src/QueryAccess/Condition.php deleted file mode 100644 index ef1f630c3e28ebf3fb1124d864e994867ec0cb38..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/Condition.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -/** - * Represents a single query access condition. - */ -final class Condition { - - /** - * The supported operators. - * - * @var string[] - */ - protected static $supportedOperators = [ - '=', '<>', '<', '<=', '>', '>=', 'BETWEEN', 'NOT BETWEEN', - 'IN', 'NOT IN', 'IS NULL', 'IS NOT NULL', - ]; - - /** - * The field. - * - * @var string - */ - protected $field; - - /** - * The value. - * - * @var mixed - */ - protected $value; - - /** - * The operator. - * - * @var string - */ - protected $operator; - - /** - * Constructs a new Condition object. - * - * @param string $field - * The field, with an optional column name. E.g: 'uid', 'address.locality'. - * @param mixed $value - * The value. - * @param string $operator - * The operator. - * Possible values: =, <>, <, <=, >, >=, BETWEEN, NOT BETWEEN, - * IN, NOT IN, IS NULL, IS NOT NULL. - */ - public function __construct($field, $value, $operator = NULL) { - // Provide a default based on the data type of the value. - if (!isset($operator)) { - $operator = is_array($value) ? 'IN' : '='; - } - // Validate the selected operator. - if (!in_array($operator, self::$supportedOperators)) { - throw new \InvalidArgumentException(sprintf('Unrecognized operator "%s".', $operator)); - } - - $this->field = $field; - $this->value = $value; - $this->operator = $operator; - } - - /** - * {@inheritdoc} - */ - public function getField() { - return $this->field; - } - - /** - * {@inheritdoc} - */ - public function getValue() { - return $this->value; - } - - /** - * {@inheritdoc} - */ - public function getOperator() { - return $this->operator; - } - - /** - * Gets the string representation of the condition. - * - * Used for debugging purposes. - * - * @return string - * The string representation of the condition. - */ - public function __toString() { - if (in_array($this->operator, ['IS NULL', 'IS NOT NULL'])) { - return "{$this->field} {$this->operator}"; - } - else { - if (is_array($this->value)) { - $value = "['" . implode("', '", $this->value) . "']"; - } - else { - $value = "'" . $this->value . "'"; - } - - return "{$this->field} {$this->operator} $value"; - } - } - -} diff --git a/web/modules/entity/src/QueryAccess/ConditionGroup.php b/web/modules/entity/src/QueryAccess/ConditionGroup.php deleted file mode 100644 index 094feb109b49d8a30e5fe50a5f968542c5def5bd..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/ConditionGroup.php +++ /dev/null @@ -1,227 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; - -/** - * Represents a group of query access conditions. - * - * Used by query access handlers for filtering lists of entities based on - * granted permissions. - * - * Examples: - * @code - * // Filter by node type and uid. - * $condition_group = new ConditionGroup(); - * $condition_group->addCondition('type', ['article', 'page']); - * $condition_group->addCondition('uid', '1'); - * - * // Filter by node type or status. - * $condition_group = new ConditionGroup('OR'); - * $condition_group->addCondition('type', ['article', 'page']); - * $condition_group->addCondition('status', '1', '<>'); - * - * // Nested condition groups: node type AND (uid OR status). - * $condition_group = new ConditionGroup(); - * $condition_group->addCondition('type', ['article', 'page']); - * $condition_group->addCondition((new ConditionGroup('OR')) - * ->addCondition('uid', 1) - * ->addCondition('status', '1') - * ); - * @endcode - */ -final class ConditionGroup implements \Countable, RefinableCacheableDependencyInterface { - - use RefinableCacheableDependencyTrait; - - /** - * The conjunction. - * - * @var string - */ - protected $conjunction; - - /** - * The conditions. - * - * @var \Drupal\entity\QueryAccess\Condition[]|\Drupal\entity\QueryAccess\ConditionGroup[] - */ - protected $conditions = []; - - /** - * Whether the condition group is always FALSE. - * - * @var bool - */ - protected $alwaysFalse = FALSE; - - /** - * Constructs a new ConditionGroup object. - * - * @param string $conjunction - * The conjunction. - */ - public function __construct($conjunction = 'AND') { - $this->conjunction = $conjunction; - } - - /** - * Gets the conjunction. - * - * @return string - * The conjunction. Possible values: AND, OR. - */ - public function getConjunction() { - return $this->conjunction; - } - - /** - * Gets all conditions and nested condition groups. - * - * @return \Drupal\entity\QueryAccess\Condition[]|\Drupal\entity\QueryAccess\ConditionGroup[] - * The conditions, where each one is either a Condition or a nested - * ConditionGroup. Returned by reference, to allow callers to replace - * or remove conditions. - */ - public function &getConditions() { - return $this->conditions; - } - - /** - * Adds a condition. - * - * @param string|\Drupal\entity\QueryAccess\ConditionGroup $field - * Either a condition group (for nested AND/OR conditions), or a - * field name with an optional column name. E.g: 'uid', 'address.locality'. - * @param mixed $value - * The value. - * @param string $operator - * The operator. - * Possible values: =, <>, <, <=, >, >=, BETWEEN, NOT BETWEEN, - * IN, NOT IN, IS NULL, IS NOT NULL. - * - * @return $this - */ - public function addCondition($field, $value = NULL, $operator = NULL) { - if ($field instanceof ConditionGroup) { - if ($field->count() === 1) { - // The condition group only has a single condition, merge it. - $this->conditions[] = reset($field->getConditions()); - $this->addCacheTags($field->getCacheTags()); - $this->addCacheContexts($field->getCacheContexts()); - $this->mergeCacheMaxAge($field->getCacheMaxAge()); - } - elseif ($field->count() > 1) { - $this->conditions[] = $field; - } - } - else { - $this->conditions[] = new Condition($field, $value, $operator); - } - - return $this; - } - - /** - * Gets whether the condition group is always FALSE. - * - * Used when the user doesn't have access to any entities, to ensure that a - * query returns no results. - * - * @return bool - * Whether the condition group is always FALSE. - */ - public function isAlwaysFalse() { - return $this->alwaysFalse; - } - - /** - * Sets whether the condition group should always be FALSE. - * - * @param bool $always_false - * Whether the condition group should always be FALSE. - * - * @return $this - */ - public function alwaysFalse($always_false = TRUE) { - $this->alwaysFalse = $always_false; - return $this; - } - - /** - * Clones the contained conditions when the condition group is cloned. - */ - public function __clone() { - foreach ($this->conditions as $i => $condition) { - $this->conditions[$i] = clone $condition; - } - } - - /** - * Gets the string representation of the condition group. - * - * @return string - * The string representation of the condition group. - */ - public function __toString() { - // Special case for a single, nested condition group: - if (count($this->conditions) == 1) { - return (string) reset($this->conditions); - } - $lines = []; - foreach ($this->conditions as $condition) { - $lines[] = str_replace("\n", "\n ", (string) $condition); - } - return $lines ? "(\n " . implode("\n {$this->conjunction}\n ", $lines) . "\n)" : ''; - } - - /** - * {@inheritdoc} - */ - public function count() { - return count($this->conditions); - } - - /** - * {@inheritdoc} - */ - public function getCacheTags() { - $tags = $this->cacheTags; - foreach ($this->conditions as $condition) { - if ($condition instanceof ConditionGroup) { - $tags = array_merge($tags, $condition->getCacheTags()); - } - } - return Cache::mergeTags($tags, []); - } - - /** - * {@inheritdoc} - */ - public function getCacheContexts() { - $cache_contexts = $this->cacheContexts; - foreach ($this->conditions as $condition) { - if ($condition instanceof ConditionGroup) { - $cache_contexts = array_merge($cache_contexts, $condition->getCacheContexts()); - } - } - return Cache::mergeContexts($cache_contexts); - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - $max_age = $this->cacheMaxAge; - foreach ($this->conditions as $condition) { - if ($condition instanceof ConditionGroup) { - $max_age = Cache::mergeMaxAges($max_age, $condition->getCacheMaxAge()); - } - } - return $max_age; - } - -} diff --git a/web/modules/entity/src/QueryAccess/EntityQueryAlter.php b/web/modules/entity/src/QueryAccess/EntityQueryAlter.php deleted file mode 100644 index 8d5f4c83154b0b86554b420f740de75ecf3e4ea8..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/EntityQueryAlter.php +++ /dev/null @@ -1,199 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; -use Drupal\Core\Database\Query\SelectInterface; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityFieldManagerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\Query\Sql\Tables; -use Drupal\Core\Entity\Sql\SqlContentEntityStorage; -use Drupal\Core\Render\RendererInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; - -/** - * Defines a class for altering entity queries. - * - * EntityQuery doesn't have an alter hook, forcing this class to operate - * on the underlying SQL query, duplicating the EntityQuery condition logic. - * - * @internal - */ -class EntityQueryAlter implements ContainerInjectionInterface { - - /** - * The entity field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManagerInterface - */ - protected $entityFieldManager; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The renderer. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack - */ - protected $requestStack; - - /** - * Constructs a new EntityQueryAlter object. - * - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager - * The entity field manager. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - */ - public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, RequestStack $request_stack) { - $this->entityFieldManager = $entity_field_manager; - $this->entityTypeManager = $entity_type_manager; - $this->renderer = $renderer; - $this->requestStack = $request_stack; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_field.manager'), - $container->get('entity_type.manager'), - $container->get('renderer'), - $container->get('request_stack') - ); - } - - /** - * Alters the select query for the given entity type. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * The select query. - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - */ - public function alter(SelectInterface $query, EntityTypeInterface $entity_type) { - if (!$entity_type->hasHandlerClass('query_access')) { - return; - } - $entity_type_id = $entity_type->id(); - $storage = $this->entityTypeManager->getStorage($entity_type_id); - if (!$storage instanceof SqlContentEntityStorage) { - return; - } - - /** @var \Drupal\entity\QueryAccess\QueryAccessHandlerInterface $query_access */ - $query_access = $this->entityTypeManager->getHandler($entity_type_id, 'query_access'); - $conditions = $query_access->getConditions($query->getMetaData('op') ?: 'view'); - if ($conditions->isAlwaysFalse()) { - $query->where('1 = 0'); - } - elseif (count($conditions)) { - $sql_conditions = $this->mapConditions($conditions, $query); - $query->condition($sql_conditions); - } - - $this->applyCacheability(CacheableMetadata::createFromObject($conditions)); - } - - /** - * Maps an entity type's access conditions to SQL conditions. - * - * @param \Drupal\entity\QueryAccess\ConditionGroup $conditions - * The access conditions. - * @param \Drupal\Core\Database\Query\SelectInterface $query - * The SQL query. - * @param bool $nested_inside_or - * Whether the access conditions are nested inside an OR condition. - * - * @return \Drupal\Core\Database\Query\ConditionInterface - * The SQL conditions. - */ - protected function mapConditions(ConditionGroup $conditions, SelectInterface $query, $nested_inside_or = FALSE) { - $sql_condition = $query->conditionGroupFactory($conditions->getConjunction()); - $tables = new Tables($query); - $nested_inside_or = $nested_inside_or || $conditions->getConjunction() == 'OR'; - foreach ($conditions->getConditions() as $condition) { - if ($condition instanceof ConditionGroup) { - $nested_sql_conditions = $this->mapConditions($condition, $query, $nested_inside_or); - $sql_condition->condition($nested_sql_conditions); - } - else { - // Access conditions don't specify a langcode. - $langcode = NULL; - $type = $nested_inside_or || $condition->getOperator() === 'IS NULL' ? 'LEFT' : 'INNER'; - $sql_field = $tables->addField($condition->getField(), $type, $langcode); - $value = $condition->getValue(); - $operator = $condition->getOperator(); - // Using LIKE/NOT LIKE ensures a case insensitive comparison. - // @see \Drupal\Core\Entity\Query\Sql\Condition::translateCondition(). - $case_sensitive = $tables->isFieldCaseSensitive($condition->getField()); - $operator_map = [ - '=' => 'LIKE', - '<>' => 'NOT LIKE', - ]; - if (!$case_sensitive && isset($operator_map[$operator])) { - $operator = $operator_map[$operator]; - $value = $query->escapeLike($value); - } - - $sql_condition->condition($sql_field, $value, $operator); - } - } - - return $sql_condition; - } - - /** - * Applies the cacheablity metadata to the current request. - * - * @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata - * The cacheability metadata. - */ - protected function applyCacheability(CacheableMetadata $cacheable_metadata) { - $request = $this->requestStack->getCurrentRequest(); - if ($request->isMethodCacheable() && $this->renderer->hasRenderContext() && $this->hasCacheableMetadata($cacheable_metadata)) { - $build = []; - $cacheable_metadata->applyTo($build); - $this->renderer->render($build); - } - } - - /** - * Check if the cacheable metadata is not empty. - * - * An empty cacheable metadata object has no context, tags, and is permanent. - * - * @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata - * The cacheable metadata. - * - * @return bool - * TRUE if there is cacheability metadata, otherwise FALSE. - */ - protected function hasCacheableMetadata(CacheableMetadata $cacheable_metadata) { - return $cacheable_metadata->getCacheMaxAge() !== Cache::PERMANENT - || count($cacheable_metadata->getCacheContexts()) > 0 - || count($cacheable_metadata->getCacheTags()) > 0; - } - -} diff --git a/web/modules/entity/src/QueryAccess/EventOnlyQueryAccessHandler.php b/web/modules/entity/src/QueryAccess/EventOnlyQueryAccessHandler.php deleted file mode 100644 index c26b749ac4acef49e16948eca7593899b7d7294a..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/EventOnlyQueryAccessHandler.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Entity\EntityHandlerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Session\AccountInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Generic query access handler for entity types that do not have one. - * - * This query access handler only fires the alter event so that modules can - * subscribe to the query access alter event to alter any entity query or views - * query without having to duplicate the related code from Entity API. - */ -final class EventOnlyQueryAccessHandler implements EntityHandlerInterface, QueryAccessHandlerInterface { - - /** - * The entity type. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - - /** - * The event dispatcher. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $currentUser; - - /** - * Constructs a new EventOnlyQueryAccessHandler object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * The event dispatcher. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - */ - public function __construct(EntityTypeInterface $entity_type, EventDispatcherInterface $event_dispatcher, AccountInterface $current_user) { - $this->entityType = $entity_type; - $this->eventDispatcher = $event_dispatcher; - $this->currentUser = $current_user; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('event_dispatcher'), - $container->get('current_user') - ); - } - - /** - * {@inheritdoc} - */ - public function getConditions($operation, AccountInterface $account = NULL) { - $account = $account ?: $this->currentUser; - $entity_type_id = $this->entityType->id(); - $conditions = new ConditionGroup('OR'); - - // Allow other modules to modify the conditions before they are used. - $event = new QueryAccessEvent($conditions, $operation, $account, $entity_type_id); - $this->eventDispatcher->dispatch("entity.query_access", $event); - $this->eventDispatcher->dispatch("entity.query_access.{$entity_type_id}", $event); - - return $conditions; - } - -} diff --git a/web/modules/entity/src/QueryAccess/QueryAccessEvent.php b/web/modules/entity/src/QueryAccess/QueryAccessEvent.php deleted file mode 100644 index fe8a59c2d236fbc97809c847f6ddd9c9464d0374..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/QueryAccessEvent.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Session\AccountInterface; -use Symfony\Component\EventDispatcher\Event; - -/** - * Defines the query access event. - * - * Allows modules to modify access conditions before they're applied to a query. - * - * The event ID is both generic and dynamic: - * - entity.query_access - * - entity.query_access.$entity_type_id - */ -class QueryAccessEvent extends Event { - - /** - * The conditions. - * - * @var \Drupal\entity\QueryAccess\ConditionGroup - */ - protected $conditions; - - /** - * The operation. - * - * @var string - */ - protected $operation; - - /** - * The user for which to restrict access. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $account; - - /** - * The ID of entity type the query is for. - * - * @var string - */ - protected $entityTypeId; - - /** - * Constructs a new QueryAccessEvent. - * - * @param \Drupal\entity\QueryAccess\ConditionGroup $conditions - * The conditions. - * @param string $operation - * The operation. Usually one of "view", "update", "duplicate", or "delete". - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to restrict access. - * @param string $entity_type_id - * The ID of entity type the query is for. - */ - public function __construct(ConditionGroup $conditions, $operation, AccountInterface $account, $entity_type_id = NULL) { - $this->conditions = $conditions; - $this->operation = $operation; - $this->account = $account; - if (!isset($entity_type_id)) { - @trigger_error('The $entity_type_id argument must be passed to QueryAccessEvent::__construct(), it is required before entity:2.0.0. See https://www.drupal.org/node/3134363.', E_USER_DEPRECATED); - } - else { - $this->entityTypeId = $entity_type_id; - } - } - - /** - * Gets the conditions. - * - * If $conditions->isAlwaysFalse() is TRUE, the user doesn't have access to - * any entities, and the query is expected to return no results. - * This can be reversed by calling $conditions->alwaysFalse(FALSE). - * - * If $conditions->isAlwaysFalse() is FALSE, and the condition group is - * empty (count is 0), the user has full access, and the query doesn't - * need to be restricted. - * - * @return \Drupal\entity\QueryAccess\ConditionGroup - * The conditions. - */ - public function getConditions() { - return $this->conditions; - } - - /** - * Gets the operation. - * - * @return string - * The operation. Usually one of "view", "update" or "delete". - */ - public function getOperation() { - return $this->operation; - } - - /** - * Gets the user for which to restrict access. - * - * @return \Drupal\Core\Session\AccountInterface - * The user. - */ - public function getAccount() { - return $this->account; - } - - /** - * Gets the the entity type ID. - * - * @return string - * The entity type ID. - */ - public function getEntityTypeId() { - return $this->entityTypeId; - } - -} diff --git a/web/modules/entity/src/QueryAccess/QueryAccessHandler.php b/web/modules/entity/src/QueryAccess/QueryAccessHandler.php deleted file mode 100644 index f9ec51c4cd953f7ee7e729e90a0dae124cc2ea65..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/QueryAccessHandler.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Session\AccountInterface; - -/** - * Controls query access based on the generic entity permissions. - * - * @see \Drupal\entity\EntityAccessControlHandler - * @see \Drupal\entity\EntityPermissionProvider - */ -class QueryAccessHandler extends QueryAccessHandlerBase { - - /** - * {@inheritdoc} - */ - protected function buildEntityOwnerConditions($operation, AccountInterface $account) { - if ($operation == 'view') { - // EntityPermissionProvider doesn't provide own/any view permissions. - return $this->buildEntityConditions($operation, $account); - } - - return parent::buildEntityOwnerConditions($operation, $account); - } - -} diff --git a/web/modules/entity/src/QueryAccess/QueryAccessHandlerBase.php b/web/modules/entity/src/QueryAccess/QueryAccessHandlerBase.php deleted file mode 100644 index ec96e9e57e075351dffaddeb8aab39a4a53bc989..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/QueryAccessHandlerBase.php +++ /dev/null @@ -1,281 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Entity\EntityHandlerInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\user\EntityOwnerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Provides common logic for query access handlers. - * - * @see \Drupal\entity\QueryAccess\QueryAccessHandler - * @see \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler - */ -abstract class QueryAccessHandlerBase implements EntityHandlerInterface, QueryAccessHandlerInterface { - - /** - * The entity type. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - - /** - * The entity type bundle info. - * - * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface - */ - protected $bundleInfo; - - /** - * The event dispatcher. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $currentUser; - - /** - * Constructs a new QueryAccessHandlerBase object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info - * The entity type bundle info. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * The event dispatcher. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - */ - public function __construct(EntityTypeInterface $entity_type, EntityTypeBundleInfoInterface $bundle_info, EventDispatcherInterface $event_dispatcher, AccountInterface $current_user) { - $this->entityType = $entity_type; - $this->bundleInfo = $bundle_info; - $this->eventDispatcher = $event_dispatcher; - $this->currentUser = $current_user; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity_type.bundle.info'), - $container->get('event_dispatcher'), - $container->get('current_user') - ); - } - - /** - * {@inheritdoc} - */ - public function getConditions($operation, AccountInterface $account = NULL) { - $account = $account ?: $this->currentUser; - $entity_type_id = $this->entityType->id(); - $conditions = $this->buildConditions($operation, $account); - - // Allow other modules to modify the conditions before they are used. - $event = new QueryAccessEvent($conditions, $operation, $account, $entity_type_id); - $this->eventDispatcher->dispatch("entity.query_access", $event); - $this->eventDispatcher->dispatch("entity.query_access.{$entity_type_id}", $event); - - return $conditions; - } - - /** - * Builds the conditions for the given operation and user. - * - * @param string $operation - * The access operation. Usually one of "view", "update", "duplicate", - * or "delete". - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to restrict access. - * - * @return \Drupal\entity\QueryAccess\ConditionGroup - * The conditions. - */ - public function buildConditions($operation, AccountInterface $account) { - $entity_type_id = $this->entityType->id(); - $has_owner = $this->entityType->entityClassImplements(EntityOwnerInterface::class); - $has_published = $this->entityType->entityClassImplements(EntityPublishedInterface::class); - // Guard against broken/incomplete entity type definitions. - if ($has_owner && !$this->entityType->hasKey('owner') && !$this->entityType->hasKey('uid')) { - throw new \RuntimeException(sprintf('The "%s" entity type did not define an "owner" or "uid" key.', $entity_type_id)); - } - if ($has_published && !$this->entityType->hasKey('published')) { - throw new \RuntimeException(sprintf('The "%s" entity type did not define a "published" key', $entity_type_id)); - } - - $admin_permission = $this->entityType->getAdminPermission() ?: "administer {$entity_type_id}"; - if ($account->hasPermission($admin_permission)) { - // The user has full access to all operations, no conditions needed. - $conditions = new ConditionGroup('OR'); - $conditions->addCacheContexts(['user.permissions']); - return $conditions; - } - - if ($has_owner) { - $entity_conditions = $this->buildEntityOwnerConditions($operation, $account); - } - else { - $entity_conditions = $this->buildEntityConditions($operation, $account); - } - - $conditions = NULL; - if ($operation == 'view' && $has_published) { - $owner_key = $this->entityType->hasKey('owner') ? $this->entityType->getKey('owner') : $this->entityType->getKey('uid'); - $published_key = $this->entityType->getKey('published'); - $published_conditions = NULL; - $unpublished_conditions = NULL; - - if ($entity_conditions) { - // Restrict the existing conditions to published entities only. - $published_conditions = new ConditionGroup('AND'); - $published_conditions->addCacheContexts(['user.permissions']); - $published_conditions->addCondition($entity_conditions); - $published_conditions->addCondition($published_key, '1'); - } - if ($has_owner && $account->hasPermission("view own unpublished $entity_type_id")) { - $unpublished_conditions = new ConditionGroup('AND'); - $unpublished_conditions->addCacheContexts(['user']); - $unpublished_conditions->addCondition($owner_key, $account->id()); - $unpublished_conditions->addCondition($published_key, '0'); - } - - if ($published_conditions && $unpublished_conditions) { - $conditions = new ConditionGroup('OR'); - $conditions->addCondition($published_conditions); - $conditions->addCondition($unpublished_conditions); - } - elseif ($published_conditions) { - $conditions = $published_conditions; - } - elseif ($unpublished_conditions) { - $conditions = $unpublished_conditions; - } - } - else { - $conditions = $entity_conditions; - } - - if (!$conditions) { - // The user doesn't have access to any entities. - // Falsify the query to ensure no results are returned. - $conditions = new ConditionGroup('OR'); - $conditions->addCacheContexts(['user.permissions']); - $conditions->alwaysFalse(); - } - - return $conditions; - } - - /** - * Builds the conditions for entities that have an owner. - * - * @param string $operation - * The access operation. Usually one of "view", "update", "duplicate", - * or "delete". - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to restrict access. - * - * @return \Drupal\entity\QueryAccess\ConditionGroup|null - * The conditions, or NULL if the user doesn't have access to any entity. - */ - protected function buildEntityOwnerConditions($operation, AccountInterface $account) { - $entity_type_id = $this->entityType->id(); - $owner_key = $this->entityType->hasKey('owner') ? $this->entityType->getKey('owner') : $this->entityType->getKey('uid'); - $bundle_key = $this->entityType->getKey('bundle'); - - $conditions = new ConditionGroup('OR'); - $conditions->addCacheContexts(['user.permissions']); - // Any $entity_type permission. - if ($account->hasPermission("$operation any $entity_type_id")) { - // The user has full access, no conditions needed. - return $conditions; - } - - // Own $entity_type permission. - if ($account->hasPermission("$operation own $entity_type_id")) { - $conditions->addCacheContexts(['user']); - $conditions->addCondition($owner_key, $account->id()); - } - - $bundles = array_keys($this->bundleInfo->getBundleInfo($entity_type_id)); - $bundles_with_any_permission = []; - $bundles_with_own_permission = []; - foreach ($bundles as $bundle) { - if ($account->hasPermission("$operation any $bundle $entity_type_id")) { - $bundles_with_any_permission[] = $bundle; - } - if ($account->hasPermission("$operation own $bundle $entity_type_id")) { - $bundles_with_own_permission[] = $bundle; - } - } - // Any $bundle permission. - if ($bundles_with_any_permission) { - $conditions->addCondition($bundle_key, $bundles_with_any_permission); - } - // Own $bundle permission. - if ($bundles_with_own_permission) { - $conditions->addCacheContexts(['user']); - $conditions->addCondition((new ConditionGroup('AND')) - ->addCondition($owner_key, $account->id()) - ->addCondition($bundle_key, $bundles_with_own_permission) - ); - } - - return $conditions->count() ? $conditions : NULL; - } - - /** - * Builds the conditions for entities that do not have an owner. - * - * @param string $operation - * The access operation. Usually one of "view", "update", "duplicate", - * or "delete". - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to restrict access. - * - * @return \Drupal\entity\QueryAccess\ConditionGroup|null - * The conditions, or NULL if the user doesn't have access to any entity. - */ - protected function buildEntityConditions($operation, AccountInterface $account) { - $entity_type_id = $this->entityType->id(); - $bundle_key = $this->entityType->getKey('bundle'); - - $conditions = new ConditionGroup('OR'); - $conditions->addCacheContexts(['user.permissions']); - // The $entity_type permission. - if ($account->hasPermission("$operation $entity_type_id")) { - // The user has full access, no conditions needed. - return $conditions; - } - - $bundles = array_keys($this->bundleInfo->getBundleInfo($entity_type_id)); - $bundles_with_any_permission = []; - foreach ($bundles as $bundle) { - if ($account->hasPermission("$operation $bundle $entity_type_id")) { - $bundles_with_any_permission[] = $bundle; - } - } - // The $bundle permission. - if ($bundles_with_any_permission) { - $conditions->addCondition($bundle_key, $bundles_with_any_permission); - } - - return $conditions->count() ? $conditions : NULL; - } - -} diff --git a/web/modules/entity/src/QueryAccess/QueryAccessHandlerInterface.php b/web/modules/entity/src/QueryAccess/QueryAccessHandlerInterface.php deleted file mode 100644 index 8fcb87a50976f6a46cf40e1c9b27e4e952f345ca..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/QueryAccessHandlerInterface.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Session\AccountInterface; - -/** - * Query access handlers control access to entities in queries. - * - * An entity defines a query access handler in its annotation: - * @code - * query_access = "\Drupal\entity\QueryAccess\QueryAccessHandler" - * @code - * The handler builds a set of conditions which are then applied to a query - * to filter it. For example, if the user #22 only has access to view - * their own entities, a uid = '22' condition will be built and applied. - * - * The following query types are supported: - * - Entity queries with the $entity_type_id . '_access' tag. - * - Views queries. - */ -interface QueryAccessHandlerInterface { - - /** - * Gets the conditions for the given operation and user. - * - * The "entity.query_access.$entity_type_id" event is fired to allow - * modules to alter the conditions. - * - * @param string $operation - * The access operation. Usually one of "view", "update", "duplicate", - * or "delete". - * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to restrict access, or NULL - * to assume the current user. Defaults to NULL. - * - * @return \Drupal\entity\QueryAccess\ConditionGroup - * The conditions. - */ - public function getConditions($operation, AccountInterface $account = NULL); - -} diff --git a/web/modules/entity/src/QueryAccess/UncacheableQueryAccessHandler.php b/web/modules/entity/src/QueryAccess/UncacheableQueryAccessHandler.php deleted file mode 100644 index d849fe1a592c23a442ba65e0a44580396138e3fd..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/UncacheableQueryAccessHandler.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -/** - * Controls query access based on the uncacheable entity permissions. - * - * @see \Drupal\entity\UncacheableEntityAccessControlHandler - * @see \Drupal\entity\UncacheableEntityPermissionProvider - */ -class UncacheableQueryAccessHandler extends QueryAccessHandlerBase {} diff --git a/web/modules/entity/src/QueryAccess/ViewsQueryAlter.php b/web/modules/entity/src/QueryAccess/ViewsQueryAlter.php deleted file mode 100644 index 3d660fdaae85f87940d29a528c9eafebce2d67f8..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/QueryAccess/ViewsQueryAlter.php +++ /dev/null @@ -1,251 +0,0 @@ -<?php - -namespace Drupal\entity\QueryAccess; - -use Drupal\Core\Cache\CacheableMetadata; -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\Condition as SqlCondition; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Entity\EntityFieldManagerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\Sql\DefaultTableMapping; -use Drupal\Core\Entity\Sql\SqlContentEntityStorage; -use Drupal\Core\Render\RendererInterface; -use Drupal\views\Plugin\views\query\Sql; -use Drupal\views\ViewExecutable; -use Drupal\views\Views; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; - -/** - * Defines a class for altering views queries. - * - * @internal - */ -class ViewsQueryAlter implements ContainerInjectionInterface { - - /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $connection; - - /** - * The entity field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManagerInterface - */ - protected $entityFieldManager; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The renderer. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack - */ - protected $requestStack; - - /** - * Constructs a new ViewsQueryAlter object. - * - * @param \Drupal\Core\Database\Connection $connection - * The database connection. - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager - * The entity field manager. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - */ - public function __construct(Connection $connection, EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, RequestStack $request_stack) { - $this->connection = $connection; - $this->entityFieldManager = $entity_field_manager; - $this->entityTypeManager = $entity_type_manager; - $this->renderer = $renderer; - $this->requestStack = $request_stack; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('database'), - $container->get('entity_field.manager'), - $container->get('entity_type.manager'), - $container->get('renderer'), - $container->get('request_stack') - ); - } - - /** - * Alters the given views query. - * - * @param \Drupal\views\Plugin\views\query\Sql $query - * The views query. - * @param \Drupal\views\ViewExecutable $view - * The view. - */ - public function alter(Sql $query, ViewExecutable $view) { - $table_info = $query->getEntityTableInfo(); - $base_table = reset($table_info); - if (empty($base_table['entity_type']) || $base_table['relationship_id'] != 'none') { - return; - } - $entity_type_id = $base_table['entity_type']; - $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); - if (!$entity_type->hasHandlerClass('query_access')) { - return; - } - $storage = $this->entityTypeManager->getStorage($entity_type_id); - if (!$storage instanceof SqlContentEntityStorage) { - return; - } - - /** @var \Drupal\entity\QueryAccess\QueryAccessHandlerInterface $query_access */ - $query_access = $this->entityTypeManager->getHandler($entity_type_id, 'query_access'); - $conditions = $query_access->getConditions('view'); - if ($conditions->isAlwaysFalse()) { - $query->addWhereExpression(0, '1 = 0'); - } - elseif (count($conditions)) { - // Store the data table, in case mapConditions() needs to join it in. - $base_table['data_table'] = $entity_type->getDataTable(); - $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id); - /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */ - $table_mapping = $storage->getTableMapping(); - $sql_conditions = $this->mapConditions($conditions, $query, $base_table, $field_storage_definitions, $table_mapping); - $query->addWhere(0, $sql_conditions); - } - - $this->applyCacheability(CacheableMetadata::createFromObject($conditions)); - } - - /** - * Maps an entity type's access conditions to views SQL conditions. - * - * @param \Drupal\entity\QueryAccess\ConditionGroup $conditions - * The access conditions. - * @param \Drupal\views\Plugin\views\query\Sql $query - * The views query. - * @param array $base_table - * The base table information. - * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions - * The field storage definitions. - * @param \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping - * The table mapping. - * - * @return \Drupal\Core\Database\Query\ConditionInterface - * The SQL conditions. - */ - protected function mapConditions(ConditionGroup $conditions, Sql $query, array $base_table, array $field_storage_definitions, DefaultTableMapping $table_mapping) { - $sql_condition = new SqlCondition($conditions->getConjunction()); - foreach ($conditions->getConditions() as $condition) { - if ($condition instanceof ConditionGroup) { - $nested_sql_conditions = $this->mapConditions($condition, $query, $base_table, $field_storage_definitions, $table_mapping); - $sql_condition->condition($nested_sql_conditions); - } - else { - $field = $condition->getField(); - $property_name = NULL; - if (strpos($field, '.') !== FALSE) { - list($field, $property_name) = explode('.', $field); - } - // Skip unknown fields. - if (!isset($field_storage_definitions[$field])) { - continue; - } - $field_storage_definition = $field_storage_definitions[$field]; - if (!$property_name) { - $property_name = $field_storage_definition->getMainPropertyName(); - } - - $column = $table_mapping->getFieldColumnName($field_storage_definition, $property_name); - if ($table_mapping->requiresDedicatedTableStorage($field_storage_definitions[$field])) { - if ($base_table['revision']) { - $dedicated_table = $table_mapping->getDedicatedRevisionTableName($field_storage_definition); - } - else { - $dedicated_table = $table_mapping->getDedicatedDataTableName($field_storage_definition); - } - // Views defaults to LEFT JOIN. For simplicity, we don't try to - // use an INNER JOIN when it's safe to do so (AND conjunctions). - $alias = $query->ensureTable($dedicated_table); - } - elseif ($base_table['revision'] && !$field_storage_definition->isRevisionable()) { - // Workaround for #2652652, which causes $query->ensureTable() - // to not work in this case, due to a missing relationship. - if ($data_table = $query->getTableInfo($base_table['data_table'])) { - $alias = $data_table['alias']; - } - else { - $configuration = [ - 'type' => 'INNER', - 'table' => $base_table['data_table'], - 'field' => 'id', - 'left_table' => $base_table['alias'], - 'left_field' => 'id', - ]; - /** @var \Drupal\Views\Plugin\views\join\JoinPluginBase $join */ - $join = Views::pluginManager('join')->createInstance('standard', $configuration); - $alias = $query->addRelationship($base_table['data_table'], $join, $data_table); - } - } - else { - $alias = $base_table['alias']; - } - - $value = $condition->getValue(); - $operator = $condition->getOperator(); - // Using LIKE/NOT LIKE ensures a case insensitive comparison. - // @see \Drupal\Core\Entity\Query\Sql\Condition::translateCondition(). - $property_definitions = $field_storage_definition->getPropertyDefinitions(); - $case_sensitive = $property_definitions[$property_name]->getSetting('case_sensitive'); - $operator_map = [ - '=' => 'LIKE', - '<>' => 'NOT LIKE', - ]; - if (!$case_sensitive && isset($operator_map[$operator])) { - $operator = $operator_map[$operator]; - $value = $this->connection->escapeLike($value); - } - - $sql_condition->condition("$alias.$column", $value, $operator); - } - } - - return $sql_condition; - } - - /** - * Applies the cacheablity metadata to the current request. - * - * @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata - * The cacheability metadata. - */ - protected function applyCacheability(CacheableMetadata $cacheable_metadata) { - $request = $this->requestStack->getCurrentRequest(); - if ($request->isMethodCacheable() && $this->renderer->hasRenderContext()) { - $build = []; - $cacheable_metadata->applyTo($build); - $this->renderer->render($build); - } - } - -} diff --git a/web/modules/entity/src/Revision/RevisionableContentEntityBase.php b/web/modules/entity/src/Revision/RevisionableContentEntityBase.php deleted file mode 100644 index f6dc11cb3f9adb64a4d35cb7c8c85708f0a6378f..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Revision/RevisionableContentEntityBase.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\entity\Revision; - -use Drupal\Core\Entity\RevisionableContentEntityBase as BaseRevisionableContentEntityBase; - -/** - * Improves the url route handling of core's revisionable content entity base. - */ -abstract class RevisionableContentEntityBase extends BaseRevisionableContentEntityBase { - - /** - * {@inheritdoc} - */ - protected function urlRouteParameters($rel) { - $uri_route_parameters = parent::urlRouteParameters($rel); - - if (strpos($this->getEntityType()->getLinkTemplate($rel), $this->getEntityTypeId() . '_revision') !== FALSE) { - $uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId(); - } - - return $uri_route_parameters; - } - -} diff --git a/web/modules/entity/src/Routing/AdminHtmlRouteProvider.php b/web/modules/entity/src/Routing/AdminHtmlRouteProvider.php deleted file mode 100644 index 0b6e7e33740e7ecf5f314ab511ad4f46382658a0..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Routing/AdminHtmlRouteProvider.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Provides HTML routes for entities with administrative add/edit/delete pages. - * - * Use this class if the add/edit/delete form routes should use the - * administrative theme. - */ -class AdminHtmlRouteProvider extends DefaultHtmlRouteProvider { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); - - $entity_type_id = $entity_type->id(); - $admin_route_names = [ - "entity.{$entity_type_id}.add_page", - "entity.{$entity_type_id}.add_form", - "entity.{$entity_type_id}.edit_form", - "entity.{$entity_type_id}.delete_form", - "entity.{$entity_type_id}.delete_multiple_form", - "entity.{$entity_type_id}.duplicate_form", - ]; - foreach ($admin_route_names as $admin_route_name) { - if ($route = $collection->get($admin_route_name)) { - $route->setOption('_admin_route', TRUE); - } - } - - return $collection; - } - -} diff --git a/web/modules/entity/src/Routing/DefaultHtmlRouteProvider.php b/web/modules/entity/src/Routing/DefaultHtmlRouteProvider.php deleted file mode 100644 index 29c67d4577ea2ddb746b95f7bbf984698be85ae2..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Routing/DefaultHtmlRouteProvider.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider as CoreDefaultHtmlRouteProvider; -use Drupal\entity\Controller\EntityDuplicateController; -use Symfony\Component\Routing\Route; - -/** - * Provides HTML routes for entities. - */ -class DefaultHtmlRouteProvider extends CoreDefaultHtmlRouteProvider { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); - - $entity_type_id = $entity_type->id(); - if ($duplicate_route = $this->getDuplicateFormRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.duplicate_form", $duplicate_route); - } - - return $collection; - } - - /** - * {@inheritdoc} - */ - protected function getCollectionRoute(EntityTypeInterface $entity_type) { - $route = parent::getCollectionRoute($entity_type); - if ($route && $entity_type->hasHandlerClass('permission_provider')) { - $admin_permission = $entity_type->getAdminPermission(); - $overview_permission = "access {$entity_type->id()} overview"; - $route->setRequirement('_permission', "$admin_permission+$overview_permission"); - } - return $route; - } - - /** - * Gets the duplicate-form route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getDuplicateFormRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('duplicate-form')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('duplicate-form')); - $route - ->setDefaults([ - '_controller' => EntityDuplicateController::class . '::form', - '_title_callback' => EntityDuplicateController::class . '::title', - 'entity_type_id' => $entity_type_id, - ]) - ->setRequirement('_entity_access', "{$entity_type_id}.duplicate") - ->setOption('parameters', [ - $entity_type_id => ['type' => 'entity:' . $entity_type_id], - ]); - // Entity types with serial IDs can specify this in their route - // requirements, improving the matching process. - if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') { - $route->setRequirement($entity_type_id, '\d+'); - } - - return $route; - } - } - -} diff --git a/web/modules/entity/src/Routing/DeleteMultipleRouteProvider.php b/web/modules/entity/src/Routing/DeleteMultipleRouteProvider.php deleted file mode 100644 index 7fb95481a37662617f4164c3254c519283d1be44..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Routing/DeleteMultipleRouteProvider.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Routing\EntityRouteProviderInterface; -use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\RouteCollection; - -/** - * Provides the HTML route for deleting multiple entities. - * - * @deprecated Since Drupal 8.6.x the core DefaultHtmlRouteProvider provides - * the route for any entity type with a "delete-multiple-form" link template - * and a "delete-multiple-confirm" form. - */ -class DeleteMultipleRouteProvider implements EntityRouteProviderInterface { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $routes = new RouteCollection(); - if ($route = $this->deleteMultipleFormRoute($entity_type)) { - $routes->add('entity.' . $entity_type->id() . '.delete_multiple_form', $route); - } - - return $routes; - } - - /** - * Returns the delete multiple form route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function deleteMultipleFormRoute(EntityTypeInterface $entity_type) { - // Core requires a "delete-multiple-confirm" form to be declared as well, - // if it's missing, it's safe to assume that the entity type is still - // relying on previous Entity API contrib behavior. - if ($entity_type->hasLinkTemplate('delete-multiple-form') && !$entity_type->hasHandlerClass('form', 'delete-multiple-confirm')) { - $route = new Route($entity_type->getLinkTemplate('delete-multiple-form')); - $route->setDefault('_form', '\Drupal\entity\Form\DeleteMultipleForm'); - $route->setDefault('entity_type_id', $entity_type->id()); - $route->setRequirement('_entity_delete_multiple_access', $entity_type->id()); - - return $route; - } - } - -} diff --git a/web/modules/entity/src/Routing/RevisionRouteProvider.php b/web/modules/entity/src/Routing/RevisionRouteProvider.php deleted file mode 100644 index 8d55ae42c97a5beff3656ffeeac3391d8217b395..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/Routing/RevisionRouteProvider.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Routing\EntityRouteProviderInterface; -use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\RouteCollection; - -/** - * Provides revision routes. - */ -class RevisionRouteProvider implements EntityRouteProviderInterface { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = new RouteCollection(); - $entity_type_id = $entity_type->id(); - if ($view_route = $this->getRevisionViewRoute($entity_type)) { - $collection->add("entity.$entity_type_id.revision", $view_route); - } - if ($view_route = $this->getRevisionRevertRoute($entity_type)) { - $collection->add("entity.$entity_type_id.revision_revert_form", $view_route); - } - - if ($view_route = $this->getRevisionHistoryRoute($entity_type)) { - $collection->add("entity.$entity_type_id.version_history", $view_route); - } - - return $collection; - } - - /** - * Gets the entity revision view route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getRevisionViewRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('revision')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('revision')); - $route->addDefaults([ - '_controller' => '\Drupal\Core\Entity\Controller\EntityViewController::viewRevision', - '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title', - ]); - $route->addRequirements([ - '_entity_access_revision' => "$entity_type_id.view", - ]); - $route->setOption('parameters', [ - $entity_type->id() => [ - 'type' => 'entity:' . $entity_type->id(), - ], - $entity_type->id() . '_revision' => [ - 'type' => 'entity_revision:' . $entity_type->id(), - ], - ]); - return $route; - } - } - - /** - * Gets the entity revision revert route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('revision-revert-form')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('revision-revert-form')); - $route->addDefaults([ - '_form' => '\Drupal\entity\Form\RevisionRevertForm', - 'title' => 'Revert to earlier revision', - ]); - $route->addRequirements([ - '_entity_access_revision' => "$entity_type_id.update", - ]); - $route->setOption('parameters', [ - $entity_type->id() => [ - 'type' => 'entity:' . $entity_type->id(), - ], - $entity_type->id() . '_revision' => [ - 'type' => 'entity_revision:' . $entity_type->id(), - ], - ]); - return $route; - } - } - - /** - * Gets the entity revision version history route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getRevisionHistoryRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('version-history')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('version-history')); - $route->addDefaults([ - '_controller' => '\Drupal\entity\Controller\RevisionOverviewController::revisionOverviewController', - '_title' => 'Revisions', - ]); - $route->setRequirement('_entity_access_revision', "$entity_type_id.list"); - $route->setOption('entity_type_id', $entity_type->id()); - $route->setOption('parameters', [ - $entity_type->id() => [ - 'type' => 'entity:' . $entity_type->id(), - ], - ]); - return $route; - } - } - -} diff --git a/web/modules/entity/src/UncacheableEntityAccessControlHandler.php b/web/modules/entity/src/UncacheableEntityAccessControlHandler.php deleted file mode 100644 index a53724bedffe178a211b2ed81bd3d795d40d35b6..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/UncacheableEntityAccessControlHandler.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Session\AccountInterface; - -/** - * Controls access based on the uncacheable entity permissions. - * - * @see \Drupal\entity\UncacheableEntityPermissionProvider - * - * Note: this access control handler will cause pages to be cached per user. - */ -class UncacheableEntityAccessControlHandler extends EntityAccessControlHandlerBase { - - /** - * {@inheritdoc} - */ - public function __construct(EntityTypeInterface $entity_type) { - parent::__construct($entity_type); - - if (!$entity_type->hasHandlerClass('permission_provider') || !is_a($entity_type->getHandlerClass('permission_provider'), UncacheableEntityPermissionProvider::class, TRUE)) { - throw new \Exception('\Drupal\entity\UncacheableEntityAccessControlHandler requires the \Drupal\entity\UncacheableEntityPermissionProvider permission provider.'); - } - } - - /** - * {@inheritdoc} - */ - protected function checkEntityOwnerPermissions(EntityInterface $entity, $operation, AccountInterface $account) { - /** @var \Drupal\user\EntityOwnerInterface $entity */ - if ($operation === 'view' && $entity instanceof EntityPublishedInterface && !$entity->isPublished()) { - if ($account->id() != $entity->getOwnerId()) { - // There's no permission for viewing other user's unpublished entity. - return AccessResult::neutral()->cachePerUser(); - } - - $permissions = [ - "view own unpublished {$entity->getEntityTypeId()}", - ]; - $result = AccessResult::allowedIfHasPermissions($account, $permissions)->cachePerUser(); - } - else { - $result = parent::checkEntityOwnerPermissions($entity, $operation, $account); - } - - return $result; - } - -} diff --git a/web/modules/entity/src/UncacheableEntityPermissionProvider.php b/web/modules/entity/src/UncacheableEntityPermissionProvider.php deleted file mode 100644 index 10c2f37d93db48b99fd993c930d5de4277dec3f9..0000000000000000000000000000000000000000 --- a/web/modules/entity/src/UncacheableEntityPermissionProvider.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -namespace Drupal\entity; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\user\EntityOwnerInterface; - -/** - * Provides generic entity permissions which are cached per user. - * - * Intended for content entity types, since config entity types usually rely - * on a single "administer" permission. - * - * Provided permissions: - * - The declared "admin_permission" of the entity type (or - * "administer $entity_type" if the entity type does not declare an - * administrative permission) - * - access $entity_type overview - * - view own unpublished $entity_type - * - view (own|any) ($bundle) $entity_type - * - update (own|any) ($bundle) $entity_type - * - duplicate (own|any) ($bundle) $entity_type - * - delete (own|any) ($bundle) $entity_type - * - create $bundle $entity_type - * - * Important: - * Provides "view own ($bundle) $entity_type" permissions, which require - * caching pages per user. This can significantly increase the size of caches, - * impacting site performance. Use \Drupal\entity\EntityPermissionProvider - * if those permissions are not necessary. - * - * Example annotation: - * @code - * handlers = { - * "access" = "Drupal\entity\UncacheableEntityAccessControlHandler", - * "permission_provider" = "Drupal\entity\UncacheableEntityPermissionProvider", - * } - * @endcode - * - * @see \Drupal\entity\EntityAccessControlHandler - * @see \Drupal\entity\EntityPermissions - */ -class UncacheableEntityPermissionProvider extends EntityPermissionProviderBase { - - /** - * Builds permissions for the entity_type granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildEntityTypePermissions(EntityTypeInterface $entity_type) { - $permissions = parent::buildEntityTypePermissions($entity_type); - - $entity_type_id = $entity_type->id(); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $plural_label = $entity_type->getPluralLabel(); - - if ($has_owner) { - $permissions["view any {$entity_type_id}"] = [ - 'title' => $this->t('View any @type', [ - '@type' => $plural_label, - ]), - ]; - $permissions["view own {$entity_type_id}"] = [ - 'title' => $this->t('View own @type', [ - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["view {$entity_type_id}"] = [ - 'title' => $this->t('View @type', [ - '@type' => $plural_label, - ]), - ]; - } - - return $permissions; - } - - /** - * Builds permissions for the bundle granularity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return array - * The permissions. - */ - protected function buildBundlePermissions(EntityTypeInterface $entity_type) { - $permissions = parent::buildBundlePermissions($entity_type); - $entity_type_id = $entity_type->id(); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - $has_owner = $entity_type->entityClassImplements(EntityOwnerInterface::class); - $plural_label = $entity_type->getPluralLabel(); - - if ($has_owner) { - $permissions["view any {$entity_type_id}"] = [ - 'title' => $this->t('View any @type', [ - '@type' => $plural_label, - ]), - ]; - $permissions["view own {$entity_type_id}"] = [ - 'title' => $this->t('View own @type', [ - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["view {$entity_type_id}"] = [ - 'title' => $this->t('View @type', [ - '@type' => $plural_label, - ]), - ]; - } - - foreach ($bundles as $bundle_name => $bundle_info) { - if ($has_owner) { - $permissions["view any {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: View any @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - $permissions["view own {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: View own @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - else { - $permissions["view {$bundle_name} {$entity_type_id}"] = [ - 'title' => $this->t('@bundle: View @type', [ - '@bundle' => $bundle_info['label'], - '@type' => $plural_label, - ]), - ]; - } - } - - return $permissions; - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/entity_module_bundle_plugin_examples_test.info.yml b/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/entity_module_bundle_plugin_examples_test.info.yml deleted file mode 100644 index 110d2ec4c6ecccd4b157a8514147d24129628d08..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/entity_module_bundle_plugin_examples_test.info.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: 'Entity bundle plugin examples test' -type: module -description: 'Module for testing bundle plugins.' -package: Testing -core_version_requirement: ^8.7.7 || ^9 -dependencies: - - entity - -# Information added by Drupal.org packaging script on 2020-11-26 -version: '8.x-1.2' -project: 'entity' -datestamp: 1606399152 diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/src/Plugin/BundlePluginTest/Second.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/src/Plugin/BundlePluginTest/Second.php deleted file mode 100644 index a047b6e818beb5fcb0f0174bba2f7c2eed80765d..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_examples_test/src/Plugin/BundlePluginTest/Second.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_examples_test\Plugin\BundlePluginTest; - -use Drupal\entity\BundleFieldDefinition; -use Drupal\Core\Plugin\PluginBase; -use Drupal\entity_module_bundle_plugin_test\Plugin\BundlePluginTest\BundlePluginTestInterface; - -/** - * Provides the second bundle plugin. - * - * @BundlePluginTest( - * id = "second", - * label = @Translation("Second"), - * ) - */ -class Second extends PluginBase implements BundlePluginTestInterface { - - /** - * {@inheritdoc} - */ - public function buildFieldDefinitions() { - $fields = []; - $fields['second_mail'] = BundleFieldDefinition::create('email') - ->setLabel(t('Email')) - ->setRequired(TRUE); - - return $fields; - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.info.yml b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.info.yml deleted file mode 100644 index 22d7283f4f8af9584f44da3293f962df751e094c..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.info.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: 'Entity bundle plugin test' -type: module -description: 'Module for testing bundle plugins.' -package: Testing -core_version_requirement: ^8.7.7 || ^9 -dependencies: - - entity - -# Information added by Drupal.org packaging script on 2020-11-26 -version: '8.x-1.2' -project: 'entity' -datestamp: 1606399152 diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.services.yml b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.services.yml deleted file mode 100644 index ead5cd39d734f5bf561fae9f49ff385d26dae3ca..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/entity_module_bundle_plugin_test.services.yml +++ /dev/null @@ -1,4 +0,0 @@ -services: - plugin.manager.bundle_plugin_test: - class: Drupal\entity_module_bundle_plugin_test\BundlePluginTestManager - parent: default_plugin_manager diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Annotation/BundlePluginTest.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Annotation/BundlePluginTest.php deleted file mode 100644 index f09f70eb2ecb9f704d91b0e0144a3fa9708c217f..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Annotation/BundlePluginTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_test\Annotation; - -use Drupal\Component\Annotation\Plugin; - -/** - * Defines the BundlePluginTest annotation object. - * - * Plugin namespace: Plugin\BundlePluginTest. - * - * @see plugin_api - * - * @Annotation - */ -class BundlePluginTest extends Plugin { - - /** - * The plugin ID. - * - * @var string - */ - public $id; - - /** - * The plugin label. - * - * @ingroup plugin_translatable - * - * @var \Drupal\Core\Annotation\Translation - */ - public $label; - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/BundlePluginTestManager.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/BundlePluginTestManager.php deleted file mode 100644 index 68cd398efbd1f50469d3af06419af59a775b5df5..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/BundlePluginTestManager.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_test; - -use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Plugin\DefaultPluginManager; - -/** - * Manages discovery and instantiation of BundlePluginTest plugins. - * - * @see \Drupal\entity_module_bundle_plugin_test\Annotation\BundlePluginTest - * @see plugin_api - */ -class BundlePluginTestManager extends DefaultPluginManager { - - /** - * Constructs a new BundlePluginTestManager object. - * - * @param \Traversable $namespaces - * An object that implements \Traversable which contains the root paths - * keyed by the corresponding namespace to look for plugin implementations. - * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend - * The cache backend. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/BundlePluginTest', $namespaces, $module_handler, 'Drupal\entity_module_bundle_plugin_test\Plugin\BundlePluginTest\BundlePluginTestInterface', 'Drupal\entity_module_bundle_plugin_test\Annotation\BundlePluginTest'); - - $this->alterInfo('bundle_plugin_test_info'); - $this->setCacheBackend($cache_backend, 'bundle_plugin_test_plugins'); - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Entity/EntityTestBundlePlugin.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Entity/EntityTestBundlePlugin.php deleted file mode 100644 index 1c75a477a1b17464a8336430c1b9f679e9b672a5..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Entity/EntityTestBundlePlugin.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_test\Entity; - -use Drupal\Core\Entity\ContentEntityBase; - -/** - * Defines the 'entity_test_bundle_plugin' entity class. - * - * @ContentEntityType( - * id = "entity_test_bundle_plugin", - * label = @Translation("Entity test bundle plugin"), - * bundle_label = @Translation("Bundle Plugin Test"), - * bundle_plugin_type = "bundle_plugin_test", - * base_table = "entity_test_bundle_plugin", - * admin_permission = "administer content", - * fieldable = TRUE, - * entity_keys = { - * "id" = "method_id", - * "uuid" = "uuid", - * "bundle" = "type" - * }, - * ) - */ -class EntityTestBundlePlugin extends ContentEntityBase { - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/BundlePluginTestInterface.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/BundlePluginTestInterface.php deleted file mode 100644 index 2b25a02dbad3bca7a81c322cd130d858eaea1b36..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/BundlePluginTestInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_test\Plugin\BundlePluginTest; - -use Drupal\entity\BundlePlugin\BundlePluginInterface; - -/** - * Defines the interface for BundlePluginTest plugins. - */ -interface BundlePluginTestInterface extends BundlePluginInterface { - -} diff --git a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/First.php b/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/First.php deleted file mode 100644 index 728a90b69ca70ade64e12cccabaf7ba13dc6f1c9..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_bundle_plugin_test/src/Plugin/BundlePluginTest/First.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -namespace Drupal\entity_module_bundle_plugin_test\Plugin\BundlePluginTest; - -use Drupal\entity\BundleFieldDefinition; -use Drupal\Core\Plugin\PluginBase; - -/** - * Provides the first bundle plugin. - * - * @BundlePluginTest( - * id = "first", - * label = @Translation("First"), - * description = @Translation("Some description"), - * ) - */ -class First extends PluginBase implements BundlePluginTestInterface { - - /** - * {@inheritdoc} - */ - public function buildFieldDefinitions() { - $fields = []; - $fields['first_mail'] = BundleFieldDefinition::create('email') - ->setLabel(t('Email')) - ->setRequired(TRUE); - - return $fields; - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.first.assigned.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.first.assigned.yml deleted file mode 100644 index 9e9c57738599f0b2c8bda9797e0bb07c11fddc42..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.first.assigned.yml +++ /dev/null @@ -1,17 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - field.storage.entity_test_enhanced.assigned -id: entity_test_enhanced.first.assigned -field_name: assigned -entity_type: entity_test_enhanced -bundle: first -label: Assigned -description: '' -required: false -translatable: false -default_value: { } -default_value_callback: '' -settings: { } -field_type: string diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.second.assigned.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.second.assigned.yml deleted file mode 100644 index fb259e3f6662558aedbfb13dc1ce066f06d35510..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/field.field.entity_test_enhanced.second.assigned.yml +++ /dev/null @@ -1,17 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - field.storage.entity_test_enhanced.assigned -id: entity_test_enhanced.second.assigned -field_name: assigned -entity_type: entity_test_enhanced -bundle: second -label: Assigned -description: '' -required: false -translatable: false -default_value: { } -default_value_callback: '' -settings: { } -field_type: string diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/field.storage.entity_test_enhanced.assigned.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/field.storage.entity_test_enhanced.assigned.yml deleted file mode 100644 index 3669b5181517f324153a7aab737c2745ccc76033..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/field.storage.entity_test_enhanced.assigned.yml +++ /dev/null @@ -1,20 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced.assigned -field_name: assigned -entity_type: entity_test_enhanced -type: string -settings: - max_length: 255 - is_ascii: false - case_sensitive: true -module: core -locked: false -cardinality: 1 -translatable: true -indexes: { } -persist_with_no_fields: false -custom_storage: false diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_delete_action.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_delete_action.yml deleted file mode 100644 index c735d873b5a2792ffb6a771594d2ee2d53258cb7..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_delete_action.yml +++ /dev/null @@ -1,10 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_with_owner_delete_action -label: 'Delete enhanced entities with owner' -type: entity_test_enhanced_with_owner -plugin: entity:delete_action:entity_test_enhanced_with_owner -configuration: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_publish_action.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_publish_action.yml deleted file mode 100644 index 5ee7ef1e823f440e091c9fb2d23a0f15c66dfe5f..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_publish_action.yml +++ /dev/null @@ -1,10 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_with_owner_publish_action -label: 'Publish enhanced entities with owner' -type: entity_test_enhanced_with_owner -plugin: entity:publish_action:entity_test_enhanced_with_owner -configuration: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_unpublish_action.yml b/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_unpublish_action.yml deleted file mode 100644 index ad434850db102ce0667113c8f2aef3ef3d32997c..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/install/system.action.entity_test_enhanced_with_owner_unpublish_action.yml +++ /dev/null @@ -1,10 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_with_owner_unpublish_action -label: 'Unpublish enhanced entities with owner' -type: entity_test_enhanced_with_owner -plugin: entity:unpublish_action:entity_test_enhanced_with_owner -configuration: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced.yml b/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced.yml deleted file mode 100644 index ab0ecf5001cfb493b499badddb309e2c4aac6f6a..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced.yml +++ /dev/null @@ -1,170 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced -label: 'Enhanced entities' -module: views -description: '' -tag: '' -base_table: entity_test_enhanced_field_data -base_field: id -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: mini - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: ‹‹ - next: ›› - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - name: - table: entity_test_enhanced_field_data - field: name - id: name - entity_type: null - entity_field: name - plugin_id: field - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: { } - group_column: value - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - filters: { } - sorts: - id: - id: id - table: entity_test_enhanced_field_data - field: id - relationship: none - group_type: group - admin_label: '' - order: ASC - exposed: false - expose: - label: '' - entity_type: entity_test_enhanced - entity_field: id - plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args - tags: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_revisions.yml b/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_revisions.yml deleted file mode 100644 index 98def8a6e776af4c0a541816a8730ad0eac36e56..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_revisions.yml +++ /dev/null @@ -1,170 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_revisions -label: 'Enhanced entities (Revisions)' -module: views -description: '' -tag: '' -base_table: entity_test_enhanced_field_revision -base_field: nid -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: mini - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: ‹‹ - next: ›› - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - name: - table: entity_test_enhanced_field_revision - field: name - id: name - entity_type: null - entity_field: name - plugin_id: field - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: { } - group_column: value - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - filters: { } - sorts: - vid: - id: vid - table: entity_test_enhanced_field_revision - field: vid - relationship: none - group_type: group - admin_label: '' - order: ASC - exposed: false - expose: - label: '' - entity_type: entity_test_enhanced - entity_field: vid - plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args - tags: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner.yml b/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner.yml deleted file mode 100644 index fcee646c2174a596455d6aa56812c26840c12a07..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner.yml +++ /dev/null @@ -1,170 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_with_owner -label: 'Enhanced entities with an owner' -module: views -description: '' -tag: '' -base_table: entity_test_enhanced_with_owner_field_data -base_field: id -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: mini - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: ‹‹ - next: ›› - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - name: - table: entity_test_enhanced_with_owner_field_data - field: name - id: name - entity_type: null - entity_field: name - plugin_id: field - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: { } - group_column: value - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - filters: { } - sorts: - id: - id: id - table: entity_test_enhanced_with_owner_field_data - field: id - relationship: none - group_type: group - admin_label: '' - order: ASC - exposed: false - expose: - label: '' - entity_type: entity_test_enhanced_with_owner - entity_field: id - plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args - tags: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner_revisions.yml b/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner_revisions.yml deleted file mode 100644 index 6e3c7e933c6c3247958eebbaa45c5c041ded5bf1..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/config/optional/views.view.entity_test_enhanced_with_owner_revisions.yml +++ /dev/null @@ -1,170 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_module_test -id: entity_test_enhanced_with_owner_revisions -label: 'Enhanced entities with an owner (Revisions)' -module: views -description: '' -tag: '' -base_table: entity_test_enhanced_with_owner_field_revision -base_field: nid -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: mini - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: ‹‹ - next: ›› - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - name: - table: entity_test_enhanced_with_owner_field_revision - field: name - id: name - entity_type: null - entity_field: name - plugin_id: field - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: { } - group_column: value - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - filters: { } - sorts: - vid: - id: vid - table: entity_test_enhanced_with_owner_field_revision - field: vid - relationship: none - group_type: group - admin_label: '' - order: ASC - exposed: false - expose: - label: '' - entity_type: entity_test_enhanced_with_owner - entity_field: vid - plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args - tags: { } diff --git a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.info.yml b/web/modules/entity/tests/modules/entity_module_test/entity_module_test.info.yml deleted file mode 100644 index d1b46fded39a7264ea6b0571e4079f67b00c5bcb..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.info.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Entity test -type: module -package: Testing -core_version_requirement: ^8.7.7 || ^9 -dependencies: - - field - -# Information added by Drupal.org packaging script on 2020-11-26 -version: '8.x-1.2' -project: 'entity' -datestamp: 1606399152 diff --git a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.module b/web/modules/entity/tests/modules/entity_module_test/entity_module_test.module deleted file mode 100644 index bcd14929a254c10b5f844b53fc554549a1c157a9..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.module +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -/** - * Implements hook_entity_bundle_info(). - */ -function entity_module_test_entity_bundle_info() { - $bundles['entity_test_enhanced']['default']['label'] = t('Default'); - $bundles['entity_test_enhanced']['first']['label'] = t('First'); - $bundles['entity_test_enhanced']['second']['label'] = t('Second'); - $bundles['entity_test_enhanced_with_owner']['default']['label'] = t('Default'); - $bundles['entity_test_enhanced_with_owner']['first']['label'] = t('First'); - $bundles['entity_test_enhanced_with_owner']['second']['label'] = t('Second'); - - return $bundles; -} diff --git a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.permissions.yml b/web/modules/entity/tests/modules/entity_module_test/entity_module_test.permissions.yml deleted file mode 100644 index 4821c726f3761b23b04f7e4d841af7d9cc0011bb..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.permissions.yml +++ /dev/null @@ -1,6 +0,0 @@ -'view all entity_test_enhanced revisions': - title: 'View all entity_test_enhanced revisions' - 'restrict access': TRUE -'revert all entity_test_enhanced revisions': - title: 'Revert all entity_test_enhanced revisions' - 'restrict access': TRUE diff --git a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.services.yml b/web/modules/entity/tests/modules/entity_module_test/entity_module_test.services.yml deleted file mode 100644 index 60f953c10a1a0e745248a0891a8024abb41d683a..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/entity_module_test.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - entity_module_test.query_access_subscriber: - class: Drupal\entity_module_test\EventSubscriber\QueryAccessSubscriber - tags: - - { name: event_subscriber } diff --git a/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php b/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php deleted file mode 100644 index eba3f3aa99a191c9046bfa4301a5e51a89278c7b..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php - -namespace Drupal\entity_module_test\Entity; - -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityPublishedTrait; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity\Revision\RevisionableContentEntityBase; - -/** - * Provides a test entity which uses all the capabilities of entity module. - * - * @ContentEntityType( - * id = "entity_test_enhanced", - * label = @Translation("Enhanced entity"), - * label_collection = @Translation("Enhanced entities"), - * label_singular = @Translation("enhanced entity"), - * label_plural = @Translation("enhanced entities"), - * label_count = @PluralTranslation( - * singular = "@count enhanced entity", - * plural = "@count enhanced entities", - * ), - * handlers = { - * "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage", - * "access" = "\Drupal\entity\EntityAccessControlHandler", - * "query_access" = "\Drupal\entity\QueryAccess\QueryAccessHandler", - * "permission_provider" = "\Drupal\entity\EntityPermissionProvider", - * "form" = { - * "add" = "\Drupal\entity_module_test\Form\EnhancedEntityForm", - * "edit" = "\Drupal\entity_module_test\Form\EnhancedEntityForm", - * "duplicate" = "\Drupal\entity_module_test\Form\EnhancedEntityForm", - * "delete" = "\Drupal\Core\Entity\EntityDeleteForm", - * }, - * "route_provider" = { - * "html" = "\Drupal\entity\Routing\DefaultHtmlRouteProvider", - * "revision" = "\Drupal\entity\Routing\RevisionRouteProvider", - * "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider", - * }, - * "local_action_provider" = { - * "collection" = "\Drupal\entity\Menu\EntityCollectionLocalActionProvider", - * }, - * "local_task_provider" = { - * "default" = "\Drupal\entity\Menu\DefaultEntityLocalTaskProvider", - * }, - * "list_builder" = "\Drupal\Core\Entity\EntityListBuilder", - * "views_data" = "\Drupal\entity\EntityViewsData", - * }, - * base_table = "entity_test_enhanced", - * data_table = "entity_test_enhanced_field_data", - * revision_table = "entity_test_enhanced_revision", - * revision_data_table = "entity_test_enhanced_field_revision", - * translatable = TRUE, - * revisionable = TRUE, - * admin_permission = "administer entity_test_enhanced", - * permission_granularity = "bundle", - * entity_keys = { - * "id" = "id", - * "bundle" = "type", - * "revision" = "vid", - * "langcode" = "langcode", - * "label" = "name", - * "published" = "status", - * }, - * revision_metadata_keys = { - * "revision_user" = "revision_user", - * "revision_created" = "revision_created", - * "revision_log_message" = "revision_log_message" - * }, - * links = { - * "add-page" = "/entity_test_enhanced/add", - * "add-form" = "/entity_test_enhanced/add/{type}", - * "edit-form" = "/entity_test_enhanced/{entity_test_enhanced}/edit", - * "duplicate-form" = "/entity_test_enhanced/{entity_test_enhanced}/duplicate", - * "canonical" = "/entity_test_enhanced/{entity_test_enhanced}", - * "collection" = "/entity_test_enhanced", - * "delete-form" = "/entity_test_enhanced/{entity_test_enhanced}/delete", - * "delete-multiple-form" = "/entity_test_enhanced/delete", - * "revision" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/view", - * "revision-revert-form" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/revert", - * "version-history" = "/entity_test_enhanced/{entity_test_enhanced}/revisions", - * }, - * ) - */ -class EnhancedEntity extends RevisionableContentEntityBase implements EntityPublishedInterface { - - use EntityPublishedTrait; - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields = parent::baseFieldDefinitions($entity_type); - $fields += static::publishedBaseFieldDefinitions($entity_type); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel('Name') - ->setRevisionable(TRUE) - ->setDisplayOptions('form', [ - 'type' => 'string_textfield', - 'weight' => 0, - ]) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'string', - 'weight' => -5, - ]); - - return $fields; - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntityWithOwner.php b/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntityWithOwner.php deleted file mode 100644 index 894262df97a09655c5aac0e24a473d5bd0dcec18..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/src/Entity/EnhancedEntityWithOwner.php +++ /dev/null @@ -1,118 +0,0 @@ -<?php - -namespace Drupal\entity_module_test\Entity; - -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityPublishedTrait; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity\Revision\RevisionableContentEntityBase; -use Drupal\user\EntityOwnerInterface; -use Drupal\user\EntityOwnerTrait; - -/** - * Provides a test entity which uses all the capabilities of entity module. - * - * @ContentEntityType( - * id = "entity_test_enhanced_with_owner", - * label = @Translation("Enhanced entity with owner"), - * label_collection = @Translation("Enhanced entities with owner"), - * label_singular = @Translation("enhanced entity with owner"), - * label_plural = @Translation("enhanced entities with owner"), - * label_count = @PluralTranslation( - * singular = "@count enhanced entity with owner", - * plural = "@count enhanced entities with owner", - * ), - * handlers = { - * "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage", - * "access" = "\Drupal\entity\UncacheableEntityAccessControlHandler", - * "query_access" = "\Drupal\entity\QueryAccess\UncacheableQueryAccessHandler", - * "permission_provider" = "\Drupal\entity\UncacheableEntityPermissionProvider", - * "form" = { - * "add" = "\Drupal\Core\Entity\ContentEntityForm", - * "edit" = "\Drupal\Core\Entity\ContentEntityForm", - * "delete" = "\Drupal\Core\Entity\EntityDeleteForm", - * }, - * "route_provider" = { - * "html" = "\Drupal\entity\Routing\DefaultHtmlRouteProvider", - * "revision" = "\Drupal\entity\Routing\RevisionRouteProvider", - * "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider", - * }, - * "local_action_provider" = { - * "collection" = "\Drupal\entity\Menu\EntityCollectionLocalActionProvider", - * }, - * "list_builder" = "\Drupal\entity\BulkFormEntityListBuilder", - * "views_data" = "\Drupal\entity\EntityViewsData", - * }, - * base_table = "entity_test_enhanced_with_owner", - * data_table = "entity_test_enhanced_with_owner_field_data", - * revision_table = "entity_test_enhanced_with_owner_revision", - * revision_data_table = "entity_test_enhanced_with_owner_field_revision", - * translatable = TRUE, - * revisionable = TRUE, - * admin_permission = "administer entity_test_enhanced_with_owner", - * permission_granularity = "bundle", - * entity_keys = { - * "id" = "id", - * "bundle" = "type", - * "revision" = "vid", - * "langcode" = "langcode", - * "label" = "name", - * "owner" = "user_id", - * "published" = "status", - * }, - * revision_metadata_keys = { - * "revision_user" = "revision_user", - * "revision_created" = "revision_created", - * "revision_log_message" = "revision_log_message" - * }, - * links = { - * "add-page" = "/entity_test_enhanced_with_owner/add", - * "add-form" = "/entity_test_enhanced_with_owner/add/{type}", - * "edit-form" = "/entity_test_enhanced_with_owner/{entity_test_enhanced_with_owner}/edit", - * "duplicate-form" = "/entity_test_enhanced/{entity_test_enhanced}/duplicate", - * "canonical" = "/entity_test_enhanced_with_owner/{entity_test_enhanced_with_owner}", - * "collection" = "/entity_test_enhanced_with_owner", - * "delete-multiple-form" = "/entity_test_enhanced_with_owner/delete", - * }, - * ) - */ -class EnhancedEntityWithOwner extends RevisionableContentEntityBase implements EntityOwnerInterface, EntityPublishedInterface { - - use EntityOwnerTrait, EntityPublishedTrait; - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields = parent::baseFieldDefinitions($entity_type); - $fields += static::ownerBaseFieldDefinitions($entity_type); - $fields += static::publishedBaseFieldDefinitions($entity_type); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel('Name') - ->setRevisionable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'string', - 'weight' => -5, - ]); - - $fields['user_id'] - // Default EntityTest entities to have the root user as the owner, to - // simplify testing. - ->setDefaultValue([0 => ['target_id' => 1]]) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => -1, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'placeholder' => '', - ], - ]); - - return $fields; - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php b/web/modules/entity/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php deleted file mode 100644 index cb3ee0ea5d2452c22bbc6d76bab460d86b9a1d1e..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php - -namespace Drupal\entity_module_test\EventSubscriber; - -use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\entity\QueryAccess\ConditionGroup; -use Drupal\entity\QueryAccess\QueryAccessEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -class QueryAccessSubscriber implements EventSubscriberInterface { - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - return [ - 'entity.query_access' => 'onGenericQueryAccess', - 'entity.query_access.entity_test_enhanced' => 'onQueryAccess', - 'entity.query_access.node' => 'onEventOnlyQueryAccess', - ]; - } - - /** - * Modifies the access conditions based on the entity type. - * - * This is just a convenient example for testing the catch-all event. A real - * subscriber would probably extend the conditions based on the third party - * settings it set on the entity type(s). - * - * @param \Drupal\entity\QueryAccess\QueryAccessEvent $event - * The event. - */ - public function onGenericQueryAccess(QueryAccessEvent $event) { - $conditions = $event->getConditions(); - $email = $event->getAccount()->getEmail(); - if ($event->getEntityTypeId() == 'entity_test_enhanced_with_owner') { - // Disallow access to entity_test_enhanced_with_owner for the user with - // email address user9000@example.com. Anyone else has access. - if ($email == 'user9000@example.com') { - $conditions->alwaysFalse(); - } - elseif ($email == 'user9001@example.com') { - $conditions->alwaysFalse(FALSE); - } - } - } - - /** - * Modifies the access conditions based on the current user. - * - * This is just a convenient example for testing. A real subscriber would - * ignore the account and extend the conditions to cover additional factors, - * such as a custom entity field. - * - * @param \Drupal\entity\QueryAccess\QueryAccessEvent $event - * The event. - */ - public function onQueryAccess(QueryAccessEvent $event) { - $conditions = $event->getConditions(); - $email = $event->getAccount()->getEmail(); - - if ($email == 'user1@example.com') { - // This user should not have access to any entities. - $conditions->alwaysFalse(); - } - elseif ($email == 'user2@example.com') { - // This user should have access to entities with the IDs 1, 2, and 3. - // The query access handler might have already set ->alwaysFalse() - // due to the user not having any other access, so we make sure - // to undo it with $conditions->alwaysFalse(TRUE). - $conditions->alwaysFalse(FALSE); - $conditions->addCondition('id', ['1', '2', '3']); - } - elseif ($email == 'user3@example.com') { - // This user should only have access to entities assigned to "marketing", - // or unassigned entities. - $conditions->alwaysFalse(FALSE); - $conditions->addCondition((new ConditionGroup('OR')) - ->addCondition('assigned', NULL, 'IS NULL') - // Confirm that explicitly specifying the property name works. - ->addCondition('assigned.value', 'marketing') - ); - } - } - - /** - * Modifies the access conditions based on the node type. - * - * This is just a convenient example for testing whether the event-only query - * access subscriber is added to entity types that do not specify a query - * access handler; in this case: node. - * - * @param \Drupal\entity\QueryAccess\QueryAccessEvent $event - * The event. - */ - public function onEventOnlyQueryAccess(QueryAccessEvent $event) { - if (\Drupal::state()->get('test_event_only_query_access')) { - $conditions = $event->getConditions(); - $conditions->addCondition('type', 'foo'); - - $cacheability = \Drupal::state()->get('event_only_query_acccess_cacheability'); - if ($cacheability instanceof CacheableDependencyInterface) { - $conditions->addCacheableDependency($cacheability); - } - } - } - -} diff --git a/web/modules/entity/tests/modules/entity_module_test/src/Form/EnhancedEntityForm.php b/web/modules/entity/tests/modules/entity_module_test/src/Form/EnhancedEntityForm.php deleted file mode 100644 index 1c42a820b172468c33821a1311b74faeb852f3c5..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/modules/entity_module_test/src/Form/EnhancedEntityForm.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Drupal\entity_module_test\Form; - -use Drupal\Core\Entity\ContentEntityForm; -use Drupal\Core\Form\FormStateInterface; -use Drupal\entity\Form\EntityDuplicateFormTrait; - -class EnhancedEntityForm extends ContentEntityForm { - - use EntityDuplicateFormTrait; - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); - $this->postSave($this->entity, $this->operation); - - $this->messenger()->addMessage($this->t('Saved the %label enhanced entity.', ['%label' => $this->entity->label()])); - $form_state->setRedirect('entity.entity_test_enhanced.collection'); - } - -} diff --git a/web/modules/entity/tests/src/Functional/BulkFormEntityListBuilderTest.php b/web/modules/entity/tests/src/Functional/BulkFormEntityListBuilderTest.php deleted file mode 100644 index 06f941280a36c8b9ef712342b0eed9edf2542a11..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/BulkFormEntityListBuilderTest.php +++ /dev/null @@ -1,220 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional; - -use Drupal\entity_module_test\Entity\EnhancedEntityWithOwner; -use Drupal\Tests\block\Traits\BlockCreationTrait; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests the bulk-form list builder. - * - * @group entity - * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - */ -class BulkFormEntityListBuilderTest extends BrowserTestBase { - - use BlockCreationTrait; - - /** - * The entity storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $storage; - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_module_test', 'user', 'entity', 'block']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'classy'; - - /** - * The base permissions to grant for the test user. - * - * @var string[] - */ - protected $basePermissions = [ - 'access entity_test_enhanced_with_owner overview', - 'view any entity_test_enhanced_with_owner', - 'view own unpublished entity_test_enhanced_with_owner', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - /* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ - $entity_type_manager = $this->container->get('entity_type.manager'); - $this->storage = $entity_type_manager->getStorage('entity_test_enhanced_with_owner'); - - $this->placeBlock('page_title_block'); - $this->placeBlock('local_tasks_block'); - - $account = $this->drupalCreateUser($this->basePermissions); - $this->drupalLogin($account); - } - - /** - * Tests that the bulk form is displayed correctly. - */ - public function testBulkForm() { - $entity = $this->storage->create([ - 'name' => 'Entity 1', - 'type' => 'default', - ]); - $collection_url = $entity->getEntityType()->getLinkTemplate('collection'); - - // Without any entities the bulk form should not be shown. - $this->drupalGet($collection_url); - $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->fieldNotExists('Action'); - $this->assertSession()->buttonNotExists('Apply to selected items'); - - // Create an entity and make sure that the bulk form is shown. - $entity->save(); - $this->drupalGet($collection_url); - $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->fieldExists('Action'); - $this->assertSession()->buttonExists('Apply to selected items'); - - $this->submitForm([], 'Apply to selected items'); - $this->assertSession()->elementTextContains('css', '.messages--error', 'No items selected.'); - } - - /** - * Test the delete action on the bulk form. - */ - public function testDeleteAction() { - $entity = $this->storage->create([ - 'name' => 'Entity 1', - 'type' => 'default', - 'user_id' => $this->loggedInUser->id(), - ]); - $entity->save(); - $id = $entity->id(); - - $this->drupalGet($entity->toUrl('collection')); - $this->assertSession()->fieldValueEquals('Action', 'entity_test_enhanced_with_owner_delete_action'); - $edit = ["entities[$id]" => $id]; - $this->submitForm($edit, 'Apply to selected items'); - - $this->assertSession()->elementTextContains('css', '.messages--error', 'No access to execute Delete enhanced entities with owner on the enhanced entity with owner Entity 1.'); - $this->assertInstanceOf(EnhancedEntityWithOwner::class, $this->storage->load($id)); - - $account = $this->drupalCreateUser(array_merge( - $this->basePermissions, - ['delete any default entity_test_enhanced_with_owner'] - )); - $this->drupalLogin($account); - $this->drupalGet($entity->toUrl('collection')); - $this->submitForm($edit, 'Apply to selected items'); - - $this->assertSession()->elementTextContains('css', 'h1', 'Are you sure you want to delete this enhanced entity with owner?'); - $this->submitForm([], 'Delete'); - // The entity is deleted in the web process, but will still be in the static - // cache of the test process, so we need to clear it manually. - $this->storage->resetCache([$id]); - - $this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner'); - $this->assertSession()->elementTextContains('css', '.messages--status', 'Deleted 1 item.'); - $this->assertNull($this->storage->load($id)); - } - - /** - * Test the publish action on the bulk form. - */ - public function testPublishAction() { - /* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */ - $entity = $this->storage->create([ - 'name' => 'Entity 1', - 'type' => 'default', - 'user_id' => $this->loggedInUser->id(), - 'status' => 0, - ]); - $entity->save(); - $id = $entity->id(); - - $this->drupalGet($entity->toUrl('collection')); - $edit = [ - 'action' => 'entity_test_enhanced_with_owner_publish_action', - "entities[$id]" => $id, - ]; - $this->submitForm($edit, 'Apply to selected items'); - - $this->assertSession()->elementTextContains('css', '.messages--error', 'No access to execute Publish enhanced entities with owner on the enhanced entity with owner Entity 1.'); - $entity = $this->storage->load($id); - $this->assertFalse($entity->isPublished()); - - $account = $this->drupalCreateUser(array_merge( - $this->basePermissions, - ['update any default entity_test_enhanced_with_owner'] - )); - $entity->setOwner($account)->save(); - $this->drupalLogin($account); - $this->drupalGet($entity->toUrl('collection')); - $this->submitForm($edit, 'Apply to selected items'); - // The entity is deleted in the web process, but will still be in the static - // cache of the test process, so we need to clear it manually. - $this->storage->resetCache([$id]); - - $this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner'); - $this->assertSession()->elementTextContains('css', '.messages--status', 'Publish enhanced entities with owner was applied to 1 item.'); - $entity = $this->storage->load($id); - $this->assertTrue($entity->isPublished()); - } - - /** - * Test the unpublish action on the bulk form. - */ - public function testUnpublishAction() { - /* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */ - $entity = $this->storage->create([ - 'name' => 'Entity 1', - 'type' => 'default', - 'user_id' => $this->loggedInUser->id(), - ]); - $entity->save(); - $id = $entity->id(); - - $this->drupalGet($entity->toUrl('collection')); - $edit = [ - 'action' => 'entity_test_enhanced_with_owner_unpublish_action', - "entities[$id]" => $id, - ]; - $this->submitForm($edit, 'Apply to selected items'); - - $this->assertSession()->elementTextContains('css', '.messages--error', 'No access to execute Unpublish enhanced entities with owner on the enhanced entity with owner Entity 1.'); - $entity = $this->storage->load($id); - $this->assertTrue($entity->isPublished()); - - $account = $this->drupalCreateUser(array_merge( - $this->basePermissions, - ['update any default entity_test_enhanced_with_owner'] - )); - $entity->setOwner($account)->save(); - $this->drupalLogin($account); - $this->drupalGet($entity->toUrl('collection')); - $this->submitForm($edit, 'Apply to selected items'); - // The entity is deleted in the web process, but will still be in the static - // cache of the test process, so we need to clear it manually. - $this->storage->resetCache([$id]); - - $this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner'); - $this->assertSession()->elementTextContains('css', '.messages--status', 'Unpublish enhanced entities with owner was applied to 1 item.'); - $entity = $this->storage->load($id); - $this->assertFalse($entity->isPublished()); - } - -} diff --git a/web/modules/entity/tests/src/Functional/CollectionRouteAccessTest.php b/web/modules/entity/tests/src/Functional/CollectionRouteAccessTest.php deleted file mode 100644 index 59544ba6240460aa18a2a63d220b528e831f4c28..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/CollectionRouteAccessTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\Tests\block\Traits\BlockCreationTrait; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests the collection route access check. - * - * @group entity - * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - */ -class CollectionRouteAccessTest extends BrowserTestBase { - - use BlockCreationTrait; - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_module_test', 'user', 'entity', 'block']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->placeBlock('local_tasks_block'); - $this->placeBlock('system_breadcrumb_block'); - } - - /** - * Test the collection route access. - */ - public function testCollectionRouteAccess() { - $entity = EnhancedEntity::create([ - 'name' => 'rev 1', - 'type' => 'default', - ]); - $entity->save(); - - // User without any relevant permissions. - $account = $this->drupalCreateUser(['access administration pages']); - $this->drupalLogin($account); - - $this->drupalGet($entity->toUrl('collection')); - $this->assertSession()->statusCodeEquals(403); - - // User with "access overview" permissions. - $account = $this->drupalCreateUser(['access entity_test_enhanced overview']); - $this->drupalLogin($account); - - $this->drupalGet($entity->toUrl('collection')); - $this->assertSession()->statusCodeEquals(200); - - // User with full administration permissions. - $account = $this->drupalCreateUser(['administer entity_test_enhanced']); - $this->drupalLogin($account); - - $this->drupalGet($entity->toUrl('collection')); - $this->assertSession()->statusCodeEquals(200); - } - -} diff --git a/web/modules/entity/tests/src/Functional/EntityDuplicateTest.php b/web/modules/entity/tests/src/Functional/EntityDuplicateTest.php deleted file mode 100644 index bbed104ba66780f839e16164254bb3416a369579..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/EntityDuplicateTest.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\Tests\block\Traits\BlockCreationTrait; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests the entity duplicate UI. - * - * @group entity - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ -class EntityDuplicateTest extends BrowserTestBase { - - use BlockCreationTrait; - - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $account; - - /** - * The entity_test_enhanced storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $storage; - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_module_test', 'user', 'entity', 'block']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->placeBlock('local_tasks_block'); - $this->placeBlock('page_title_block'); - $this->placeBlock('system_breadcrumb_block'); - - $this->account = $this->drupalCreateUser([ - 'administer entity_test_enhanced', - ]); - $this->drupalLogin($this->account); - - $this->storage = $this->container->get('entity_type.manager')->getStorage('entity_test_enhanced'); - } - - /** - * Tests the duplicate form. - */ - public function testForm() { - $entity = EnhancedEntity::create([ - 'name' => 'Test', - 'type' => 'default', - ]); - $entity->save(); - - $this->drupalGet($entity->toUrl('duplicate-form')); - $this->assertSession()->pageTextContains('Duplicate Test'); - $this->submitForm(['name[0][value]' => 'Test2'], 'Save'); - $this->assertSession()->pageTextContains('Saved the Test2 enhanced entity.'); - - $this->storage->resetCache(); - $entity = EnhancedEntity::load('1'); - $this->assertEquals('Test', $entity->label()); - - $duplicated_entity = EnhancedEntity::load('2'); - $this->assertEquals('Test2', $duplicated_entity->label()); - } - -} diff --git a/web/modules/entity/tests/src/Functional/Menu/EntityLocalActionTest.php b/web/modules/entity/tests/src/Functional/Menu/EntityLocalActionTest.php deleted file mode 100644 index 53c489a8c91196d699c592b14f2ce5762ada4302..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/Menu/EntityLocalActionTest.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional\Menu; - -use Drupal\Tests\BrowserTestBase; - -/** - * Tests that entity local actions are generated correctly. - * - * @group entity - * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - */ -class EntityLocalActionTest extends BrowserTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['block', 'entity', 'entity_module_test']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->drupalPlaceBlock('local_actions_block'); - - $account = $this->drupalCreateUser(['administer entity_test_enhanced']); - $this->drupalLogin($account); - } - - /** - * Tests the local action on the collection is provided correctly. - */ - public function testCollectionLocalAction() { - $this->drupalGet('/entity_test_enhanced'); - $this->assertSession()->linkByHrefExists('/entity_test_enhanced/add?destination=/entity_test_enhanced'); - $this->assertSession()->linkExists('Add enhanced entity'); - } - -} diff --git a/web/modules/entity/tests/src/Functional/Menu/EntityLocalTaskTest.php b/web/modules/entity/tests/src/Functional/Menu/EntityLocalTaskTest.php deleted file mode 100644 index e5107d412ef33c40d869eea603433b5971544ec8..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/Menu/EntityLocalTaskTest.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional\Menu; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests that entity local tasks are generated correctly. - * - * @group entity - * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - */ -class EntityLocalTaskTest extends BrowserTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['block', 'entity', 'entity_module_test']; - - /** - * The view path of the entity used in the test. - * - * @var string - */ - protected $viewPath; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $entity = EnhancedEntity::create([ - 'type' => 'default', - ]); - $entity->save(); - $this->viewPath = $entity->toUrl()->toString(); - - $this->drupalPlaceBlock('local_tasks_block'); - - $account = $this->drupalCreateUser(['administer entity_test_enhanced']); - $this->drupalLogin($account); - } - - /** - * Tests the local tasks of the entity are provided correctly. - */ - public function testCollectionLocalAction() { - $this->drupalGet($this->viewPath); - $this->assertLocalTasks(); - - $this->clickLink('Edit'); - $this->assertLocalTasks(); - - $this->clickLink('Duplicate'); - $this->assertLocalTasks(); - - $this->clickLink('Revisions'); - $this->assertLocalTasks(); - } - - /** - * Asserts that the entity's local tasks are visible. - */ - protected function assertLocalTasks() { - $this->assertSession()->linkByHrefExists($this->viewPath); - $this->assertSession()->linkExists('View'); - - $this->assertSession()->linkByHrefExists("$this->viewPath/edit"); - $this->assertSession()->linkExists('Edit'); - - $this->assertSession()->linkByHrefExists("$this->viewPath/duplicate"); - $this->assertSession()->linkExists('Duplicate'); - - $this->assertSession()->linkByHrefExists("$this->viewPath/revisions"); - $this->assertSession()->linkExists('Revisions'); - } - -} diff --git a/web/modules/entity/tests/src/Functional/RevisionRouteAccessTest.php b/web/modules/entity/tests/src/Functional/RevisionRouteAccessTest.php deleted file mode 100644 index 47fb5dffe04107e4791c363b94f2746d004e4e79..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Functional/RevisionRouteAccessTest.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Functional; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\Tests\block\Traits\BlockCreationTrait; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests the revision route access check. - * - * @group entity - * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - */ -class RevisionRouteAccessTest extends BrowserTestBase { - - use BlockCreationTrait; - - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $account; - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_module_test', 'user', 'entity', 'block']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->placeBlock('local_tasks_block'); - $this->placeBlock('system_breadcrumb_block'); - - $this->account = $this->drupalCreateUser([ - 'administer entity_test_enhanced', - 'view all entity_test_enhanced revisions', - ]); - - $this->drupalLogin($this->account); - } - - /** - * Test enhanced entity revision routes access. - */ - public function testRevisionRouteAccess() { - $entity = EnhancedEntity::create([ - 'name' => 'rev 1', - 'type' => 'default', - ]); - $entity->save(); - - $revision = clone $entity; - $revision->name->value = 'rev 2'; - $revision->setNewRevision(TRUE); - $revision->isDefaultRevision(FALSE); - $revision->save(); - - $this->drupalGet('/entity_test_enhanced/1/revisions'); - $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->responseContains('Revisions'); - $collection_link = $this->getSession()->getPage()->findLink('Enhanced entities'); - $collection_link->click(); - $this->assertSession()->addressEquals('/entity_test_enhanced'); - $this->assertSession()->responseContains('Edit'); - $edit_link = $this->getSession()->getPage()->findLink('Edit'); - $edit_link->click(); - $this->assertSession()->addressEquals('/entity_test_enhanced/1/edit'); - // Check if we have revision tab link on edit page. - $this->getSession()->getPage()->findLink('Revisions')->click(); - $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions'); - $this->drupalGet('/entity_test_enhanced/1/revisions/2/view'); - $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->responseContains('rev 2'); - $revisions_link = $this->getSession()->getPage()->findLink('Revisions'); - $revisions_link->click(); - $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions'); - $this->assertSession()->statusCodeEquals(200); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/BundleEntityDuplicatorTest.php b/web/modules/entity/tests/src/Kernel/BundleEntityDuplicatorTest.php deleted file mode 100644 index 10f1c215aef13881f65a62ddd7d8cbf16c2cebc3..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/BundleEntityDuplicatorTest.php +++ /dev/null @@ -1,290 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel; - -use Drupal\entity_test\Entity\EntityTestBundle; -use Drupal\entity_test\Entity\EntityTestWithBundle; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldStorageConfig; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; -use Drupal\system\Entity\Action; - -/** - * Tests the bundle entity duplicator. - * - * @coversDefaultClass \Drupal\entity\BundleEntityDuplicator - * @group entity - */ -class BundleEntityDuplicatorTest extends EntityKernelTestBase { - - /** - * A test bundle entity. - * - * @var \Drupal\Core\Config\Entity\ConfigEntityInterface - */ - protected $bundleEntity; - - /** - * The bundle entity duplicator. - * - * @var \Drupal\entity\BundleEntityDuplicator - */ - protected $duplicator; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('action'); - - $this->bundleEntity = EntityTestBundle::create([ - 'id' => 'test', - 'label' => 'Test', - 'description' => 'This is the original description!', - ]); - $this->bundleEntity->save(); - $this->duplicator = $this->container->get('entity.bundle_entity_duplicator'); - } - - /** - * @covers ::duplicate - */ - public function testDuplicateInvalidEntity() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The "action" entity type is not a bundle entity type.'); - $this->duplicator->duplicate(Action::create(), []); - } - - /** - * @covers ::duplicate - */ - public function testDuplicateNoId() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The $values[\'id\'] key is empty or missing.'); - $this->duplicator->duplicate($this->bundleEntity, []); - } - - /** - * @covers ::duplicate - */ - public function testDuplicate() { - $duplicated_bundle_entity = $this->duplicator->duplicate($this->bundleEntity, [ - 'id' => 'test2', - 'label' => 'Test2', - ]); - $this->assertFalse($duplicated_bundle_entity->isNew()); - $this->assertEquals('test2', $duplicated_bundle_entity->id()); - $this->assertEquals('Test2', $duplicated_bundle_entity->label()); - $this->assertEquals($this->bundleEntity->get('description'), $duplicated_bundle_entity->get('description')); - } - - /** - * @covers ::duplicate - * @covers ::duplicateFields - * @covers ::duplicateDisplays - */ - public function testDuplicateWithFieldAndDisplays() { - $this->createTextField('field_text', 'test', 'Test text'); - $form_display = $this->getDisplay('entity_test_with_bundle', 'test', 'form'); - $form_display->setComponent('field_text', [ - 'type' => 'text_textfield', - 'weight' => 0, - ]); - $form_display->save(); - $view_display = $this->getDisplay('entity_test_with_bundle', 'test', 'view'); - $view_display->setComponent('field_text', [ - 'type' => 'text_default', - 'weight' => 0, - ]); - $view_display->save(); - - $duplicated_bundle_entity = $this->duplicator->duplicate($this->bundleEntity, [ - 'id' => 'test2', - 'label' => 'Test2', - ]); - $this->assertFalse($duplicated_bundle_entity->isNew()); - $this->assertEquals('test2', $duplicated_bundle_entity->id()); - $this->assertEquals('Test2', $duplicated_bundle_entity->label()); - $this->assertEquals($this->bundleEntity->get('description'), $duplicated_bundle_entity->get('description')); - - // Confirm that the field was copied to the new bundle. - $entity = EntityTestWithBundle::create(['type' => 'test2']); - $this->assertTrue($entity->hasField('field_text')); - - // Confirm that the entity displays were copied. - $form_display = $this->getDisplay('entity_test_with_bundle', 'test2', 'form'); - $this->assertNotEmpty($form_display->getComponent('field_text')); - - $view_display = $this->getDisplay('entity_test_with_bundle', 'test2', 'view'); - $this->assertNotEmpty($view_display->getComponent('field_text')); - } - - /** - * @covers ::duplicateFields - */ - public function testDuplicateFieldsInvalidEntity() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The "action" entity type is not a bundle entity type.'); - $this->duplicator->duplicateFields(Action::create(), 'test2'); - } - - /** - * @covers ::duplicateFields - */ - public function testDuplicateFieldsEmptyTarget() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The $target_bundle_id must not be empty.'); - $this->duplicator->duplicateFields($this->bundleEntity, ''); - } - - /** - * @covers ::duplicateFields - */ - public function testDuplicateFields() { - $this->createTextField('field_text', 'test', 'Test text'); - $this->createTextField('field_text2', 'test', 'Test text2'); - - $second_bundle_entity = EntityTestBundle::create([ - 'id' => 'test2', - 'label' => 'Test2', - ]); - $second_bundle_entity->save(); - $entity = EntityTestWithBundle::create(['type' => 'test2']); - $this->assertFalse($entity->hasField('field_text')); - $this->assertFalse($entity->hasField('field_text2')); - - $this->duplicator->duplicateFields($this->bundleEntity, 'test2'); - $entity = EntityTestWithBundle::create(['type' => 'test2']); - $this->assertTrue($entity->hasField('field_text')); - $this->assertTrue($entity->hasField('field_text2')); - } - - /** - * @covers ::duplicateDisplays - */ - public function testDuplicateDisplaysInvalidEntity() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The "action" entity type is not a bundle entity type.'); - $this->duplicator->duplicateDisplays(Action::create(), 'test2'); - } - - /** - * @covers ::duplicateDisplays - */ - public function testDuplicateDisplaysEmptyTarget() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The $target_bundle_id must not be empty.'); - $this->duplicator->duplicateDisplays($this->bundleEntity, ''); - } - - /** - * @covers ::duplicateDisplays - */ - public function testDuplicateDisplays() { - $this->createTextField('field_text', 'test', 'Test text'); - $form_display = $this->getDisplay('entity_test_with_bundle', 'test', 'form'); - $form_display->setComponent('field_text', [ - 'type' => 'text_textfield', - 'weight' => 0, - ]); - $form_display->save(); - $view_display = $this->getDisplay('entity_test_with_bundle', 'test', 'view'); - $view_display->setComponent('field_text', [ - 'type' => 'text_default', - 'weight' => 0, - ]); - $view_display->save(); - - $second_bundle_entity = EntityTestBundle::create([ - 'id' => 'test2', - 'label' => 'Test2', - ]); - $second_bundle_entity->save(); - FieldConfig::create([ - 'entity_type' => 'entity_test_with_bundle', - 'field_name' => 'field_text', - 'bundle' => 'test2', - 'label' => 'Test text', - ])->save(); - - $this->duplicator->duplicateDisplays($this->bundleEntity, 'test2'); - $form_display = $this->getDisplay('entity_test_with_bundle', 'test2', 'form'); - $this->assertNotEmpty($form_display->getComponent('field_text')); - - $view_display = $this->getDisplay('entity_test_with_bundle', 'test2', 'view'); - $this->assertNotEmpty($view_display->getComponent('field_text')); - } - - /** - * Creates a text field on the "entity_test_with_bundle" entity. - * - * @param string $field_name - * The field name. - * @param string $bundle - * The target bundle. - * @param string $label - * The field label. - */ - protected function createTextField($field_name, $bundle, $label) { - FieldStorageConfig::create([ - 'field_name' => $field_name, - 'entity_type' => 'entity_test_with_bundle', - 'type' => 'text', - 'cardinality' => 1, - ])->save(); - FieldConfig::create([ - 'entity_type' => 'entity_test_with_bundle', - 'field_name' => $field_name, - 'bundle' => $bundle, - 'label' => $label, - ])->save(); - } - - /** - * Gets the entity display for the given entity type and bundle. - * - * The entity display will be created if missing. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The bundle. - * @param string $display_context - * The display context ('view' or 'form'). - * - * @throws \InvalidArgumentException - * Thrown when an invalid display context is provided. - * - * @return \Drupal\Core\Entity\Display\EntityDisplayInterface - * The entity display. - */ - protected function getDisplay($entity_type, $bundle, $display_context) { - if (!in_array($display_context, ['view', 'form'])) { - throw new \InvalidArgumentException(sprintf('Invalid display_context %s passed to _commerce_product_get_display().', $display_context)); - } - - $entity_type_manager = $this->container->get('entity_type.manager'); - $storage = $entity_type_manager->getStorage('entity_' . $display_context . '_display'); - $display = $storage->load($entity_type . '.' . $bundle . '.default'); - if (!$display) { - $display = $storage->create([ - 'targetEntityType' => $entity_type, - 'bundle' => $bundle, - 'mode' => 'default', - 'status' => TRUE, - ]); - } - - return $display; - } - -} diff --git a/web/modules/entity/tests/src/Kernel/BundlePluginTest.php b/web/modules/entity/tests/src/Kernel/BundlePluginTest.php deleted file mode 100644 index 5f037eba888815492a30c0b59b6b174421d144d6..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/BundlePluginTest.php +++ /dev/null @@ -1,144 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel; - -use Drupal\entity_module_bundle_plugin_test\Entity\EntityTestBundlePlugin; -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests the bundle plugin API. - * - * @group entity - */ -class BundlePluginTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'system', - 'entity', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - // Install the modules properly. Putting them into static::$modules doesn't trigger the install - // hooks, like hook_modules_installed, so entity_modules_installed is not triggered(). - /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ - $module_installer = $this->container->get('module_installer'); - $module_installer->install(['entity_module_bundle_plugin_test', 'entity_module_bundle_plugin_examples_test']); - } - - /** - * Tests the bundle plugins. - */ - public function testPluginBundles() { - $bundled_entity_types = entity_get_bundle_plugin_entity_types(); - /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ - $entity_type = $bundled_entity_types['entity_test_bundle_plugin']; - $this->assertEquals('entity_test_bundle_plugin', $entity_type->id()); - $this->assertTrue($entity_type->hasHandlerClass('bundle_plugin')); - - /** @var \Drupal\Core\Entity\EntityTypeBundleInfo $entity_type_bundle_info */ - $entity_type_bundle_info = $this->container->get('entity_type.bundle.info'); - $bundle_info = $entity_type_bundle_info->getBundleInfo('entity_test_bundle_plugin'); - $this->assertEquals(2, count($bundle_info)); - $this->assertArrayHasKey('first', $bundle_info); - $this->assertArrayHasKey('second', $bundle_info); - $this->assertEquals('First', $bundle_info['first']['label']); - $this->assertEquals('Some description', $bundle_info['first']['description']); - - /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */ - $entity_field_manager = $this->container->get('entity_field.manager'); - $field_storage_definitions = $entity_field_manager->getFieldStorageDefinitions('entity_test_bundle_plugin'); - $this->assertArrayHasKey('first_mail', $field_storage_definitions); - $this->assertArrayHasKey('second_mail', $field_storage_definitions); - $first_field_definitions = $entity_field_manager->getFieldDefinitions('entity_test_bundle_plugin', 'first'); - $this->assertArrayHasKey('first_mail', $first_field_definitions); - $this->assertArrayNotHasKey('second_mail', $first_field_definitions); - $second_field_definitions = $entity_field_manager->getFieldDefinitions('entity_test_bundle_plugin', 'second'); - $this->assertArrayNotHasKey('first_mail', $second_field_definitions); - $this->assertArrayHasKey('second_mail', $second_field_definitions); - - $first_entity = EntityTestBundlePlugin::create([ - 'type' => 'first', - 'first_mail' => 'admin@test.com', - ]); - $first_entity->save(); - $first_entity = EntityTestBundlePlugin::load($first_entity->id()); - $this->assertEquals('admin@test.com', $first_entity->first_mail->value); - - $second_entity = EntityTestBundlePlugin::create([ - 'type' => 'second', - 'second_mail' => 'admin@example.com', - ]); - $second_entity->save(); - $second_entity = EntityTestBundlePlugin::load($second_entity->id()); - $this->assertEquals('admin@example.com', $second_entity->second_mail->value); - - // Also test entity queries. - $result = $this->container->get('entity_type.manager')->getStorage('entity_test_bundle_plugin') - ->getQuery() - ->condition('second_mail', 'admin@example.com') - ->execute(); - $this->assertEquals([$second_entity->id() => $second_entity->id()], $result); - - $result = $this->container->get('entity_type.manager')->getStorage('entity_test_bundle_plugin') - ->getQuery() - ->condition('type', 'first') - ->execute(); - $this->assertEquals([$first_entity->id() => $first_entity->id()], $result); - - } - - /** - * Tests the uninstallation for a bundle provided by a module. - */ - public function testBundlePluginModuleUninstallation() { - /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ - $module_installer = $this->container->get('module_installer'); - - // One should be possible to uninstall without any actual content. - $violations = $module_installer->validateUninstall(['entity_module_bundle_plugin_examples_test']); - $this->assertEmpty($violations); - - $first_entity = EntityTestBundlePlugin::create([ - 'type' => 'first', - 'first_mail' => 'admin@test.com', - ]); - $first_entity->save(); - $second_entity = EntityTestBundlePlugin::create([ - 'type' => 'second', - 'second_mail' => 'admin@example.com', - ]); - $second_entity->save(); - - $violations = $module_installer->validateUninstall(['entity_module_bundle_plugin_examples_test']); - $this->assertCount(1, $violations); - $this->assertCount(1, $violations['entity_module_bundle_plugin_examples_test']); - $this->assertEquals('There is data for the bundle Second on the entity type Entity test bundle plugin. Please remove all content before uninstalling the module.', $violations['entity_module_bundle_plugin_examples_test'][0]); - - $second_entity->delete(); - - // The first entity is defined by entity_module_bundle_plugin_test, so it should be possible - // to uninstall the module providing the second bundle plugin. - $violations = $module_installer->validateUninstall(['entity_module_bundle_plugin_examples_test']); - $this->assertEmpty($violations); - - $module_installer->uninstall(['entity_module_bundle_plugin_examples_test']); - - // The first entity is provided by entity_module_bundle_plugin_test which we cannot uninstall, - // until all the entities are deleted. - $violations = $module_installer->validateUninstall(['entity_module_bundle_plugin_test']); - $this->assertNotEmpty($violations); - - $first_entity->delete(); - $violations = $module_installer->validateUninstall(['entity_module_bundle_plugin_test']); - $this->assertEmpty($violations); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/ConditionGroupTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/ConditionGroupTest.php deleted file mode 100644 index 34dc09ceac4b091cc391d75000019604c0df7277..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/ConditionGroupTest.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity\QueryAccess\Condition; -use Drupal\entity\QueryAccess\ConditionGroup; -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests the condition group class. - * - * ConditionGroup uses \Drupal\Core\Cache\Cache internally, which makes it - * impossible to use a unit test (due to Cache accessing the global container). - * - * @coversDefaultClass \Drupal\entity\QueryAccess\ConditionGroup - * @group entity - */ -class ConditionGroupTest extends KernelTestBase { - - /** - * ::covers getConjunction - * ::covers addCondition - * ::covers getConditions - * ::covers count. - */ - public function testGetters() { - $condition_group = new ConditionGroup(); - $condition_group->addCondition('uid', '2'); - $this->assertEquals('AND', $condition_group->getConjunction()); - $expected_conditions = [ - new Condition('uid', '2'), - ]; - $this->assertEquals($expected_conditions, $condition_group->getConditions()); - $this->assertEquals(1, $condition_group->count()); - $this->assertEquals("uid = '2'", $condition_group->__toString()); - - $condition_group = new ConditionGroup('OR'); - $condition_group->addCondition('type', ['article', 'page']); - $condition_group->addCondition('status', '1', '<>'); - $this->assertEquals('OR', $condition_group->getConjunction()); - $expected_conditions = [ - new Condition('type', ['article', 'page']), - new Condition('status', '1', '<>'), - ]; - $expected_lines = [ - "(", - " type IN ['article', 'page']", - " OR", - " status <> '1'", - ")", - ]; - $this->assertEquals($expected_conditions, $condition_group->getConditions()); - $this->assertEquals(2, $condition_group->count()); - $this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString()); - - // Nested condition group with a single condition. - $condition_group = new ConditionGroup(); - $condition_group->addCondition('type', ['article', 'page']); - $condition_group->addCondition((new ConditionGroup('AND')) - ->addCondition('status', '1') - ); - $expected_conditions = [ - new Condition('type', ['article', 'page']), - new Condition('status', '1'), - ]; - $expected_lines = [ - "(", - " type IN ['article', 'page']", - " AND", - " status = '1'", - ")", - ]; - $this->assertEquals($expected_conditions, $condition_group->getConditions()); - $this->assertEquals('AND', $condition_group->getConjunction()); - $this->assertEquals(2, $condition_group->count()); - $this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString()); - - // Nested condition group with multiple conditions. - $condition_group = new ConditionGroup(); - $condition_group->addCondition('type', ['article', 'page']); - $nested_condition_group = new ConditionGroup('OR'); - $nested_condition_group->addCondition('uid', '1'); - $nested_condition_group->addCondition('status', '1'); - $condition_group->addCondition($nested_condition_group); - $expected_conditions = [ - new Condition('type', ['article', 'page']), - $nested_condition_group, - ]; - $expected_lines = [ - "(", - " type IN ['article', 'page']", - " AND", - " (", - " uid = '1'", - " OR", - " status = '1'", - " )", - ")", - ]; - $this->assertEquals($expected_conditions, $condition_group->getConditions()); - $this->assertEquals('AND', $condition_group->getConjunction()); - $this->assertEquals(2, $condition_group->count()); - $this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString()); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php deleted file mode 100644 index 3f8cd62e11d000d8345f0fa2aa906fd3b60e757e..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\Core\Cache\CacheableMetadata; -use Drupal\Core\Render\RenderContext; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; - -/** - * Tests the generic query access handler. - * - * @coversDefaultClass \Drupal\entity\QueryAccess\EventOnlyQueryAccessHandler - * @group entity - */ -class EventOnlyQueryAccessHandlerTest extends EntityKernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - 'node', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->installEntitySchema('node'); - - \Drupal::state()->set('test_event_only_query_access', TRUE); - } - - /** - * Tests cacheability with the event only query_access handler. - * - * If there is no additional cacheablility provided to the conditions, there - * should be no render conrexts leaked. - */ - public function testCacheableMetadataLeaks() { - $renderer = $this->container->get('renderer'); - $render_context = new RenderContext(); - - $node_type_storage = $this->entityTypeManager->getStorage('node_type'); - $node_type_storage->create(['type' => 'foo', 'name' => $this->randomString()])->save(); - - $node_storage = $this->entityTypeManager->getStorage('node'); - $node_1 = $node_storage->create(['type' => 'foo', 'title' => $this->randomString()]); - $node_1->save(); - $node_2 = $node_storage->create(['type' => 'bar', 'title' => $this->randomString()]); - $node_2->save(); - - $renderer->executeInRenderContext($render_context, static function () use ($node_storage) { - $node_storage->getQuery()->execute(); - }); - $this->assertTrue($render_context->isEmpty(), 'Empty cacheability was not bubbled.'); - - $cacheability = new CacheableMetadata(); - $cacheability->addCacheContexts(['user.permissions']); - \Drupal::state()->set('event_only_query_acccess_cacheability', $cacheability); - - $render_context = new RenderContext(); - $renderer->executeInRenderContext($render_context, static function () use ($node_storage) { - $node_storage->getQuery()->execute(); - }); - $this->assertFalse($render_context->isEmpty(), 'Cacheability was bubbled'); - $this->assertCount(1, $render_context); - $this->assertEquals(['user.permissions'], $render_context[0]->getCacheContexts()); - } - - /** - * Tests that entity types without a query access handler still fire events. - */ - public function testEventOnlyQueryAccessHandlerEventSubscriber() { - $node_type_storage = $this->entityTypeManager->getStorage('node_type'); - $node_type_storage->create(['type' => 'foo', 'name' => $this->randomString()])->save(); - $node_type_storage->create(['type' => 'bar', 'name' => $this->randomString()])->save(); - - $node_storage = $this->entityTypeManager->getStorage('node'); - $node_1 = $node_storage->create(['type' => 'foo', 'title' => $this->randomString()]); - $node_1->save(); - $node_2 = $node_storage->create(['type' => 'bar', 'title' => $this->randomString()]); - $node_2->save(); - - $unfiltered = $node_storage->getQuery()->accessCheck(FALSE)->execute(); - $this->assertCount(2, $unfiltered, 'Both nodes show up when access checking is turned off.'); - $this->assertArrayHasKey($node_1->id(), $unfiltered, 'foo nodes were not filtered out.'); - $this->assertArrayHasKey($node_2->id(), $unfiltered, 'bar nodes were not filtered out.'); - - $filtered = $node_storage->getQuery()->execute(); - $this->assertCount(1, $filtered, 'Only one node shows up when access checking is turned on.'); - $this->assertArrayHasKey($node_1->id(), $filtered, 'foo nodes were not filtered out.'); - $this->assertArrayNotHasKey($node_2->id(), $filtered, 'bar nodes were filtered out.'); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessEventTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessEventTest.php deleted file mode 100644 index d5a045c104cfc0b04923f74a63d262e66402d3a2..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessEventTest.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity\QueryAccess\QueryAccessHandler; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; - -/** - * Tests the query access event. - * - * @group entity - */ -class QueryAccessEventTest extends EntityKernelTestBase { - - /** - * The query access handler. - * - * @var \Drupal\entity\QueryAccess\QueryAccessHandler - */ - protected $handler; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('entity_test_enhanced'); - - // Create uid: 1 here so that it's skipped in test cases. - $admin_user = $this->createUser(); - - $entity_type_manager = $this->container->get('entity_type.manager'); - $entity_type = $entity_type_manager->getDefinition('entity_test_enhanced'); - $this->handler = QueryAccessHandler::createInstance($this->container, $entity_type); - } - - /** - * Tests the generic event. - */ - public function testGenericEvent() { - $entity_type_manager = $this->container->get('entity_type.manager'); - $entity_type = $entity_type_manager->getDefinition('entity_test_enhanced_with_owner'); - $handler = QueryAccessHandler::createInstance($this->container, $entity_type); - - $first_user = $this->createUser(['mail' => 'user9000@example.com']); - $conditions = $handler->getConditions('view', $first_user); - $this->assertTrue($conditions->isAlwaysFalse()); - - $second_user = $this->createUser(['mail' => 'user9001@example.com']); - $conditions = $handler->getConditions('view', $second_user); - $this->assertFalse($conditions->isAlwaysFalse()); - } - - /** - * Tests the event. - */ - public function testEvent() { - // By default, the first user should have full access, and the second - // user should have no access. The QueryAccessSubscriber flips that. - $first_user = $this->createUser(['mail' => 'user1@example.com'], ['administer entity_test_enhanced']); - $second_user = $this->createUser(['mail' => 'user2@example.com']); - - $conditions = $this->handler->getConditions('view', $first_user); - $this->assertTrue($conditions->isAlwaysFalse()); - - $conditions = $this->handler->getConditions('view', $second_user); - $this->assertFalse($conditions->isAlwaysFalse()); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessHandlerTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessHandlerTest.php deleted file mode 100644 index a5a57b388a9e69b22d2c0d413a3af0583d972d4d..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessHandlerTest.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity\QueryAccess\Condition; -use Drupal\entity\QueryAccess\QueryAccessHandler; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; - -/** - * Tests the query access handler. - * - * Uses the "entity_test_enhanced" entity type, which has no owner. - * UncacheableQueryAccessHandlerTest uses the "entity_test_enhanced_with_owner" - * entity type, which has an owner. This ensures both sides (owner and - * no owner) are covered. - * - * @coversDefaultClass \Drupal\entity\QueryAccess\QueryAccessHandler - * @group entity - */ -class QueryAccessHandlerTest extends EntityKernelTestBase { - - /** - * The query access handler. - * - * @var \Drupal\entity\QueryAccess\QueryAccessHandler - */ - protected $handler; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('entity_test_enhanced'); - - // Create uid: 1 here so that it's skipped in test cases. - $admin_user = $this->createUser(); - - $entity_type_manager = $this->container->get('entity_type.manager'); - $entity_type = $entity_type_manager->getDefinition('entity_test_enhanced'); - $this->handler = QueryAccessHandler::createInstance($this->container, $entity_type); - } - - /** - * @covers ::getConditions - */ - public function testNoAccess() { - foreach (['view', 'update', 'duplicate', 'delete'] as $operation) { - $user = $this->createUser([], ['access content']); - $conditions = $this->handler->getConditions($operation, $user); - $this->assertEquals(0, $conditions->count()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertTrue($conditions->isAlwaysFalse()); - } - } - - /** - * @covers ::getConditions - */ - public function testAdmin() { - foreach (['view', 'update', 'duplicate', 'delete'] as $operation) { - $user = $this->createUser([], ['administer entity_test_enhanced']); - $conditions = $this->handler->getConditions($operation, $user); - $this->assertEquals(0, $conditions->count()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - } - - /** - * @covers ::getConditions - */ - public function testView() { - // Entity type permission. - $user = $this->createUser([], ['view entity_test_enhanced']); - $conditions = $this->handler->getConditions('view', $user); - $expected_conditions = [ - new Condition('status', '1'), - ]; - $this->assertEquals(1, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - - // Bundle permission. - $user = $this->createUser([], ['view first entity_test_enhanced']); - $conditions = $this->handler->getConditions('view', $user); - $expected_conditions = [ - new Condition('type', ['first']), - new Condition('status', '1'), - ]; - $this->assertEquals('AND', $conditions->getConjunction()); - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - - /** - * @covers ::getConditions - */ - public function testUpdateDuplicateDelete() { - foreach (['update', 'duplicate', 'delete'] as $operation) { - $user = $this->createUser([], [ - "$operation first entity_test_enhanced", - "$operation second entity_test_enhanced", - ]); - $conditions = $this->handler->getConditions($operation, $user); - $expected_conditions = [ - new Condition('type', ['first', 'second']), - ]; - $this->assertEquals('OR', $conditions->getConjunction()); - $this->assertEquals(1, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessTest.php deleted file mode 100644 index 9409f2c393dc18dd79351b622551ebf60e9f1bf6..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/QueryAccessTest.php +++ /dev/null @@ -1,375 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; -use Drupal\views\Tests\ViewResultAssertionTrait; -use Drupal\views\Views; - -/** - * Test query access filtering for EntityQuery and Views. - * - * @group entity - * - * @see \Drupal\entity\QueryAccess\QueryAccessHandler - * @see \Drupal\entity\QueryAccess\EntityQueryAlter - * @see \Drupal\entity\QueryAccess\ViewsQueryAlter - */ -class QueryAccessTest extends EntityKernelTestBase { - - use ViewResultAssertionTrait; - - /** - * The test entities. - * - * @var \Drupal\Core\Entity\ContentEntityInterface[] - */ - protected $entities; - - /** - * The entity_test_enhanced storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $storage; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - 'user', - 'views', - 'system', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('entity_test_enhanced'); - $this->installConfig(['entity_module_test']); - - // Create uid: 1 here so that it's skipped in test cases. - $admin_user = $this->createUser(); - - $first_entity = EnhancedEntity::create([ - 'type' => 'first', - 'label' => 'First', - 'status' => 1, - ]); - $first_entity->save(); - - $first_entity->set('name', 'First!'); - $first_entity->set('status', 0); - $first_entity->setNewRevision(TRUE); - $first_entity->save(); - - $second_entity = EnhancedEntity::create([ - 'type' => 'first', - 'label' => 'Second', - 'status' => 0, - ]); - $second_entity->save(); - - $second_entity->set('name', 'Second!'); - $second_entity->set('status', 1); - $second_entity->setNewRevision(TRUE); - $second_entity->save(); - - $third_entity = EnhancedEntity::create([ - 'type' => 'second', - 'label' => 'Third', - 'status' => 1, - ]); - $third_entity->save(); - - $third_entity->set('name', 'Third!'); - $third_entity->setNewRevision(TRUE); - $third_entity->save(); - - $this->entities = [$first_entity, $second_entity, $third_entity]; - $this->storage = $this->entityTypeManager->getStorage('entity_test_enhanced'); - } - - /** - * Tests EntityQuery filtering. - */ - public function testEntityQuery() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced']); - $this->container->get('current_user')->setAccount($admin_user); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->execute(); - $this->assertEmpty($result); - - // View (published-only). - $user = $this->createUser([], ['view entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // View $bundle (published-only). - $user = $this->createUser([], ['view first entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[1]->id(), - ], array_values($result)); - } - - /** - * Tests EntityQuery filtering when all revisions are queried. - */ - public function testEntityQueryWithRevisions() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced']); - $this->container->get('current_user')->setAccount($admin_user); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '2' => $this->entities[0]->id(), - '3' => $this->entities[1]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->execute(); - $this->assertEmpty($result); - - // View (published-only). - $user = $this->createUser([], ['view entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - - // View $bundle (published-only). - $user = $this->createUser([], ['view first entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '4' => $this->entities[1]->id(), - ], $result); - } - - /** - * Tests Views filtering. - */ - public function testViews() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced']); - $this->container->get('current_user')->setAccount($admin_user); - - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, []); - - // View (published-only). - $user = $this->createUser([], ['view entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - - // View $bundle (published-only). - $user = $this->createUser([], ['view first entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[1]->id()], - ], ['id' => 'id']); - } - - /** - * Tests Views filtering when all revisions are queried. - */ - public function testViewsWithRevisions() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced']); - $this->container->get('current_user')->setAccount($admin_user); - - $view = Views::getView('entity_test_enhanced_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '2', 'id' => $this->entities[0]->id()], - ['vid' => '3', 'id' => $this->entities[1]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, []); - - // View (published-only). - $user = $this->createUser([], ['view entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - - // View $bundle (published-only). - $user = $this->createUser([], ['view first entity_test_enhanced']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ], ['vid' => 'vid']); - } - - /** - * Tests no filtering when query access is disabled. - */ - public function testNoFiltering() { - // EntityQuery. - $result = $this->storage->getQuery()->sort('id')->accessCheck(FALSE)->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // Views. - $view = Views::getView('entity_test_enhanced'); - $display = $view->getDisplay(); - $display_options = $display->getOption('query'); - $display_options['options']['disable_sql_rewrite'] = TRUE; - $display->setOption('query', $display_options); - $view->save(); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - $view = Views::getView('entity_test_enhanced'); - $display = $view->getDisplay(); - $display_options['options']['disable_sql_rewrite'] = FALSE; - $display->setOption('query', $display_options); - $view->save(); - } - - /** - * Tests filtering based on a configurable field. - * - * QueryAccessSubscriber adds a condition that ensures that the field value - * is either empty or matches "marketing". - * - * @see \Drupal\entity_module_test\EventSubscriber\QueryAccessSubscriber - */ - public function testConfigurableField() { - $this->entities[0]->set('assigned', 'marketing'); - $this->entities[0]->save(); - // The field is case sensitive, so the third entity should be ignored. - $this->entities[2]->set('assigned', 'MarKeTing'); - $this->entities[2]->save(); - $user = $this->createUser([ - 'mail' => 'user3@example.com', - ], ['access content']); - $this->container->get('current_user')->setAccount($user); - - // EntityQuery. - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - $this->entities[1]->id(), - ], array_values($result)); - - // EntityQuery with revisions. - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '2' => $this->entities[0]->id(), - '3' => $this->entities[1]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - ], $result); - - // View. - $view = Views::getView('entity_test_enhanced'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ['id' => $this->entities[1]->id()], - ], ['id' => 'id']); - - // View with revisions. - $view = Views::getView('entity_test_enhanced_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '2', 'id' => $this->entities[0]->id()], - ['vid' => '3', 'id' => $this->entities[1]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessHandlerTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessHandlerTest.php deleted file mode 100644 index f23c8abb26426f81bb01929a87ef490383d5c2c4..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessHandlerTest.php +++ /dev/null @@ -1,185 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity\QueryAccess\Condition; -use Drupal\entity\QueryAccess\ConditionGroup; -use Drupal\entity\QueryAccess\UncacheableQueryAccessHandler; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; - -/** - * Tests the uncacheable query access handler. - * - * Uses the "entity_test_enhanced_with_owner" entity type, which has an owner. - * QueryAccessHandlerTest uses the "entity_test_enhanced" entity type, which - * has no owner. This ensures both sides (owner and no owner) are covered. - * - * @coversDefaultClass \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler - * @group entity - */ -class UncacheableQueryAccessHandlerTest extends EntityKernelTestBase { - - /** - * The query access handler. - * - * @var \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler - */ - protected $handler; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('entity_test_enhanced_with_owner'); - - // Create uid: 1 here so that it's skipped in test cases. - $admin_user = $this->createUser(); - - $entity_type_manager = $this->container->get('entity_type.manager'); - $entity_type = $entity_type_manager->getDefinition('entity_test_enhanced_with_owner'); - $this->handler = UncacheableQueryAccessHandler::createInstance($this->container, $entity_type); - } - - /** - * @covers ::getConditions - */ - public function testNoAccess() { - foreach (['view', 'update', 'delete'] as $operation) { - $user = $this->createUser([], ['access content']); - $conditions = $this->handler->getConditions($operation, $user); - $this->assertEquals(0, $conditions->count()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertTrue($conditions->isAlwaysFalse()); - } - } - - /** - * @covers ::getConditions - */ - public function testAdmin() { - foreach (['view', 'update', 'delete'] as $operation) { - $user = $this->createUser([], ['administer entity_test_enhanced_with_owner']); - $conditions = $this->handler->getConditions($operation, $user); - $this->assertEquals(0, $conditions->count()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - } - - /** - * @covers ::getConditions - */ - public function testView() { - // Any permission. - $user = $this->createUser([], ['view any entity_test_enhanced_with_owner']); - $conditions = $this->handler->getConditions('view', $user); - $expected_conditions = [ - new Condition('status', '1'), - ]; - $this->assertEquals(1, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - - // Own permission. - $user = $this->createUser([], ['view own entity_test_enhanced_with_owner']); - $conditions = $this->handler->getConditions('view', $user); - $expected_conditions = [ - new Condition('user_id', $user->id()), - new Condition('status', '1'), - ]; - $this->assertEquals('AND', $conditions->getConjunction()); - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - - // Any permission for the first bundle, own permission for the second. - $user = $this->createUser([], [ - 'view any first entity_test_enhanced_with_owner', - 'view own second entity_test_enhanced_with_owner', - ]); - $conditions = $this->handler->getConditions('view', $user); - $expected_conditions = [ - (new ConditionGroup('OR')) - ->addCacheContexts(['user', 'user.permissions']) - ->addCondition('type', ['first']) - ->addCondition((new ConditionGroup('AND')) - ->addCondition('user_id', $user->id()) - ->addCondition('type', ['second']) - ), - new Condition('status', '1'), - ]; - $this->assertEquals('AND', $conditions->getConjunction()); - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - - // View own unpublished permission. - $user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']); - $conditions = $this->handler->buildConditions('view', $user); - $expected_conditions = [ - new Condition('user_id', $user->id()), - new Condition('status', '0'), - ]; - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - - // Both view any and view own unpublished permissions. - $user = $this->createUser([], [ - 'view any entity_test_enhanced_with_owner', - 'view own unpublished entity_test_enhanced_with_owner', - ]); - $conditions = $this->handler->buildConditions('view', $user); - $expected_conditions = [ - new Condition('status', '1'), - (new ConditionGroup('AND')) - ->addCondition('user_id', $user->id()) - ->addCondition('status', '0') - ->addCacheContexts(['user']), - ]; - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - - /** - * @covers ::getConditions - */ - public function testUpdateDuplicateDelete() { - foreach (['update', 'duplicate', 'delete'] as $operation) { - // Any permission for the first bundle, own permission for the second. - $user = $this->createUser([], [ - "$operation any first entity_test_enhanced_with_owner", - "$operation own second entity_test_enhanced_with_owner", - ]); - $conditions = $this->handler->getConditions($operation, $user); - $expected_conditions = [ - new Condition('type', ['first']), - (new ConditionGroup('AND')) - ->addCondition('user_id', $user->id()) - ->addCondition('type', ['second']), - ]; - $this->assertEquals('OR', $conditions->getConjunction()); - $this->assertEquals(2, $conditions->count()); - $this->assertEquals($expected_conditions, $conditions->getConditions()); - $this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts()); - $this->assertFalse($conditions->isAlwaysFalse()); - } - } - -} diff --git a/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessTest.php b/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessTest.php deleted file mode 100644 index 3b784c1bfded05990dda7120bffab2cb152c042e..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/QueryAccess/UncacheableQueryAccessTest.php +++ /dev/null @@ -1,511 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel\QueryAccess; - -use Drupal\entity_module_test\Entity\EnhancedEntityWithOwner; -use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; -use Drupal\views\Tests\ViewResultAssertionTrait; -use Drupal\views\Views; - -/** - * Test uncacheable query access filtering for EntityQuery and Views. - * - * @group entity - * - * @see \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler - * @see \Drupal\entity\QueryAccess\EntityQueryAlter - * @see \Drupal\entity\QueryAccess\ViewsQueryAlter - */ -class UncacheableQueryAccessTest extends EntityKernelTestBase { - - use ViewResultAssertionTrait; - - /** - * The test entities. - * - * @var \Drupal\Core\Entity\ContentEntityInterface[] - */ - protected $entities; - - /** - * The entity_test_enhanced storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $storage; - - /** - * {@inheritdoc} - */ - public static $modules = [ - 'entity', - 'entity_module_test', - 'user', - 'views', - 'system', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('entity_test_enhanced_with_owner'); - $this->installConfig(['entity_module_test']); - - // Create uid: 1 here so that it's skipped in test cases. - $admin_user = $this->createUser(); - - $first_entity = EnhancedEntityWithOwner::create([ - 'type' => 'first', - 'name' => 'First', - 'status' => 1, - ]); - $first_entity->save(); - - $first_entity->set('name', 'First!'); - $first_entity->set('status', 0); - $first_entity->setNewRevision(TRUE); - $first_entity->save(); - - $second_entity = EnhancedEntityWithOwner::create([ - 'type' => 'first', - 'name' => 'Second', - 'status' => 0, - ]); - $second_entity->save(); - - $second_entity->set('name', 'Second!'); - $second_entity->set('status', 1); - $second_entity->setNewRevision(TRUE); - $second_entity->save(); - - $third_entity = EnhancedEntityWithOwner::create([ - 'type' => 'second', - 'name' => 'Third', - 'status' => 1, - ]); - $third_entity->save(); - - $third_entity->set('name', 'Third!'); - $third_entity->setNewRevision(TRUE); - $third_entity->save(); - - $this->entities = [$first_entity, $second_entity, $third_entity]; - $this->storage = $this->entityTypeManager->getStorage('entity_test_enhanced_with_owner'); - } - - /** - * Tests EntityQuery filtering. - */ - public function testEntityQuery() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($admin_user); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->execute(); - $this->assertEmpty($result); - - // View own (published-only). - $user = $this->createUser([], ['view own entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[1]->id(), - ], array_values($result)); - - // View any (published-only). - $user = $this->createUser([], ['view any entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // View own unpublished. - $user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - ], array_values($result)); - - // View own unpublished + view any (published-only). - $user = $this->createUser([], [ - 'view own unpublished entity_test_enhanced_with_owner', - 'view any entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[0]->id(), - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - - // View own $first_bundle + View any $second_bundle. - $user = $this->createUser([], [ - 'view own first entity_test_enhanced_with_owner', - 'view any second entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->sort('id')->execute(); - $this->assertEquals([ - $this->entities[1]->id(), - $this->entities[2]->id(), - ], array_values($result)); - } - - /** - * Tests EntityQuery filtering when all revisions are queried. - */ - public function testEntityQueryWithRevisions() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($admin_user); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '2' => $this->entities[0]->id(), - '3' => $this->entities[1]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->allRevisions()->execute(); - $this->assertEmpty($result); - - // View own (published-only). - $user = $this->createUser([], ['view own entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - // The user_id field is not revisionable, which means that updating it - // will modify both revisions for each entity. - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '4' => $this->entities[1]->id(), - ], $result); - - // View any (published-only). - $user = $this->createUser([], ['view any entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - - // View own unpublished. - $user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '2' => $this->entities[0]->id(), - '3' => $this->entities[1]->id(), - ], $result); - - // View own unpublished + view any (published-only). - $user = $this->createUser([], [ - 'view own unpublished entity_test_enhanced_with_owner', - 'view any entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '1' => $this->entities[0]->id(), - '2' => $this->entities[0]->id(), - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - - // View own $first_bundle + View any $second_bundle. - $user = $this->createUser([], [ - 'view own first entity_test_enhanced_with_owner', - 'view any second entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $result = $this->storage->getQuery()->allRevisions()->sort('id')->execute(); - $this->assertEquals([ - '4' => $this->entities[1]->id(), - '5' => $this->entities[2]->id(), - '6' => $this->entities[2]->id(), - ], $result); - } - - /** - * Tests Views filtering. - */ - public function testViews() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($admin_user); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, []); - - // View own (published-only). - $user = $this->createUser([], ['view own entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[1]->id()], - ], ['id' => 'id']); - - // View any (published-only). - $user = $this->createUser([], ['view any entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - - // View own unpublished. - $user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ], ['id' => 'id']); - - // View own unpublished + view any (published-only). - $user = $this->createUser([], [ - 'view own unpublished entity_test_enhanced_with_owner', - 'view any entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[0]->id()], - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - - // View own $first_bundle + View any $second_bundle. - $user = $this->createUser([], [ - 'view own first entity_test_enhanced_with_owner', - 'view any second entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['id' => $this->entities[1]->id()], - ['id' => $this->entities[2]->id()], - ], ['id' => 'id']); - } - - /** - * Tests Views filtering when all revisions are queried. - */ - public function testViewsWithRevisions() { - // Admin permission, full access. - $admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($admin_user); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '2', 'id' => $this->entities[0]->id()], - ['vid' => '3', 'id' => $this->entities[1]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - - // No view permissions, no access. - $user = $this->createUser([], ['access content']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, []); - - // View own (published-only). - $user = $this->createUser([], ['view own entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ], ['vid' => 'vid']); - - // View any (published-only). - $user = $this->createUser([], ['view any entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - - // View own unpublished. - $user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '2', 'id' => $this->entities[0]->id()], - ['vid' => '3', 'id' => $this->entities[1]->id()], - ], ['vid' => 'vid']); - - // View own unpublished + view any (published-only). - $user = $this->createUser([], [ - 'view own unpublished entity_test_enhanced_with_owner', - 'view any entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[0]->set('user_id', $user->id()); - $this->entities[0]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '1', 'id' => $this->entities[0]->id()], - ['vid' => '2', 'id' => $this->entities[0]->id()], - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - - // View own $first_bundle + View any $second_bundle. - $user = $this->createUser([], [ - 'view own first entity_test_enhanced_with_owner', - 'view any second entity_test_enhanced_with_owner', - ]); - $this->container->get('current_user')->setAccount($user); - - $this->entities[1]->set('user_id', $user->id()); - $this->entities[1]->save(); - - $view = Views::getView('entity_test_enhanced_with_owner_revisions'); - $view->execute(); - $this->assertIdenticalResultset($view, [ - ['vid' => '4', 'id' => $this->entities[1]->id()], - ['vid' => '5', 'id' => $this->entities[2]->id()], - ['vid' => '6', 'id' => $this->entities[2]->id()], - ], ['vid' => 'vid']); - } - -} diff --git a/web/modules/entity/tests/src/Kernel/RevisionBasicUITest.php b/web/modules/entity/tests/src/Kernel/RevisionBasicUITest.php deleted file mode 100644 index 754ec0b8c6704429b4a114b26f8140aa2ac17c61..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Kernel/RevisionBasicUITest.php +++ /dev/null @@ -1,201 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Kernel; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\KernelTests\KernelTestBase; -use Drupal\user\Entity\Role; -use Drupal\user\Entity\User; -use Symfony\Component\HttpFoundation\Request; - -/** - * @group entity - */ -class RevisionBasicUITest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = ['entity_module_test', 'system', 'user', 'entity']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('user'); - $this->installEntitySchema('entity_test_enhanced'); - $this->installSchema('system', 'sequences'); - $this->installConfig(['system']); - - $this->container->get('router.builder')->rebuild(); - - // Create a test user so that the mock requests performed below have a valid - // current user context. - $user = User::create([ - // Make sure not to create user 1 which would bypass any access - // restrictions. - 'uid' => 2, - 'name' => 'Test user', - ]); - $user->save(); - $this->container->get('account_switcher')->switchTo($user); - } - - /** - * Tests the revision history controller. - */ - public function testRevisionHistory() { - $entity = EnhancedEntity::create([ - 'name' => 'rev 1', - 'type' => 'default', - ]); - $entity->save(); - - $revision = clone $entity; - $revision->name->value = 'rev 2'; - $revision->setNewRevision(TRUE); - $revision->isDefaultRevision(FALSE); - $revision->save(); - - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */ - $http_kernel = $this->container->get('http_kernel'); - $request = Request::create($revision->toUrl('version-history')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(403, $response->getStatusCode()); - - $role_admin = Role::create(['id' => 'test_role_admin']); - $role_admin->grantPermission('administer entity_test_enhanced'); - $role_admin->save(); - - $role = Role::create(['id' => 'test_role']); - $role->grantPermission('view all entity_test_enhanced revisions'); - $role->grantPermission('administer entity_test_enhanced'); - $role->save(); - - $user_admin = User::create([ - 'name' => 'Test administrator', - ]); - $user_admin->addRole($role_admin->id()); - $user_admin->save(); - $this->container->get('account_switcher')->switchTo($user_admin); - - $request = Request::create($revision->toUrl('version-history')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - - $user = User::create([ - 'name' => 'Test editor', - ]); - $user->addRole($role->id()); - $user->save(); - $this->container->get('account_switcher')->switchTo($user); - - $request = Request::create($revision->toUrl('version-history')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - - // This ensures that the default revision is still the first revision. - $this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1/revisions/2/view') !== FALSE); - $this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1') !== FALSE); - - // Publish a new revision. - $revision = clone $entity; - $revision->name->value = 'rev 3'; - $revision->setNewRevision(TRUE); - $revision->isDefaultRevision(TRUE); - $revision->save(); - - $request = Request::create($revision->toUrl('version-history')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - - // The first revision row should now include a revert link. - $this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1/revisions/1/revert') !== FALSE); - } - - public function testRevisionView() { - $entity = EnhancedEntity::create([ - 'name' => 'rev 1', - 'type' => 'default', - ]); - $entity->save(); - - $revision = clone $entity; - $revision->name->value = 'rev 2'; - $revision->setNewRevision(TRUE); - $revision->isDefaultRevision(FALSE); - $revision->save(); - - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */ - $http_kernel = $this->container->get('http_kernel'); - $request = Request::create($revision->toUrl('revision')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(403, $response->getStatusCode()); - - $role_admin = Role::create(['id' => 'test_role_admin']); - $role_admin->grantPermission('administer entity_test_enhanced'); - $role_admin->save(); - - $role = Role::create(['id' => 'test_role']); - $role->grantPermission('view all entity_test_enhanced revisions'); - $role->grantPermission('administer entity_test_enhanced'); - $role->save(); - - $user_admin = User::create([ - 'name' => 'Test administrator', - ]); - $user_admin->addRole($role_admin->id()); - $user_admin->save(); - $this->container->get('account_switcher')->switchTo($user_admin); - - $request = Request::create($revision->toUrl('version-history')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - - $user = User::create([ - 'name' => 'Test editor', - ]); - $user->addRole($role->id()); - $user->save(); - $this->container->get('account_switcher')->switchTo($user); - - $request = Request::create($revision->toUrl('revision')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertStringNotContainsString('rev 1', $response->getContent()); - $this->assertStringContainsString('rev 2', $response->getContent()); - } - - public function testRevisionRevert() { - $entity = EnhancedEntity::create([ - 'name' => 'rev 1', - 'type' => 'entity_test_enhance', - ]); - $entity->save(); - $entity->name->value = 'rev 2'; - $entity->setNewRevision(TRUE); - $entity->isDefaultRevision(TRUE); - $entity->save(); - - $role = Role::create(['id' => 'test_role']); - $role->grantPermission('administer entity_test_enhanced'); - $role->grantPermission('revert all entity_test_enhanced revisions'); - $role->save(); - - $user = User::create([ - 'name' => 'Test administrator', - ]); - $user->addRole($role->id()); - $user->save(); - $this->container->get('account_switcher')->switchTo($user); - - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */ - $http_kernel = $this->container->get('http_kernel'); - $request = Request::create($entity->toUrl('revision-revert-form')->toString()); - $response = $http_kernel->handle($request); - $this->assertEquals(200, $response->getStatusCode()); - } - -} diff --git a/web/modules/entity/tests/src/Unit/BundleEntityAccessControlHandlerTest.php b/web/modules/entity/tests/src/Unit/BundleEntityAccessControlHandlerTest.php deleted file mode 100644 index 0126d4465f4c32f769cd0324f3b7023bbf8dfd20..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/BundleEntityAccessControlHandlerTest.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit; - -use Drupal\Core\Cache\Context\CacheContextsManager; -use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\Language; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\entity\BundleEntityAccessControlHandler; -use Drupal\Tests\UnitTestCase; -use Prophecy\Argument; - -/** - * @coversDefaultClass \Drupal\entity\BundleEntityAccessControlHandler - * @group entity - */ -class BundleEntityAccessControlHandlerTest extends UnitTestCase { - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $module_handler = $this->prophesize(ModuleHandlerInterface::class); - $module_handler->invokeAll(Argument::any(), Argument::any())->willReturn([]); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens(Argument::any())->willReturn(TRUE); - - $container = new ContainerBuilder(); - $container->set('module_handler', $module_handler->reveal()); - $container->set('cache_contexts_manager', $cache_contexts_manager->reveal()); - \Drupal::setContainer($container); - } - - /** - * @covers ::checkAccess - * - * @dataProvider accessProvider - */ - public function testAccess(EntityInterface $entity, $operation, $account, $allowed) { - $handler = new BundleEntityAccessControlHandler($entity->getEntityType()); - $handler->setStringTranslation($this->getStringTranslationStub()); - $result = $handler->access($entity, $operation, $account); - $this->assertEquals($allowed, $result); - } - - /** - * Data provider for testAccess(). - * - * @return array - * A list of testAccess method arguments. - */ - public function accessProvider() { - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->id()->willReturn('green_entity_bundle'); - $entity_type->getBundleOf()->willReturn('green_entity'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type = $entity_type->reveal(); - - $entity = $this->prophesize(ConfigEntityInterface::class); - $entity->getEntityType()->willReturn($entity_type); - $entity->getEntityTypeId()->willReturn('green_entity_bundle'); - $entity->id()->willReturn('default'); - $entity->uuid()->willReturn('fake uuid'); - $entity->language()->willReturn(new Language(['id' => LanguageInterface::LANGCODE_NOT_SPECIFIED])); - - // User with no access. - $user = $this->buildMockUser(1, 'access content'); - $data[] = [$entity->reveal(), 'view label', $user->reveal(), FALSE]; - - // Permissions which grant "view label" access. - $permissions = [ - 'administer green_entity', - 'view green_entity', - 'view default green_entity', - 'view own green_entity', - 'view any green_entity', - 'view own default green_entity', - 'view any default green_entity', - ]; - foreach ($permissions as $index => $permission) { - $user = $this->buildMockUser(10 + $index, $permission); - $data[] = [$entity->reveal(), 'view label', $user->reveal(), TRUE]; - } - - return $data; - } - - /** - * Builds a mock user. - * - * @param int $uid - * The user ID. - * @param string $permission - * The permission to grant. - * - * @return \Prophecy\Prophecy\ObjectProphecy - * The user mock. - */ - protected function buildMockUser($uid, $permission) { - $account = $this->prophesize(AccountInterface::class); - $account->id()->willReturn($uid); - $account->hasPermission($permission)->willReturn(TRUE); - $account->hasPermission(Argument::any())->willReturn(FALSE); - - return $account; - } - -} diff --git a/web/modules/entity/tests/src/Unit/EntityAccessControlHandlerTest.php b/web/modules/entity/tests/src/Unit/EntityAccessControlHandlerTest.php deleted file mode 100644 index c516a169d2ccbd13c4a4e8837541fc3d93422a1e..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/EntityAccessControlHandlerTest.php +++ /dev/null @@ -1,252 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit; - -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\Context\CacheContextsManager; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\Language; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\entity\EntityAccessControlHandler; -use Drupal\entity\EntityPermissionProvider; -use Drupal\Tests\UnitTestCase; -use Drupal\user\EntityOwnerInterface; -use Prophecy\Argument; - -/** - * @coversDefaultClass \Drupal\entity\EntityAccessControlHandler - * @group entity - */ -class EntityAccessControlHandlerTest extends UnitTestCase { - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $module_handler = $this->prophesize(ModuleHandlerInterface::class); - $module_handler->invokeAll(Argument::any(), Argument::any())->willReturn([]); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens(Argument::any())->willReturn(TRUE); - - $container = new ContainerBuilder(); - $container->set('module_handler', $module_handler->reveal()); - $container->set('cache_contexts_manager', $cache_contexts_manager->reveal()); - \Drupal::setContainer($container); - } - - /** - * @covers ::checkAccess - * @covers ::checkEntityPermissions - * @covers ::checkEntityOwnerPermissions - * @covers ::checkCreateAccess - * - * @dataProvider accessProvider - */ - public function testAccess(EntityInterface $entity, $operation, $account, $allowed, $cache_contexts) { - $handler = new EntityAccessControlHandler($entity->getEntityType()); - $handler->setStringTranslation($this->getStringTranslationStub()); - $result = $handler->access($entity, $operation, $account, TRUE); - $this->assertEquals($allowed, $result->isAllowed()); - $this->assertEquals($cache_contexts, $result->getCacheContexts()); - } - - /** - * @covers ::checkCreateAccess - * - * @dataProvider createAccessProvider - */ - public function testCreateAccess(EntityTypeInterface $entity_type, $bundle, $account, $allowed, $cache_contexts) { - $handler = new EntityAccessControlHandler($entity_type); - $handler->setStringTranslation($this->getStringTranslationStub()); - $result = $handler->createAccess($bundle, $account, [], TRUE); - $this->assertEquals($allowed, $result->isAllowed()); - $this->assertEquals($cache_contexts, $result->getCacheContexts()); - } - - /** - * Data provider for testAccess(). - * - * @return array - * A list of testAccess method arguments. - */ - public function accessProvider() { - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasHandlerClass('permission_provider')->willReturn(TRUE); - $entity_type->getHandlerClass('permission_provider')->willReturn(EntityPermissionProvider::class); - $entity = $this->buildMockEntity($entity_type->reveal(), 6); - - $data = []; - // Admin permission. - $admin_user = $this->buildMockUser(5, 'administer green_entity'); - $data['admin user, view'] = [$entity->reveal(), 'view', $admin_user->reveal(), TRUE, ['user.permissions']]; - $data['admin user, update'] = [$entity->reveal(), 'update', $admin_user->reveal(), TRUE, ['user.permissions']]; - $data['admin user, duplicate'] = [$entity->reveal(), 'duplicate', $admin_user->reveal(), TRUE, ['user.permissions']]; - $data['admin user, delete'] = [$entity->reveal(), 'delete', $admin_user->reveal(), TRUE, ['user.permissions']]; - - // View, update, duplicate, delete permissions, entity without an owner. - $second_entity = $this->buildMockEntity($entity_type->reveal()); - foreach (['view', 'update', 'duplicate', 'delete'] as $operation) { - $first_user = $this->buildMockUser(6, $operation . ' green_entity'); - $second_user = $this->buildMockUser(7, 'access content'); - - $data["first user, $operation, entity without owner"] = [$second_entity->reveal(), $operation, $first_user->reveal(), TRUE, ['user.permissions']]; - $data["second user, $operation, entity without owner"] = [$second_entity->reveal(), $operation, $second_user->reveal(), FALSE, ['user.permissions']]; - } - - // Update, duplicate, and delete permissions. - foreach (['update', 'duplicate', 'delete'] as $operation) { - // Owner, non-owner, user with "any" permission. - $first_user = $this->buildMockUser(6, $operation . ' own green_entity'); - $second_user = $this->buildMockUser(7, $operation . ' own green_entity'); - $third_user = $this->buildMockUser(8, $operation . ' any green_entity'); - - $data["first user, $operation, entity with owner"] = [$entity->reveal(), $operation, $first_user->reveal(), TRUE, ['user', 'user.permissions']]; - $data["second user, $operation, entity with owner"] = [$entity->reveal(), $operation, $second_user->reveal(), FALSE, ['user', 'user.permissions']]; - $data["third user, $operation, entity with owner"] = [$entity->reveal(), $operation, $third_user->reveal(), TRUE, ['user.permissions']]; - } - - // View permissions. - $first_user = $this->buildMockUser(9, 'view green_entity'); - $second_user = $this->buildMockUser(10, 'view first green_entity'); - $third_user = $this->buildMockUser(14, 'view own unpublished green_entity'); - $fourth_user = $this->buildMockUser(14, 'access content'); - - $first_entity = $this->buildMockEntity($entity_type->reveal(), 1, 'first'); - $second_entity = $this->buildMockEntity($entity_type->reveal(), 1, 'second'); - $third_entity = $this->buildMockEntity($entity_type->reveal(), 14, 'first', FALSE); - - // The first user can view the two published entities. - $data['first user, view, first entity'] = [$first_entity->reveal(), 'view', $first_user->reveal(), TRUE, ['user.permissions']]; - $data['first user, view, second entity'] = [$second_entity->reveal(), 'view', $first_user->reveal(), TRUE, ['user.permissions']]; - $data['first user, view, third entity'] = [$third_entity->reveal(), 'view', $first_user->reveal(), FALSE, ['user']]; - - // The second user can only view published entities of bundle "first". - $data['second user, view, first entity'] = [$first_entity->reveal(), 'view', $second_user->reveal(), TRUE, ['user.permissions']]; - $data['second user, view, second entity'] = [$second_entity->reveal(), 'view', $second_user->reveal(), FALSE, ['user.permissions']]; - $data['second user, view, third entity'] = [$third_entity->reveal(), 'view', $second_user->reveal(), FALSE, ['user']]; - - // The third user can view their own unpublished entity. - $data['third user, view, first entity'] = [$first_entity->reveal(), 'view', $third_user->reveal(), FALSE, ['user.permissions']]; - $data['third user, view, second entity'] = [$second_entity->reveal(), 'view', $third_user->reveal(), FALSE, ['user.permissions']]; - $data['third user, view, third entity'] = [$third_entity->reveal(), 'view', $third_user->reveal(), TRUE, ['user', 'user.permissions']]; - - // The fourth user can't view anything. - $data['fourth user, view, first entity'] = [$first_entity->reveal(), 'view', $fourth_user->reveal(), FALSE, ['user.permissions']]; - $data['fourth user, view, second entity'] = [$second_entity->reveal(), 'view', $fourth_user->reveal(), FALSE, ['user.permissions']]; - $data['fourth user, view, third entity'] = [$third_entity->reveal(), 'view', $fourth_user->reveal(), FALSE, ['user', 'user.permissions']]; - - return $data; - } - - /** - * Data provider for testCreateAccess(). - * - * @return array - * A list of testCreateAccess method arguments. - */ - public function createAccessProvider() { - $data = []; - - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasHandlerClass('permission_provider')->willReturn(TRUE); - $entity_type->getHandlerClass('permission_provider')->willReturn(EntityPermissionProvider::class); - - // User with the admin permission. - $account = $this->buildMockUser('6', 'administer green_entity'); - $data['admin user'] = [$entity_type->reveal(), NULL, $account->reveal(), TRUE, ['user.permissions']]; - - // Ordinary user. - $account = $this->buildMockUser('6', 'create green_entity'); - $data['regular user'] = [$entity_type->reveal(), NULL, $account->reveal(), TRUE, ['user.permissions']]; - - // Ordinary user, entity with a bundle. - $account = $this->buildMockUser('6', 'create first_bundle green_entity'); - $data['regular user, entity with bundle'] = [$entity_type->reveal(), 'first_bundle', $account->reveal(), TRUE, ['user.permissions']]; - - // User with no permissions. - $account = $this->buildMockUser('6', 'access content'); - $data['user without permission'] = [$entity_type->reveal(), NULL, $account->reveal(), FALSE, ['user.permissions']]; - - return $data; - } - - /** - * Builds a mock entity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param string $owner_id - * The owner ID. - * @param string $bundle - * The bundle. - * @param bool $published - * Whether the entity is published. - * - * @return \Prophecy\Prophecy\ObjectProphecy - * The entity mock. - */ - protected function buildMockEntity(EntityTypeInterface $entity_type, $owner_id = NULL, $bundle = NULL, $published = NULL) { - $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED; - $entity = $this->prophesize(ContentEntityInterface::class); - if (isset($published)) { - $entity->willImplement(EntityPublishedInterface::class); - } - if ($owner_id) { - $entity->willImplement(EntityOwnerInterface::class); - } - if (isset($published)) { - $entity->isPublished()->willReturn($published); - } - if ($owner_id) { - $entity->getOwnerId()->willReturn($owner_id); - } - - $entity->bundle()->willReturn($bundle ?: $entity_type->id()); - $entity->isNew()->willReturn(FALSE); - $entity->uuid()->willReturn('fake uuid'); - $entity->id()->willReturn('fake id'); - $entity->getRevisionId()->willReturn(NULL); - $entity->language()->willReturn(new Language(['id' => $langcode])); - $entity->getEntityTypeId()->willReturn($entity_type->id()); - $entity->getEntityType()->willReturn($entity_type); - $entity->getCacheContexts()->willReturn([]); - $entity->getCacheTags()->willReturn([]); - $entity->getCacheMaxAge()->willReturn(Cache::PERMANENT); - - return $entity; - } - - /** - * Builds a mock user. - * - * @param int $uid - * The user ID. - * @param string $permission - * The permission to grant. - * - * @return \Prophecy\Prophecy\ObjectProphecy - * The user mock. - */ - protected function buildMockUser($uid, $permission) { - $account = $this->prophesize(AccountInterface::class); - $account->id()->willReturn($uid); - $account->hasPermission($permission)->willReturn(TRUE); - $account->hasPermission(Argument::any())->willReturn(FALSE); - - return $account; - } - -} diff --git a/web/modules/entity/tests/src/Unit/EntityPermissionProviderTest.php b/web/modules/entity/tests/src/Unit/EntityPermissionProviderTest.php deleted file mode 100644 index a339bf496262af4e6ee44fd24e641ae67889c2e0..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/EntityPermissionProviderTest.php +++ /dev/null @@ -1,204 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit; - -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\entity\EntityPermissionProvider; -use Drupal\Tests\UnitTestCase; -use Drupal\user\EntityOwnerInterface; - -/** - * @coversDefaultClass \Drupal\entity\EntityPermissionProvider - * @group entity - */ -class EntityPermissionProviderTest extends UnitTestCase { - - /** - * The entity permission provider. - * - * @var \Drupal\entity\EntityPermissionProviderInterface - */ - protected $permissionProvider; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $entity_type_bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class); - $entity_type_bundle_info->getBundleInfo('white_entity')->willReturn([ - 'first' => ['label' => 'First'], - 'second' => ['label' => 'Second'], - ]); - $entity_type_bundle_info->getBundleInfo('black_entity')->willReturn([ - 'third' => ['label' => 'Third'], - ]); - $entity_type_bundle_info->getBundleInfo('pink_entity')->willReturn([ - 'third' => ['label' => 'Third'], - ]); - $this->permissionProvider = new EntityPermissionProvider($entity_type_bundle_info->reveal()); - $this->permissionProvider->setStringTranslation($this->getStringTranslationStub()); - } - - /** - * @covers ::buildPermissions - * - * @dataProvider entityTypeProvider - */ - public function testBuildPermissions(EntityTypeInterface $entity_type, array $expected_permissions) { - $permissions = $this->permissionProvider->buildPermissions($entity_type); - $this->assertEquals(array_keys($expected_permissions), array_keys($permissions)); - foreach ($permissions as $name => $permission) { - $this->assertEquals('entity_module_test', $permission['provider']); - $this->assertEquals($expected_permissions[$name], $permission['title']); - } - } - - /** - * Data provider for testBuildPermissions(). - * - * @return array - * A list of testBuildPermissions method arguments. - */ - public function entityTypeProvider() { - $data = []; - // Content entity type. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getSingularLabel()->willReturn('green entity'); - $entity_type->getPluralLabel()->willReturn('green entities'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(FALSE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(FALSE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('entity_type'); - $expected_permissions = [ - 'administer green_entity' => 'Administer green entities', - 'create green_entity' => 'Create green entities', - 'update green_entity' => 'Update green entities', - 'duplicate green_entity' => 'Duplicate green entities', - 'delete green_entity' => 'Delete green entities', - 'view green_entity' => 'View green entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with owner. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('blue_entity'); - $entity_type->getSingularLabel()->willReturn('blue entity'); - $entity_type->getPluralLabel()->willReturn('blue entities'); - $entity_type->getAdminPermission()->willReturn('administer blue_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('entity_type'); - $expected_permissions = [ - 'administer blue_entity' => 'Administer blue entities', - 'access blue_entity overview' => 'Access the blue entities overview page', - 'create blue_entity' => 'Create blue entities', - 'update any blue_entity' => 'Update any blue entity', - 'update own blue_entity' => 'Update own blue entities', - 'duplicate any blue_entity' => 'Duplicate any blue entity', - 'duplicate own blue_entity' => 'Duplicate own blue entities', - 'delete any blue_entity' => 'Delete any blue entity', - 'delete own blue_entity' => 'Delete own blue entities', - 'view blue_entity' => 'View blue entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('white_entity'); - $entity_type->getSingularLabel()->willReturn('white entity'); - $entity_type->getPluralLabel()->willReturn('white entities'); - $entity_type->getAdminPermission()->willReturn('administer white_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(FALSE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer white_entity' => 'Administer white entities', - 'access white_entity overview' => 'Access the white entities overview page', - 'create first white_entity' => 'First: Create white entities', - 'update first white_entity' => 'First: Update white entities', - 'duplicate first white_entity' => 'First: Duplicate white entities', - 'delete first white_entity' => 'First: Delete white entities', - 'create second white_entity' => 'Second: Create white entities', - 'update second white_entity' => 'Second: Update white entities', - 'duplicate second white_entity' => 'Second: Duplicate white entities', - 'delete second white_entity' => 'Second: Delete white entities', - 'view white_entity' => 'View white entities', - 'view first white_entity' => 'First: View white entities', - 'view second white_entity' => 'Second: View white entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles and owner. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('black_entity'); - $entity_type->getSingularLabel()->willReturn('black entity'); - $entity_type->getPluralLabel()->willReturn('black entities'); - $entity_type->getAdminPermission()->willReturn('administer black_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer black_entity' => 'Administer black entities', - 'access black_entity overview' => 'Access the black entities overview page', - 'create third black_entity' => 'Third: Create black entities', - 'update any third black_entity' => 'Third: Update any black entity', - 'update own third black_entity' => 'Third: Update own black entities', - 'duplicate any third black_entity' => 'Third: Duplicate any black entity', - 'duplicate own third black_entity' => 'Third: Duplicate own black entities', - 'delete any third black_entity' => 'Third: Delete any black entity', - 'delete own third black_entity' => 'Third: Delete own black entities', - 'view black_entity' => 'View black entities', - 'view third black_entity' => 'Third: View black entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles and owner and entity published. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('pink_entity'); - $entity_type->getSingularLabel()->willReturn('pink entity'); - $entity_type->getPluralLabel()->willReturn('pink entities'); - $entity_type->getAdminPermission()->willReturn('administer pink_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(TRUE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer pink_entity' => 'Administer pink entities', - 'access pink_entity overview' => 'Access the pink entities overview page', - 'view own unpublished pink_entity' => 'View own unpublished pink entities', - 'create third pink_entity' => 'Third: Create pink entities', - 'update any third pink_entity' => 'Third: Update any pink entity', - 'update own third pink_entity' => 'Third: Update own pink entities', - 'duplicate any third pink_entity' => 'Third: Duplicate any pink entity', - 'duplicate own third pink_entity' => 'Third: Duplicate own pink entities', - 'delete any third pink_entity' => 'Third: Delete any pink entity', - 'delete own third pink_entity' => 'Third: Delete own pink entities', - 'view pink_entity' => 'View pink entities', - 'view third pink_entity' => 'Third: View pink entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - return $data; - } - -} diff --git a/web/modules/entity/tests/src/Unit/QueryAccess/ConditionTest.php b/web/modules/entity/tests/src/Unit/QueryAccess/ConditionTest.php deleted file mode 100644 index e67eef4bbe7c5324754385211f9fa4fad1dffb13..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/QueryAccess/ConditionTest.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit\QueryAccess; - -use Drupal\entity\QueryAccess\Condition; -use Drupal\Tests\UnitTestCase; - -/** - * @coversDefaultClass \Drupal\entity\QueryAccess\Condition - * @group entity - */ -class ConditionTest extends UnitTestCase { - - /** - * ::covers __construct. - */ - public function testInvalidOperator() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Unrecognized operator "INVALID".'); - new Condition('uid', '1', 'INVALID'); - } - - /** - * ::covers getField - * ::covers getValue - * ::covers getOperator - * ::covers __toString. - */ - public function testGetters() { - $condition = new Condition('uid', '2'); - $this->assertEquals('uid', $condition->getField()); - $this->assertEquals('2', $condition->getValue()); - $this->assertEquals('=', $condition->getOperator()); - $this->assertEquals("uid = '2'", $condition->__toString()); - - $condition = new Condition('type', ['article', 'page']); - $this->assertEquals('type', $condition->getField()); - $this->assertEquals(['article', 'page'], $condition->getValue()); - $this->assertEquals('IN', $condition->getOperator()); - $this->assertEquals("type IN ['article', 'page']", $condition->__toString()); - - $condition = new Condition('title', NULL, 'IS NULL'); - $this->assertEquals('title', $condition->getField()); - $this->assertEquals(NULL, $condition->getValue()); - $this->assertEquals('IS NULL', $condition->getOperator()); - $this->assertEquals("title IS NULL", $condition->__toString()); - } - -} diff --git a/web/modules/entity/tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php b/web/modules/entity/tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php deleted file mode 100644 index 15236aea2fc6819b074cd824ebc8e4ecb5e2b8a8..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php +++ /dev/null @@ -1,254 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit; - -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\Context\CacheContextsManager; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\Language; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\entity\UncacheableEntityAccessControlHandler; -use Drupal\entity\UncacheableEntityPermissionProvider; -use Drupal\Tests\UnitTestCase; -use Drupal\user\EntityOwnerInterface; -use Prophecy\Argument; - -/** - * @coversDefaultClass \Drupal\entity\UncacheableEntityAccessControlHandler - * @group entity - */ -class UncacheableEntityAccessControlHandlerTest extends UnitTestCase { - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $module_handler = $this->prophesize(ModuleHandlerInterface::class); - $module_handler->invokeAll(Argument::any(), Argument::any())->willReturn([]); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens(Argument::any())->willReturn(TRUE); - - $container = new ContainerBuilder(); - $container->set('module_handler', $module_handler->reveal()); - $container->set('cache_contexts_manager', $cache_contexts_manager->reveal()); - \Drupal::setContainer($container); - } - - /** - * @covers ::checkAccess - * @covers ::checkEntityPermissions - * @covers ::checkEntityOwnerPermissions - * @covers ::checkCreateAccess - * - * @dataProvider accessProvider - */ - public function testAccess(EntityInterface $entity, $operation, $account, $allowed) { - $handler = new UncacheableEntityAccessControlHandler($entity->getEntityType()); - $handler->setStringTranslation($this->getStringTranslationStub()); - $result = $handler->access($entity, $operation, $account); - $this->assertEquals($allowed, $result); - } - - /** - * @covers ::checkCreateAccess - * - * @dataProvider createAccessProvider - */ - public function testCreateAccess(EntityTypeInterface $entity_type, $bundle, $account, $allowed) { - $handler = new UncacheableEntityAccessControlHandler($entity_type); - $handler->setStringTranslation($this->getStringTranslationStub()); - $result = $handler->createAccess($bundle, $account); - $this->assertEquals($allowed, $result); - } - - /** - * Data provider for testAccess(). - * - * @return array - * A list of testAccess method arguments. - */ - public function accessProvider() { - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasHandlerClass('permission_provider')->willReturn(TRUE); - $entity_type->getHandlerClass('permission_provider')->willReturn(UncacheableEntityPermissionProvider::class); - $entity = $this->buildMockEntity($entity_type->reveal(), 6); - - $data = []; - // Admin permission. - $admin_user = $this->buildMockUser(5, 'administer green_entity'); - $data[] = [$entity->reveal(), 'view', $admin_user->reveal(), TRUE]; - $data[] = [$entity->reveal(), 'update', $admin_user->reveal(), TRUE]; - $data[] = [$entity->reveal(), 'duplicate', $admin_user->reveal(), TRUE]; - $data[] = [$entity->reveal(), 'delete', $admin_user->reveal(), TRUE]; - - // View, update, duplicate, delete permissions, entity without an owner. - $second_entity = $this->buildMockEntity($entity_type->reveal()); - foreach (['view', 'update', 'duplicate', 'delete'] as $operation) { - $first_user = $this->buildMockUser(6, $operation . ' green_entity'); - $second_user = $this->buildMockUser(7, 'access content'); - - $data[] = [$second_entity->reveal(), $operation, $first_user->reveal(), TRUE]; - $data[] = [$second_entity->reveal(), $operation, $second_user->reveal(), FALSE]; - } - - // View, update, duplicate, delete permissions. - foreach (['view', 'update', 'duplicate', 'delete'] as $operation) { - // Owner, non-owner, user with "any" permission. - $first_user = $this->buildMockUser(6, $operation . ' own green_entity'); - $second_user = $this->buildMockUser(7, $operation . ' own green_entity'); - $third_user = $this->buildMockUser(8, $operation . ' any green_entity'); - - $data[] = [$entity->reveal(), $operation, $first_user->reveal(), TRUE]; - $data[] = [$entity->reveal(), $operation, $second_user->reveal(), FALSE]; - $data[] = [$entity->reveal(), $operation, $third_user->reveal(), TRUE]; - } - - // Per bundle and unpublished view permissions. - $first_user = $this->buildMockUser(11, 'view any first green_entity'); - $second_user = $this->buildMockUser(12, 'view own first green_entity'); - $third_user = $this->buildMockUser(13, 'view own unpublished green_entity'); - - $first_entity = $this->buildMockEntity($entity_type->reveal(), 9999, 'first'); - $second_entity = $this->buildMockEntity($entity_type->reveal(), 12, 'first'); - $third_entity = $this->buildMockEntity($entity_type->reveal(), 9999, 'second'); - $fourth_entity = $this->buildMockEntity($entity_type->reveal(), 10, 'second'); - $fifth_entity = $this->buildMockEntity($entity_type->reveal(), 13, 'first', FALSE); - - // The first user can view the two entities of bundle "first". - $data[] = [$first_entity->reveal(), 'view', $first_user->reveal(), TRUE]; - $data[] = [$second_entity->reveal(), 'view', $first_user->reveal(), TRUE]; - $data[] = [$third_entity->reveal(), 'view', $first_user->reveal(), FALSE]; - $data[] = [$fourth_entity->reveal(), 'view', $first_user->reveal(), FALSE]; - $data[] = [$fifth_entity->reveal(), 'view', $first_user->reveal(), FALSE]; - - // The second user can view their own entity of bundle "first". - $data[] = [$first_entity->reveal(), 'view', $second_user->reveal(), FALSE]; - $data[] = [$second_entity->reveal(), 'view', $second_user->reveal(), TRUE]; - $data[] = [$third_entity->reveal(), 'view', $second_user->reveal(), FALSE]; - $data[] = [$fourth_entity->reveal(), 'view', $second_user->reveal(), FALSE]; - $data[] = [$fourth_entity->reveal(), 'view', $second_user->reveal(), FALSE]; - $data[] = [$fifth_entity->reveal(), 'view', $second_user->reveal(), FALSE]; - - // The third user can only view their own unpublished entity. - $data[] = [$first_entity->reveal(), 'view', $third_user->reveal(), FALSE]; - $data[] = [$second_entity->reveal(), 'view', $third_user->reveal(), FALSE]; - $data[] = [$third_entity->reveal(), 'view', $third_user->reveal(), FALSE]; - $data[] = [$fourth_entity->reveal(), 'view', $third_user->reveal(), FALSE]; - $data[] = [$fourth_entity->reveal(), 'view', $third_user->reveal(), FALSE]; - $data[] = [$fifth_entity->reveal(), 'view', $third_user->reveal(), TRUE]; - - return $data; - } - - /** - * Data provider for testCreateAccess(). - * - * @return array - * A list of testCreateAccess method arguments. - */ - public function createAccessProvider() { - $data = []; - - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasHandlerClass('permission_provider')->willReturn(TRUE); - $entity_type->getHandlerClass('permission_provider')->willReturn(UncacheableEntityPermissionProvider::class); - - // User with the admin permission. - $account = $this->buildMockUser('6', 'administer green_entity'); - $data[] = [$entity_type->reveal(), NULL, $account->reveal(), TRUE]; - - // Ordinary user. - $account = $this->buildMockUser('6', 'create green_entity'); - $data[] = [$entity_type->reveal(), NULL, $account->reveal(), TRUE]; - - // Ordinary user, entity with a bundle. - $account = $this->buildMockUser('6', 'create first_bundle green_entity'); - $data[] = [$entity_type->reveal(), 'first_bundle', $account->reveal(), TRUE]; - - // User with no permissions. - $account = $this->buildMockUser('6', 'access content'); - $data[] = [$entity_type->reveal(), NULL, $account->reveal(), FALSE]; - - return $data; - } - - /** - * Builds a mock entity. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * @param string $owner_id - * The owner ID. - * @param string $bundle - * The bundle. - * @param bool $published - * Whether the entity is published. - * - * @return \Prophecy\Prophecy\ObjectProphecy - * The entity mock. - */ - protected function buildMockEntity(EntityTypeInterface $entity_type, $owner_id = NULL, $bundle = NULL, $published = NULL) { - $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED; - $entity = $this->prophesize(ContentEntityInterface::class); - if (isset($published)) { - $entity->willImplement(EntityPublishedInterface::class); - } - if ($owner_id) { - $entity->willImplement(EntityOwnerInterface::class); - } - if (isset($published)) { - $entity->isPublished()->willReturn($published); - } - if ($owner_id) { - $entity->getOwnerId()->willReturn($owner_id); - } - - $entity->bundle()->willReturn($bundle ?: $entity_type->id()); - $entity->isNew()->willReturn(FALSE); - $entity->uuid()->willReturn('fake uuid'); - $entity->id()->willReturn('fake id'); - $entity->getRevisionId()->willReturn(NULL); - $entity->language()->willReturn(new Language(['id' => $langcode])); - $entity->getEntityTypeId()->willReturn($entity_type->id()); - $entity->getEntityType()->willReturn($entity_type); - $entity->getCacheContexts()->willReturn([]); - $entity->getCacheTags()->willReturn([]); - $entity->getCacheMaxAge()->willReturn(Cache::PERMANENT); - - return $entity; - } - - /** - * Builds a mock user. - * - * @param int $uid - * The user ID. - * @param string $permission - * The permission to grant. - * - * @return \Prophecy\Prophecy\ObjectProphecy - * The user mock. - */ - protected function buildMockUser($uid, $permission) { - $account = $this->prophesize(AccountInterface::class); - $account->id()->willReturn($uid); - $account->hasPermission($permission)->willReturn(TRUE); - $account->hasPermission(Argument::any())->willReturn(FALSE); - - return $account; - } - -} diff --git a/web/modules/entity/tests/src/Unit/UncacheableEntityPermissionProviderTest.php b/web/modules/entity/tests/src/Unit/UncacheableEntityPermissionProviderTest.php deleted file mode 100644 index dc78ea20b410158a013e6d4d1ad200756f4a8426..0000000000000000000000000000000000000000 --- a/web/modules/entity/tests/src/Unit/UncacheableEntityPermissionProviderTest.php +++ /dev/null @@ -1,209 +0,0 @@ -<?php - -namespace Drupal\Tests\entity\Unit; - -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Entity\EntityPublishedInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\entity\UncacheableEntityPermissionProvider; -use Drupal\Tests\UnitTestCase; -use Drupal\user\EntityOwnerInterface; - -/** - * @coversDefaultClass \Drupal\entity\UncacheableEntityPermissionProvider - * @group entity - */ -class UncacheableEntityPermissionProviderTest extends UnitTestCase { - - /** - * The entity permission provider. - * - * @var \Drupal\entity\EntityPermissionProviderInterface - */ - protected $permissionProvider; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $entity_type_bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class); - $entity_type_bundle_info->getBundleInfo('white_entity')->willReturn([ - 'first' => ['label' => 'First'], - 'second' => ['label' => 'Second'], - ]); - $entity_type_bundle_info->getBundleInfo('black_entity')->willReturn([ - 'third' => ['label' => 'Third'], - ]); - $entity_type_bundle_info->getBundleInfo('pink_entity')->willReturn([ - 'third' => ['label' => 'Third'], - ]); - $this->permissionProvider = new UncacheableEntityPermissionProvider($entity_type_bundle_info->reveal()); - $this->permissionProvider->setStringTranslation($this->getStringTranslationStub()); - } - - /** - * @covers ::buildPermissions - * - * @dataProvider entityTypeProvider - */ - public function testBuildPermissions(EntityTypeInterface $entity_type, array $expected_permissions) { - $permissions = $this->permissionProvider->buildPermissions($entity_type); - $this->assertEquals(array_keys($expected_permissions), array_keys($permissions)); - foreach ($permissions as $name => $permission) { - $this->assertEquals('entity_module_test', $permission['provider']); - $this->assertEquals($expected_permissions[$name], $permission['title']); - } - } - - /** - * Data provider for testBuildPermissions(). - * - * @return array - * A list of testBuildPermissions method arguments. - */ - public function entityTypeProvider() { - $data = []; - // Content entity type. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('green_entity'); - $entity_type->getSingularLabel()->willReturn('green entity'); - $entity_type->getPluralLabel()->willReturn('green entities'); - $entity_type->getAdminPermission()->willReturn('administer green_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(FALSE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(FALSE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('entity_type'); - $expected_permissions = [ - 'administer green_entity' => 'Administer green entities', - 'create green_entity' => 'Create green entities', - 'update green_entity' => 'Update green entities', - 'duplicate green_entity' => 'Duplicate green entities', - 'delete green_entity' => 'Delete green entities', - 'view green_entity' => 'View green entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with owner. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('blue_entity'); - $entity_type->getSingularLabel()->willReturn('blue entity'); - $entity_type->getPluralLabel()->willReturn('blue entities'); - $entity_type->getAdminPermission()->willReturn('administer blue_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('entity_type'); - $expected_permissions = [ - 'administer blue_entity' => 'Administer blue entities', - 'access blue_entity overview' => 'Access the blue entities overview page', - 'create blue_entity' => 'Create blue entities', - 'update any blue_entity' => 'Update any blue entity', - 'update own blue_entity' => 'Update own blue entities', - 'duplicate any blue_entity' => 'Duplicate any blue entity', - 'duplicate own blue_entity' => 'Duplicate own blue entities', - 'delete any blue_entity' => 'Delete any blue entity', - 'delete own blue_entity' => 'Delete own blue entities', - 'view any blue_entity' => 'View any blue entities', - 'view own blue_entity' => 'View own blue entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('white_entity'); - $entity_type->getSingularLabel()->willReturn('white entity'); - $entity_type->getPluralLabel()->willReturn('white entities'); - $entity_type->getAdminPermission()->willReturn('administer white_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(FALSE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer white_entity' => 'Administer white entities', - 'access white_entity overview' => 'Access the white entities overview page', - 'create first white_entity' => 'First: Create white entities', - 'update first white_entity' => 'First: Update white entities', - 'duplicate first white_entity' => 'First: Duplicate white entities', - 'delete first white_entity' => 'First: Delete white entities', - 'create second white_entity' => 'Second: Create white entities', - 'update second white_entity' => 'Second: Update white entities', - 'duplicate second white_entity' => 'Second: Duplicate white entities', - 'delete second white_entity' => 'Second: Delete white entities', - 'view white_entity' => 'View white entities', - 'view first white_entity' => 'First: View white entities', - 'view second white_entity' => 'Second: View white entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles and owner. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('black_entity'); - $entity_type->getSingularLabel()->willReturn('black entity'); - $entity_type->getAdminPermission()->willReturn('administer black_entity'); - $entity_type->getPluralLabel()->willReturn('black entities'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(FALSE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer black_entity' => 'Administer black entities', - 'access black_entity overview' => 'Access the black entities overview page', - 'create third black_entity' => 'Third: Create black entities', - 'update any third black_entity' => 'Third: Update any black entity', - 'update own third black_entity' => 'Third: Update own black entities', - 'duplicate any third black_entity' => 'Third: Duplicate any black entity', - 'duplicate own third black_entity' => 'Third: Duplicate own black entities', - 'delete any third black_entity' => 'Third: Delete any black entity', - 'delete own third black_entity' => 'Third: Delete own black entities', - 'view any black_entity' => 'View any black entities', - 'view own black_entity' => 'View own black entities', - 'view any third black_entity' => 'Third: View any black entities', - 'view own third black_entity' => 'Third: View own black entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - // Content entity type with bundles and owner and entity published. - $entity_type = $this->prophesize(ContentEntityTypeInterface::class); - $entity_type->getProvider()->willReturn('entity_module_test'); - $entity_type->id()->willReturn('pink_entity'); - $entity_type->getSingularLabel()->willReturn('pink entity'); - $entity_type->getPluralLabel()->willReturn('pink entities'); - $entity_type->getAdminPermission()->willReturn('administer pink_entity'); - $entity_type->hasLinkTemplate('collection')->willReturn(TRUE); - $entity_type->hasLinkTemplate('duplicate-form')->willReturn(TRUE); - $entity_type->entityClassImplements(EntityOwnerInterface::class)->willReturn(TRUE); - $entity_type->entityClassImplements(EntityPublishedInterface::class)->willReturn(TRUE); - $entity_type->getPermissionGranularity()->willReturn('bundle'); - $expected_permissions = [ - 'administer pink_entity' => 'Administer pink entities', - 'access pink_entity overview' => 'Access the pink entities overview page', - 'view own unpublished pink_entity' => 'View own unpublished pink entities', - 'create third pink_entity' => 'Third: Create pink entities', - 'update any third pink_entity' => 'Third: Update any pink entity', - 'update own third pink_entity' => 'Third: Update own pink entities', - 'duplicate any third pink_entity' => 'Third: Duplicate any pink entity', - 'duplicate own third pink_entity' => 'Third: Duplicate own pink entities', - 'delete any third pink_entity' => 'Third: Delete any pink entity', - 'delete own third pink_entity' => 'Third: Delete own pink entities', - 'view any pink_entity' => 'View any pink entities', - 'view own pink_entity' => 'View own pink entities', - 'view any third pink_entity' => 'Third: View any pink entities', - 'view own third pink_entity' => 'Third: View own pink entities', - ]; - $data[] = [$entity_type->reveal(), $expected_permissions]; - - return $data; - } - -}