Snippets
Oleksiy Kalinichenko Custom fix for "Allow profiles to define a base/parent profile and load them in the correct order" based on https://www.drupal.org/node/1356276 for Drupal 8.6 and 8.7
Created by
Oleksiy Kalinichenko
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 | diff --git a/core/core.services.yml b/core/core.services.yml
index eb562afea7..3bce00bfcd 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -304,7 +304,7 @@ services:
- { name: event_subscriber }
config.installer:
class: Drupal\Core\Config\ConfigInstaller
- arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.manager', '@event_dispatcher', '%install_profile%']
+ arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.manager', '@event_dispatcher', '%install_profile%', '@extension.list.profile']
lazy: true
config.storage:
class: Drupal\Core\Config\CachedStorage
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index aed688d8be..89ed327d95 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -474,6 +474,12 @@ function install_begin_request($class_loader, &$install_state) {
if (isset($install_state['profile_info']['distribution']['install']['theme'])) {
$install_state['theme'] = $install_state['profile_info']['distribution']['install']['theme'];
}
+ // Ensure all profile directories are registered.
+ $profiles = \Drupal::service('extension.list.profile')->getAncestors($profile);
+ $profile_directories = array_map(function($extension) {
+ return $extension->getPath();
+ }, $profiles);
+ $listing->setProfileDirectories($profile_directories);
}
// Before having installed the system module and being able to do a module
@@ -1283,7 +1289,9 @@ function install_select_profile(&$install_state) {
* - For interactive installations via request query parameters.
* - For non-interactive installations via install_drupal() settings.
* - One of the available profiles is a distribution. If multiple profiles are
- * distributions, then the first discovered profile will be selected.
+ * distributions, then the first discovered profile will be selected. If an
+ * inherited profile is detected that is a distribution, it will be chosen
+ * over its base profile.
* - Only one visible profile is available.
*
* @param array $install_state
@@ -1308,12 +1316,9 @@ function _install_select_profile(&$install_state) {
return $profile;
}
}
- // If any of the profiles are distribution profiles, return the first one.
- foreach ($install_state['profiles'] as $profile) {
- $profile_info = install_profile_info($profile->getName());
- if (!empty($profile_info['distribution'])) {
- return $profile->getName();
- }
+ // Check for a distribution profile.
+ if ($distribution = \Drupal::service('extension.list.profile')->selectDistribution(array_keys($install_state['profiles']))) {
+ return $distribution;
}
// Get all visible (not hidden) profiles.
$visible_profiles = array_filter($install_state['profiles'], function ($profile) {
@@ -1660,7 +1665,10 @@ function install_profile_themes(&$install_state) {
* An array of information about the current installation state.
*/
function install_install_profile(&$install_state) {
- \Drupal::service('module_installer')->install([drupal_get_profile()], FALSE);
+ // Install all the profiles.
+ $profiles = \Drupal::service('extension.list.profile')->getAncestors();
+ \Drupal::service('module_installer')->install(array_keys($profiles), FALSE);
+
// Install all available optional config. During installation the module order
// is determined by dependencies. If there are no dependencies between modules
// then the order in which they are installed is dependent on random factors
diff --git a/core/includes/install.inc b/core/includes/install.inc
index 03dea88c33..f4292b79f0 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -566,7 +566,6 @@ function install_ensure_config_directory($type) {
* The list of modules to install.
*/
function drupal_verify_profile($install_state) {
- $profile = $install_state['parameters']['profile'];
$info = $install_state['profile_info'];
// Get the list of available modules for the selected installation profile.
@@ -575,10 +574,11 @@ function drupal_verify_profile($install_state) {
foreach ($listing->scan('module') as $present_module) {
$present_modules[] = $present_module->getName();
}
-
- // The installation profile is also a module, which needs to be installed
- // after all the other dependencies have been installed.
- $present_modules[] = $profile;
+ // Get the list of available profiles, which may be used as base profiles or
+ // ancestors of the selected installation profile.
+ foreach ($listing->scan('profile') as $present_profile) {
+ $present_modules[] = $present_profile->getName();
+ }
// Verify that all of the profile's required modules are present.
$missing_modules = array_diff($info['install'], $present_modules);
@@ -1079,6 +1079,9 @@ function drupal_check_module($module) {
* Drupal's default installer theme.
* - finish_url: A destination to visit after the installation of the
* distribution is finished
+ * - base profile: The shortname of the base installation profile. Existence of
+ * this key denotes that the installation profile depends on a parent
+ * installation profile.
*
* Note that this function does an expensive file system scan to get info file
* information for dependencies. If you only need information from the info
@@ -1105,20 +1108,9 @@ function install_profile_info($profile, $langcode = 'en') {
$cache = &drupal_static(__FUNCTION__, []);
if (!isset($cache[$profile][$langcode])) {
- // Set defaults for module info.
- $defaults = [
- 'dependencies' => [],
- 'install' => [],
- 'themes' => ['stark'],
- 'description' => '',
- 'version' => NULL,
- 'hidden' => FALSE,
- 'php' => DRUPAL_MINIMUM_PHP,
- 'config_install_path' => NULL,
- ];
$profile_path = drupal_get_path('profile', $profile);
- $info = \Drupal::service('info_parser')->parse("$profile_path/$profile.info.yml");
- $info += $defaults;
+ $info = \Drupal::service('extension.list.profile')->getExtensionInfo($profile);
+ $ancestors = \Drupal::service('extension.list.profile')->getAncestors($profile);
// Convert dependencies in [project:module] format.
$info['dependencies'] = array_map(function ($dependency) {
@@ -1140,6 +1132,9 @@ function install_profile_info($profile, $langcode = 'en') {
// remove any duplicates.
$info['install'] = array_unique(array_merge($info['install'], $required, $info['dependencies'], $locale));
+ // Remove the base profiles from the install list.
+ $info['install'] = array_diff($info['install'], array_keys($ancestors));
+
// If the profile has a config/sync directory use that to install drupal.
if (is_dir($profile_path . '/config/sync')) {
$info['config_install_path'] = $profile_path . '/config/sync';
diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php
index 4a198a7252..383b47936e 100644
--- a/core/lib/Drupal/Core/Config/ConfigInstaller.php
+++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php
@@ -4,6 +4,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\Entity\ConfigDependencyManager;
+use Drupal\Core\Extension\ProfileExtensionList;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ConfigInstaller implements ConfigInstallerInterface {
@@ -50,6 +51,13 @@ class ConfigInstaller implements ConfigInstallerInterface {
*/
protected $sourceStorage;
+ /**
+ * The profile list.
+ *
+ * @var \Drupal\Core\Extension\ProfileExtensionList
+ */
+ protected $profileList;
+
/**
* Is configuration being created as part of a configuration sync.
*
@@ -79,14 +87,17 @@ class ConfigInstaller implements ConfigInstallerInterface {
* The event dispatcher.
* @param string $install_profile
* The name of the currently active installation profile.
+ * @param \Drupal\Core\Extension\ProfileExtensionList|null $profile_list
+ * (optional) The profile list.
*/
- public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, $install_profile) {
+ public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, $install_profile, ProfileExtensionList $profile_list = NULL) {
$this->configFactory = $config_factory;
$this->activeStorages[$active_storage->getCollectionName()] = $active_storage;
$this->typedConfig = $typed_config;
$this->configManager = $config_manager;
$this->eventDispatcher = $event_dispatcher;
$this->installProfile = $install_profile;
+ $this->profileList = $profile_list ?: \Drupal::service('extension.list.profile');
}
/**
@@ -487,7 +498,8 @@ public function checkConfigurationToInstall($type, $name) {
// Install profiles can not have config clashes. Configuration that
// has the same name as a module's configuration will be used instead.
- if ($name != $this->drupalGetProfile()) {
+ $profiles = $this->profileList->getAncestors($this->installProfile);
+ if (!isset($profiles[$name])) {
// Throw an exception if the module being installed contains configuration
// that already exists. Additionally, can not continue installing more
// modules because those may depend on the current module being installed.
diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
index 9103ab8c07..430e3546a9 100644
--- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
+++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
@@ -3,6 +3,8 @@
namespace Drupal\Core\Config;
use Drupal\Core\Extension\ExtensionDiscovery;
+use Drupal\Core\Extension\ProfileExtensionList;
+use Drupal\Core\Extension\ProfileHandlerInterface;
/**
* Storage to access configuration and schema in enabled extensions.
@@ -52,9 +54,11 @@ class ExtensionInstallStorage extends InstallStorage {
* (optional) The current installation profile. This parameter will be
* mandatory in Drupal 9.0.0. In Drupal 8.3.0 not providing this parameter
* will trigger a silenced deprecation warning.
+ * @param \Drupal\Core\Extension\ProfileExtensionList $profile_list
+ * (optional) The profile list.
*/
- public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE, $profile = NULL) {
- parent::__construct($directory, $collection);
+ public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE, $profile = NULL, ProfileExtensionList $profile_list = NULL) {
+ parent::__construct($directory, $collection, $profile_list);
$this->configStorage = $config_storage;
$this->includeProfile = $include_profile;
if (is_null($profile)) {
@@ -93,19 +97,11 @@ protected function getAllFolders() {
$extensions = $this->configStorage->read('core.extension');
// @todo Remove this scan as part of https://www.drupal.org/node/2186491
- $listing = new ExtensionDiscovery(\Drupal::root());
+ $listing = new ExtensionDiscovery(\Drupal::root(), TRUE, NULL, NULL, $this->profileList);
if (!empty($extensions['module'])) {
$modules = $extensions['module'];
// Remove the install profile as this is handled later.
unset($modules[$this->installProfile]);
- $profile_list = $listing->scan('profile');
- if ($this->installProfile && isset($profile_list[$this->installProfile])) {
- // Prime the drupal_get_filename() static cache with the profile info
- // file location so we can use drupal_get_path() on the active profile
- // during the module scan.
- // @todo Remove as part of https://www.drupal.org/node/2186491
- drupal_get_filename('profile', $this->installProfile, $profile_list[$this->installProfile]->getPathname());
- }
$module_list_scan = $listing->scan('module');
$module_list = [];
foreach (array_keys($modules) as $module) {
@@ -126,18 +122,11 @@ protected function getAllFolders() {
}
if ($this->includeProfile) {
- // The install profile can override module default configuration. We do
- // this by replacing the config file path from the module/theme with the
- // install profile version if there are any duplicates.
- if ($this->installProfile) {
- if (!isset($profile_list)) {
- $profile_list = $listing->scan('profile');
- }
- if (isset($profile_list[$this->installProfile])) {
- $profile_folders = $this->getComponentNames([$profile_list[$this->installProfile]]);
- $this->folders = $profile_folders + $this->folders;
- }
- }
+ // The install profile (and any parent profiles) can override module
+ // default configuration. We do this by replacing the config file path
+ // from the module/theme with the install profile version if there are
+ // any duplicates.
+ $this->folders += $this->getComponentNames($this->profileList->getAncestors($this->installProfile));
}
}
return $this->folders;
diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php
index c8d189e480..96a9898f05 100644
--- a/core/lib/Drupal/Core/Config/InstallStorage.php
+++ b/core/lib/Drupal/Core/Config/InstallStorage.php
@@ -4,6 +4,8 @@
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\Extension;
+use Drupal\Core\Extension\ProfileExtensionList;
+use Drupal\Core\Extension\ProfileHandlerInterface;
/**
* Storage used by the Drupal installer.
@@ -47,6 +49,13 @@ class InstallStorage extends FileStorage {
*/
protected $directory;
+ /**
+ * The profile list, used to find additional folders to scan for config.
+ *
+ * @var \Drupal\Core\Extension\ProfileExtensionList
+ */
+ protected $profileList;
+
/**
* Constructs an InstallStorage object.
*
@@ -56,9 +65,14 @@ class InstallStorage extends FileStorage {
* @param string $collection
* (optional) The collection to store configuration in. Defaults to the
* default collection.
+ * @param \Drupal\Core\Extension\ProfileExtensionList $profile_list
+ * (optional) The profile list.
*/
- public function __construct($directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION) {
+ public function __construct($directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, ProfileExtensionList $profile_list = NULL) {
parent::__construct($directory, $collection);
+ if (\Drupal::hasService('extension.list.profile')) {
+ $this->profileList = $profile_list ?: \Drupal::service('extension.list.profile');
+ }
}
/**
@@ -151,21 +165,12 @@ protected function getAllFolders() {
if (!isset($this->folders)) {
$this->folders = [];
$this->folders += $this->getCoreNames();
+ // Get dependent profiles and add the extension components.
+ $this->folders += $this->getComponentNames($this->profileList->getAncestors());
// Perform an ExtensionDiscovery scan as we cannot use drupal_get_path()
// yet because the system module may not yet be enabled during install.
// @todo Remove as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root());
- if ($profile = drupal_get_profile()) {
- $profile_list = $listing->scan('profile');
- if (isset($profile_list[$profile])) {
- // Prime the drupal_get_filename() static cache with the profile info
- // file location so we can use drupal_get_path() on the active profile
- // during the module scan.
- // @todo Remove as part of https://www.drupal.org/node/2186491
- drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname());
- $this->folders += $this->getComponentNames([$profile_list[$profile]]);
- }
- }
// @todo Remove as part of https://www.drupal.org/node/2186491
$this->folders += $this->getComponentNames($listing->scan('module'));
$this->folders += $this->getComponentNames($listing->scan('theme'));
diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
index c0e3a4a2c8..f8234a450f 100644
--- a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
@@ -114,12 +114,18 @@ protected function validateModules(ConfigImporter $config_importer) {
$config_importer->logError($this->t('Unable to install the %module module since it does not exist.', ['%module' => $module]));
}
+ // Get a list of parent profiles and the main profile.
+ /* @var $profiles \Drupal\Core\Extension\Extension[] */
+ $profiles = \Drupal::service('extension.list.profile')->getAncestors();
+ /* @var $main_profile \Drupal\Core\Extension\Extension */
+ $main_profile = end($profiles);
+
// Ensure that all modules being installed have their dependencies met.
$installs = $config_importer->getExtensionChangelist('module', 'install');
foreach ($installs as $module) {
$missing_dependencies = [];
foreach (array_keys($module_data[$module]->requires) as $required_module) {
- if (!isset($core_extension['module'][$required_module])) {
+ if (!isset($core_extension['module'][$required_module]) && !array_key_exists($module, $profiles)) {
$missing_dependencies[] = $module_data[$required_module]->info['name'];
}
}
@@ -139,18 +145,44 @@ protected function validateModules(ConfigImporter $config_importer) {
$uninstalls = $config_importer->getExtensionChangelist('module', 'uninstall');
foreach ($uninstalls as $module) {
foreach (array_keys($module_data[$module]->required_by) as $dependent_module) {
- if ($module_data[$dependent_module]->status && !in_array($dependent_module, $uninstalls, TRUE) && $dependent_module !== $install_profile) {
- $module_name = $module_data[$module]->info['name'];
- $dependent_module_name = $module_data[$dependent_module]->info['name'];
- $config_importer->logError($this->t('Unable to uninstall the %module module since the %dependent_module module is installed.', ['%module' => $module_name, '%dependent_module' => $dependent_module_name]));
+ if ($module_data[$dependent_module]->status && !in_array($dependent_module, $uninstalls, TRUE)) {
+ if (!array_key_exists($dependent_module, $profiles)) {
+ $module_name = $module_data[$module]->info['name'];
+ $dependent_module_name = $module_data[$dependent_module]->info['name'];
+ $config_importer->logError($this->t('Unable to uninstall the %module module since the %dependent_module module is installed.', [
+ '%module' => $module_name,
+ '%dependent_module' => $dependent_module_name
+ ]));
+ }
}
}
}
- // Ensure that the install profile is not being uninstalled.
- if (in_array($install_profile, $uninstalls, TRUE)) {
- $profile_name = $module_data[$install_profile]->info['name'];
- $config_importer->logError($this->t('Unable to uninstall the %profile profile since it is the install profile.', ['%profile' => $profile_name]));
+ // Don't allow profiles to be uninstalled. It's possible for no profile to
+ // be set yet if the config is being imported during initial site install.
+ if ($main_profile instanceof \Drupal\Core\Extension\Extension) {
+ if (in_array($main_profile->getName(), $uninstalls, TRUE)) {
+ // Ensure that the active profile is not being uninstalled.
+ $profile_name = $main_profile->info['name'];
+ $config_importer->logError($this->t('Unable to uninstall the %profile profile since it is the main install profile.', ['%profile' => $profile_name]));
+ }
+ if ($profile_uninstalls = array_intersect_key($profiles, array_flip($uninstalls))) {
+ // Ensure that none of the parent profiles are being uninstalled.
+ $profile_names = [];
+ foreach ($profile_uninstalls as $profile) {
+ if ($profile->getName() !== $main_profile->getName()) {
+ $profile_names[] = $module_data[$profile->getName()]->info['name'];
+ }
+ }
+ if (!empty($profile_names)) {
+ $message = $this->formatPlural(count($profile_names),
+ 'Unable to uninstall the :profile profile since it is a parent of another installed profile.',
+ 'Unable to uninstall the :profile profiles since they are parents of another installed profile.',
+ [':profile' => implode(', ', $profile_names)]
+ );
+ $config_importer->logError($message);
+ }
+ }
}
}
diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
index 17c0e5b4a3..8fea6212ce 100644
--- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -91,6 +91,15 @@ class ExtensionDiscovery {
*/
protected $sitePath;
+ /**
+ * The profile list.
+ *
+ * Used to determine the directories in which we want to scan for modules.
+ *
+ * @var \Drupal\Core\Extension\ProfileExtensionList
+ */
+ protected $profileList;
+
/**
* Constructs a new ExtensionDiscovery object.
*
@@ -102,12 +111,24 @@ class ExtensionDiscovery {
* The available profile directories
* @param string $site_path
* The path to the site.
+ * @param \Drupal\Core\Extension\ProfileExtensionList|null $profile_list
+ * (optional) The profile list.
*/
- public function __construct($root, $use_file_cache = TRUE, $profile_directories = NULL, $site_path = NULL) {
+ public function __construct($root, $use_file_cache = TRUE, $profile_directories = NULL, $site_path = NULL, ProfileExtensionList $profile_list = NULL) {
$this->root = $root;
$this->fileCache = $use_file_cache ? FileCacheFactory::get('extension_discovery') : NULL;
$this->profileDirectories = $profile_directories;
$this->sitePath = $site_path;
+
+ // ExtensionDiscovery can be used without a service container
+ // (@drupalKernel::moduleData), so only use the profile list service if it
+ // is available to us.
+ if ($profile_list) {
+ $this->profileList = $profile_list;
+ }
+ elseif (\Drupal::hasService('extension.list.profile')) {
+ $this->profileList = \Drupal::service('extension.list.profile');
+ }
}
/**
@@ -241,7 +262,19 @@ public function setProfileDirectoriesFromSettings() {
// In case both profile directories contain the same extension, the actual
// profile always has precedence.
if ($profile) {
- $this->profileDirectories[] = drupal_get_path('profile', $profile);
+ if ($this->profileList) {
+ $profiles = $this->profileList->getAncestors($profile);
+ }
+ else {
+ $profiles = [
+ $profile => new Extension($this->root, 'profile', drupal_get_path('profile', $profile)),
+ ];
+ }
+
+ $profile_directories = array_map(function(Extension $extension) {
+ return $extension->getPath();
+ }, $profiles);
+ $this->profileDirectories = array_unique(array_merge($profile_directories, $this->profileDirectories));
}
return $this;
}
diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php
index 01fcf59095..f37f97e63f 100644
--- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php
+++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php
@@ -35,7 +35,7 @@ class ModuleExtensionList extends ExtensionList {
/**
* The profile list needed by this module list.
*
- * @var \Drupal\Core\Extension\ExtensionList
+ * @var \Drupal\Core\Extension\ProfileExtensionList
*/
protected $profileList;
@@ -56,14 +56,14 @@ class ModuleExtensionList extends ExtensionList {
* The state.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
- * @param \Drupal\Core\Extension\ExtensionList $profile_list
+ * @param \Drupal\Core\Extension\ProfileExtensionList $profile_list
* The site profile listing.
* @param string $install_profile
* The install profile used by the site.
* @param array[] $container_modules_info
* (optional) The module locations coming from the compiled container.
*/
- public function __construct($root, $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, ConfigFactoryInterface $config_factory, ExtensionList $profile_list, $install_profile, array $container_modules_info = []) {
+ public function __construct($root, $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, ConfigFactoryInterface $config_factory, ProfileExtensionList $profile_list, $install_profile, array $container_modules_info = []) {
parent::__construct($root, $type, $cache, $info_parser, $module_handler, $state, $install_profile);
$this->configFactory = $config_factory;
@@ -100,8 +100,7 @@ protected function getExtensionDiscovery() {
protected function getProfileDirectories(ExtensionDiscovery $discovery) {
$discovery->setProfileDirectories([]);
$all_profiles = $discovery->scan('profile');
- $active_profile = $all_profiles[$this->installProfile];
- $profiles = array_intersect_key($all_profiles, $this->configFactory->get('core.extension')->get('module') ?: [$active_profile->getName() => 0]);
+ $profiles = $this->profileList->getAncestors($this->installProfile);
// If a module is within a profile directory but specifies another
// profile for testing, it needs to be found in the parent profile.
@@ -139,13 +138,9 @@ protected function getActiveProfile() {
*/
protected function doScanExtensions() {
$extensions = parent::doScanExtensions();
-
- $profiles = $this->profileList->getList();
- // Modify the active profile object that was previously added to the module
- // list.
- if ($this->installProfile && isset($profiles[$this->installProfile])) {
- $extensions[$this->installProfile] = $profiles[$this->installProfile];
- }
+ // Merge in the install profile and any profile ancestors.
+ $profiles = $this->profileList->getAncestors($this->installProfile);
+ $extensions = array_merge($extensions, $profiles);
return $extensions;
}
diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
index 65466a2d65..96c0f1736f 100644
--- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -357,7 +357,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
return FALSE;
}
- // Skip already uninstalled modules.
+ // Skip already uninstalled modules and dependencies of profiles.
if (isset($installed_modules[$dependent]) && !isset($module_list[$dependent])) {
$module_list[$dependent] = $dependent;
}
diff --git a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php
index 4f73f9c9cb..4bcad55c1b 100644
--- a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php
+++ b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php
@@ -17,13 +17,172 @@ class ProfileExtensionList extends ExtensionList {
'package' => 'Other',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
+ 'themes' => ['stark'],
+ 'hidden' => FALSE,
+ 'base profile' => '',
];
+ /**
+ * {@inheritdoc}
+ */
+ public function getExtensionInfo($extension_name) {
+ $all_info = $this->getAllAvailableInfo();
+ if (isset($all_info[$extension_name])) {
+ return $all_info[$extension_name];
+ }
+ throw new \InvalidArgumentException("The {$this->type} $extension_name does not exist.");
+ }
+
+ /**
+ * Returns a list comprised of the profile, its parent profile if it has one,
+ * and any further ancestors.
+ *
+ * @param string $profile
+ * (optional) The name of profile. Defaults to the current install profile.
+ *
+ * @return \Drupal\Core\Extension\Extension[]
+ * An associative array of Extension objects, keyed by profile name in
+ * descending order of their dependencies (ancestors first). If the profile
+ * is not given and cannot be determined, returns an empty array.
+ */
+ public function getAncestors($profile = NULL) {
+ $ancestors = [];
+
+ if (empty($profile)) {
+ $profile = $this->installProfile ?: drupal_get_profile();
+ }
+ if (empty($profile)) {
+ return $ancestors;
+ }
+
+ $extension = $this->get($profile);
+
+ foreach (($extension->ancestors ?? []) as $ancestor) {
+ $ancestors[$ancestor] = $this->get($ancestor);
+ }
+ $ancestors[$profile] = $extension;
+
+ return $ancestors;
+ }
+
+ /**
+ * Returns all available profiles which are distributions.
+ *
+ * @return \Drupal\Core\Extension\Extension[]
+ * Processed extension objects, keyed by machine name.
+ */
+ public function listDistributions() {
+ return array_filter($this->getList(), function (Extension $profile) {
+ return !empty($profile->info['distribution']);
+ });
+ }
+
+ /**
+ * Select the install distribution from the list of profiles.
+ *
+ * If there are multiple profiles marked as distributions, select the first.
+ * If there is an inherited profile marked as a distribution, select it over
+ * its base profile.
+ *
+ * @param string[] $profiles
+ * List of profile names to search.
+ *
+ * @return string|null
+ * The selected distribution profile name, or NULL if none is found.
+ */
+ public function selectDistribution(array $profiles = NULL) {
+ $distributions = $this->listDistributions();
+
+ if ($profiles) {
+ $distributions = array_intersect_key($distributions, array_flip($profiles));
+ }
+
+ // Remove any distributions which are extended by another one.
+ foreach ($distributions as $profile_name => $profile) {
+ if (!empty($profile->info['base profile'])) {
+ $base_profile = $profile->info['base profile'];
+ unset($distributions[$base_profile]);
+ }
+ }
+
+ return key($distributions) ?: NULL;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doList() {
+ $profiles = parent::doList();
+
+ // Compute the ancestry of each profile before any further processing.
+ foreach ($profiles as $profile) {
+ // Maintain a list of profiles which depend on this one.
+ $profile->children = [];
+
+ // Maintain a list of profiles that this one depends on, in reverse
+ // ancestral order (immediate parent first).
+ $profile->ancestors = $this->computeAncestry($profiles, $profile);
+
+ // Give the profile a heavy weight to ensure that its hooks run last.
+ $profile->weight = count($profile->ancestors) + 1000;
+ }
+
+ // For each profile, merge in ancestors' module and theme lists.
+ foreach ($profiles as $profile_name => $profile) {
+ if (empty($profile->ancestors)) {
+ continue;
+ }
+ // Reference the extension info here for readability.
+ $info = &$profile->info;
+
+ // Add the parent profile as a hard dependency.
+ $info['dependencies'][] = reset($profile->ancestors);
+
+ // Add all themes and extensions listed by ancestors.
+ foreach ($profile->ancestors as $ancestor) {
+ $ancestor = $profiles[$ancestor];
+
+ // Add the current profile as a child of the ancestor.
+ $ancestor->children[] = $profile_name;
+ $info['install'] = array_merge($info['install'], $ancestor->info['install']);
+ $info['themes'] = array_merge($info['themes'], $ancestor->info['themes']);
+ // Add ancestor dependencies as our dependencies.
+ $info['dependencies'] = array_merge($info['dependencies'], $ancestor->info['dependencies']);
+ }
+ $info['dependencies'] = array_unique($info['dependencies']);
+ $info['install'] = array_unique($info['install']);
+ $info['themes'] = array_unique($info['themes']);
+ }
+ return $profiles;
+ }
+
+ /**
+ * Computes and returns the ancestral lineage of a profile.
+ *
+ * @param \Drupal\Core\Extension\Extension[] $profiles
+ * All discovered profiles.
+ * @param \Drupal\Core\Extension\Extension $profile
+ * The profile for which to compute the ancestry.
+ *
+ * @return string[]
+ * The names of the ancestors of the given profile, in order.
+ */
+ protected function computeAncestry(array $profiles, Extension $profile) {
+ $ancestors = [];
+
+ while (!empty($profile->info['base profile'])) {
+ array_unshift($ancestors, $profile->info['base profile']);
+ $profile = $profile->info['base profile'];
+ $profile = $profiles[$profile];
+ }
+ return $ancestors;
+ }
+
/**
* {@inheritdoc}
*/
protected function getInstalledExtensionNames() {
- return [$this->installProfile];
+ return array_keys($this->getAncestors());
}
}
diff --git a/core/lib/Drupal/Core/Installer/InstallerProfileExtensionList.php b/core/lib/Drupal/Core/Installer/InstallerProfileExtensionList.php
new file mode 100644
index 0000000000..d5c42adea3
--- /dev/null
+++ b/core/lib/Drupal/Core/Installer/InstallerProfileExtensionList.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\Core\Installer;
+
+use Drupal\Core\Extension\ProfileExtensionList;
+
+/**
+ * Overrides the profile extension list to have a static cache.
+ */
+class InstallerProfileExtensionList extends ProfileExtensionList {
+
+ /**
+ * Static version of the added file names during the installer.
+ *
+ * @var string[]
+ *
+ * @internal
+ */
+ protected static $staticAddedPathNames;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setPathname($extension_name, $pathname) {
+ parent::setPathname($extension_name, $pathname);
+
+ // In the early installer the container is rebuilt multiple times. Therefore
+ // we have to keep the added filenames across those rebuilds. This is not a
+ // final design, but rather just a workaround resolved at some point,
+ // hopefully.
+ // @todo Remove as part of https://drupal.org/project/drupal/issues/2934063
+ static::$staticAddedPathNames[$extension_name] = $pathname;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPathname($extension_name) {
+ if (isset($this->addedPathNames[$extension_name])) {
+ return $this->addedPathNames[$extension_name];
+ }
+ elseif (isset($this->pathNames[$extension_name])) {
+ return $this->pathNames[$extension_name];
+ }
+ elseif (isset(static::$staticAddedPathNames[$extension_name])) {
+ return static::$staticAddedPathNames[$extension_name];
+ }
+ elseif (($path_names = $this->getPathnames()) && isset($path_names[$extension_name])) {
+ // Ensure we don't have to do path scanning more than really needed.
+ foreach ($path_names as $extension => $path_name) {
+ static::$staticAddedPathNames[$extension] = $path_name;
+ }
+ return $path_names[$extension_name];
+ }
+ throw new \InvalidArgumentException("The {$this->type} $extension_name does not exist.");
+ }
+
+}
diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
index dd4ae5f470..e98aa3dcc8 100644
--- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
+++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
@@ -62,6 +62,7 @@ public function register(ContainerBuilder $container) {
// Use a performance optimised module extension list.
$container->getDefinition('extension.list.module')->setClass('Drupal\Core\Installer\InstallerModuleExtensionList');
+ $container->getDefinition('extension.list.profile')->setClass('Drupal\Core\Installer\InstallerProfileExtensionList');
}
/**
diff --git a/core/modules/config/tests/src/Functional/ConfigImportBaseInstallProfileTest.php b/core/modules/config/tests/src/Functional/ConfigImportBaseInstallProfileTest.php
new file mode 100644
index 0000000000..583c31153b
--- /dev/null
+++ b/core/modules/config/tests/src/Functional/ConfigImportBaseInstallProfileTest.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Drupal\Tests\config\Functional;
+
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests the importing/exporting configuration based on install sub-profile.
+ *
+ * @group config
+ */
+class ConfigImportBaseInstallProfileTest extends BrowserTestBase {
+
+ /**
+ * The profile to install as a basis for testing.
+ *
+ * @var string
+ */
+ protected $profile = 'testing_inherited';
+
+ /**
+ * A user with the 'synchronize configuration' permission.
+ *
+ * @var \Drupal\user\UserInterface
+ */
+ protected $webUser;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->webUser = $this->drupalCreateUser(['synchronize configuration']);
+ $this->drupalLogin($this->webUser);
+ $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
+ }
+
+ /**
+ * Tests config importer cannot uninstall parent install profiles and
+ * dependencies of parent profiles can be uninstalled.
+ *
+ * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber
+ */
+ public function testInstallParentProfileValidation() {
+ $sync = $this->container->get('config.storage.sync');
+ $this->copyConfig($this->container->get('config.storage'), $sync);
+ $core = $sync->read('core.extension');
+
+ // Ensure that parent profile can not be uninstalled.
+ unset($core['module']['testing']);
+ $sync->write('core.extension', $core);
+
+ $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
+ $this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
+ $this->assertText('Unable to uninstall the Testing profile since it is a parent of another installed profile.');
+
+ // Uninstall dependencies of parent profile.
+ $core['module']['testing'] = 0;
+ unset($core['module']['dynamic_page_cache']);
+ $sync->write('core.extension', $core);
+ $sync->deleteAll('dynamic_page_cache.');
+ $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
+ $this->assertText('The configuration was imported successfully.');
+ $this->rebuildContainer();
+ $this->assertFalse(\Drupal::moduleHandler()->moduleExists('dynamic_page_cache'), 'The dynamic_page_cache module has been uninstalled.');
+ }
+
+ /**
+ * Tests config importer cannot uninstall sub-profiles and dependencies of
+ * sub-profiles can be uninstalled.
+ *
+ * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber
+ */
+ public function testInstallSubProfileValidation() {
+ $sync = $this->container->get('config.storage.sync');
+ $this->copyConfig($this->container->get('config.storage'), $sync);
+ $core = $sync->read('core.extension');
+
+ // Ensure install sub-profiles can not be uninstalled.
+ unset($core['module']['testing_inherited']);
+ $sync->write('core.extension', $core);
+
+ $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
+ $this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
+ $this->assertText('Unable to uninstall the Testing Inherited profile since it is the main install profile.');
+
+ // Uninstall dependencies of main profile.
+ $core['module']['testing_inherited'] = 0;
+ unset($core['module']['syslog']);
+ $sync->write('core.extension', $core);
+ $sync->deleteAll('syslog.');
+ $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
+ $this->assertText('The configuration was imported successfully.');
+ $this->rebuildContainer();
+ $this->assertFalse(\Drupal::moduleHandler()->moduleExists('syslog'), 'The syslog module has been uninstalled.');
+ }
+
+}
diff --git a/core/modules/config/tests/src/Functional/ConfigImportInstallProfileTest.php b/core/modules/config/tests/src/Functional/ConfigImportInstallProfileTest.php
index 8b0787d6ee..d8d33da0e6 100644
--- a/core/modules/config/tests/src/Functional/ConfigImportInstallProfileTest.php
+++ b/core/modules/config/tests/src/Functional/ConfigImportInstallProfileTest.php
@@ -56,7 +56,7 @@ public function testInstallProfileValidation() {
$this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
$this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
- $this->assertText('Unable to uninstall the Testing config import profile since it is the install profile.');
+ $this->assertText('Unable to uninstall the Testing config import profile since it is the main install profile.');
// Uninstall dependencies of testing_config_import.
$core['module']['testing_config_import'] = 0;
diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php
index 841a741e44..8329d53bc5 100644
--- a/core/modules/system/src/Form/ModulesUninstallForm.php
+++ b/core/modules/system/src/Form/ModulesUninstallForm.php
@@ -116,10 +116,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
return $form;
}
+ $profiles = \Drupal::service('extension.list.profile')->getAncestors();
+
// Sort all modules by their name.
uasort($uninstallable, 'system_sort_modules_by_info_name');
$validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));
+ // Remove any profiles from the list.
+ $uninstallable = array_diff_key($uninstallable, $profiles);
+
$form['uninstall'] = ['#tree' => TRUE];
foreach ($uninstallable as $module_key => $module) {
$name = $module->info['name'] ?: $module->getName();
@@ -140,7 +145,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['uninstall'][$module->getName()]['#disabled'] = TRUE;
}
// All modules which depend on this one must be uninstalled first, before
- // we can allow this module to be uninstalled.
+ // we can allow this module to be uninstalled. (Installation profiles are
+ // excluded from this list.)
foreach (array_keys($module->required_by) as $dependent) {
if (drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
$name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent;
diff --git a/core/profiles/testing_inherited/config/install/block.block.stable_login.yml b/core/profiles/testing_inherited/config/install/block.block.stable_login.yml
new file mode 100644
index 0000000000..3650c6c41a
--- /dev/null
+++ b/core/profiles/testing_inherited/config/install/block.block.stable_login.yml
@@ -0,0 +1,19 @@
+langcode: en
+status: true
+dependencies:
+ module:
+ - user
+ theme:
+ - stable
+id: stable_login
+theme: stable
+region: sidebar_first
+weight: 0
+provider: null
+plugin: user_login_block
+settings:
+ id: user_login_block
+ label: 'User login'
+ provider: user
+ label_display: visible
+visibility: { }
diff --git a/core/profiles/testing_inherited/config/install/system.theme.yml b/core/profiles/testing_inherited/config/install/system.theme.yml
new file mode 100644
index 0000000000..67aeeeeac7
--- /dev/null
+++ b/core/profiles/testing_inherited/config/install/system.theme.yml
@@ -0,0 +1,2 @@
+# @todo: Remove this file in https://www.drupal.org/node/2352949
+default: stable
diff --git a/core/profiles/testing_inherited/modules/child_profile_module/child_profile_module.info.yml b/core/profiles/testing_inherited/modules/child_profile_module/child_profile_module.info.yml
new file mode 100644
index 0000000000..a3eec3e6df
--- /dev/null
+++ b/core/profiles/testing_inherited/modules/child_profile_module/child_profile_module.info.yml
@@ -0,0 +1,6 @@
+name: 'Child profile module'
+core: 8.x
+type: module
+description: 'A module contained in a child profile, for testing.'
+package: Testing
+version: VERSION
diff --git a/core/profiles/testing_inherited/modules/contrib/contrib_child_profile_module/contrib_child_profile_module.info.yml b/core/profiles/testing_inherited/modules/contrib/contrib_child_profile_module/contrib_child_profile_module.info.yml
new file mode 100644
index 0000000000..8eb63b3597
--- /dev/null
+++ b/core/profiles/testing_inherited/modules/contrib/contrib_child_profile_module/contrib_child_profile_module.info.yml
@@ -0,0 +1,6 @@
+name: 'Contrib child profile module'
+core: 8.x
+type: module
+description: 'A contrib module contained in a child profile, for testing.'
+package: Testing
+version: VERSION
diff --git a/core/profiles/testing_inherited/modules/custom/custom_child_profile_module/custom_child_profile_module.info.yml b/core/profiles/testing_inherited/modules/custom/custom_child_profile_module/custom_child_profile_module.info.yml
new file mode 100644
index 0000000000..5ffc61ff92
--- /dev/null
+++ b/core/profiles/testing_inherited/modules/custom/custom_child_profile_module/custom_child_profile_module.info.yml
@@ -0,0 +1,6 @@
+name: 'Custom child profile module'
+core: 8.x
+type: module
+description: 'A custom module contained in a child profile, for testing.'
+package: Testing
+version: VERSION
diff --git a/core/profiles/testing_inherited/testing_inherited.info.yml b/core/profiles/testing_inherited/testing_inherited.info.yml
new file mode 100644
index 0000000000..9f8309077e
--- /dev/null
+++ b/core/profiles/testing_inherited/testing_inherited.info.yml
@@ -0,0 +1,18 @@
+name: Testing Inherited
+type: profile
+description: 'Profile for testing base profile inheritance.'
+version: VERSION
+core: 8.x
+hidden: true
+
+base profile: testing
+
+install:
+ - block
+ - config
+ - child_profile_module
+ - contrib_child_profile_module
+ - custom_child_profile_module
+
+themes:
+ - stable
diff --git a/core/profiles/testing_inherited/tests/src/Functional/InheritedProfileTest.php b/core/profiles/testing_inherited/tests/src/Functional/InheritedProfileTest.php
new file mode 100644
index 0000000000..0af6c4f68d
--- /dev/null
+++ b/core/profiles/testing_inherited/tests/src/Functional/InheritedProfileTest.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Tests\testing_inherited\Functional;
+
+use Drupal\block\BlockInterface;
+use Drupal\block\Entity\Block;
+use Drupal\FunctionalTests\Installer\InstallerTestBase;
+
+/**
+ * Tests installing from an inherited profile.
+ *
+ * @group profiles
+ */
+class InheritedProfileTest extends InstallerTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected $profile = 'testing_inherited';
+
+ /**
+ * Tests inherited installation profile.
+ */
+ public function testInheritedProfile() {
+ // Check that the stable_login block exists.
+ $this->assertInstanceOf(BlockInterface::class, Block::load('stable_login'));
+
+ // Check that stable is the default theme.
+ $this->assertSame('stable', $this->config('system.theme')->get('default'));
+
+ /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
+ $module_handler = $this->container->get('module_handler');
+ // Check that parent dependencies are installed.
+ $this->assertTrue($module_handler->moduleExists('page_cache'));
+ // Check that child profile dependencies are installed.
+ $this->assertTrue($module_handler->moduleExists('config'));
+ // Check that modules contained in the child profile are installed.
+ $this->assertTrue($module_handler->moduleExists('child_profile_module'));
+ $this->assertTrue($module_handler->moduleExists('contrib_child_profile_module'));
+ $this->assertTrue($module_handler->moduleExists('custom_child_profile_module'));
+
+ // Check that all themes were installed.
+ $this->assertTrue(\Drupal::service('theme_handler')->themeExists('stable'));
+ }
+
+}
diff --git a/core/profiles/testing_inherited_standard/testing_inherited_standard.info.yml b/core/profiles/testing_inherited_standard/testing_inherited_standard.info.yml
new file mode 100644
index 0000000000..af0bae73c0
--- /dev/null
+++ b/core/profiles/testing_inherited_standard/testing_inherited_standard.info.yml
@@ -0,0 +1,13 @@
+name: Testing Inherited Standard
+type: profile
+description: 'Profile for testing base profile inheritance.'
+version: VERSION
+core: 8.x
+hidden: true
+
+base profile: standard
+
+install: []
+
+themes:
+ - bartik
diff --git a/core/profiles/testing_inherited_standard/tests/src/Functional/InheritedProfileTest.php b/core/profiles/testing_inherited_standard/tests/src/Functional/InheritedProfileTest.php
new file mode 100644
index 0000000000..25093a9eec
--- /dev/null
+++ b/core/profiles/testing_inherited_standard/tests/src/Functional/InheritedProfileTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Drupal\Tests\testing_inherited_standard\Functional;
+
+use Drupal\FunctionalTests\Installer\InstallerTestBase;
+
+/**
+ * Tests installing from an inherited standard profile.
+ *
+ * @group profiles
+ */
+class InheritedProfileTest extends InstallerTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected $profile = 'testing_inherited_standard';
+
+ /**
+ * Tests inherited installation profile.
+ */
+ public function testInheritedProfile() {
+ // Do nothing, simply install this profile.
+ }
+
+}
diff --git a/core/profiles/testing_subsubprofile/modules/grandchild_profile_module/grandchild_profile_module.info.yml b/core/profiles/testing_subsubprofile/modules/grandchild_profile_module/grandchild_profile_module.info.yml
new file mode 100644
index 0000000000..d92c99d8f9
--- /dev/null
+++ b/core/profiles/testing_subsubprofile/modules/grandchild_profile_module/grandchild_profile_module.info.yml
@@ -0,0 +1,6 @@
+name: 'Grandchild profile module'
+core: 8.x
+type: module
+description: 'A module contained in a grandchild profile, for testing.'
+package: Testing
+version: VERSION
diff --git a/core/profiles/testing_subsubprofile/testing_subsubprofile.info.yml b/core/profiles/testing_subsubprofile/testing_subsubprofile.info.yml
new file mode 100644
index 0000000000..98101a9163
--- /dev/null
+++ b/core/profiles/testing_subsubprofile/testing_subsubprofile.info.yml
@@ -0,0 +1,12 @@
+name: Testing SubSubProfile
+type: profile
+description: 'Profile for testing deep profile inheritance.'
+version: VERSION
+core: 8.x
+hidden: true
+
+base profile: testing_inherited
+
+install:
+ - syslog
+ - grandchild_profile_module
diff --git a/core/profiles/testing_subsubprofile/tests/src/Functional/DeepInheritedProfileTest.php b/core/profiles/testing_subsubprofile/tests/src/Functional/DeepInheritedProfileTest.php
new file mode 100644
index 0000000000..7df6c46fc0
--- /dev/null
+++ b/core/profiles/testing_subsubprofile/tests/src/Functional/DeepInheritedProfileTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Drupal\Tests\testing_subsubprofile\Functional;
+
+use Drupal\FunctionalTests\Installer\InstallerTestBase;
+
+/**
+ * Tests installing from an inherited profile whose parent is also inherited.
+ *
+ * @group profiles
+ */
+class DeepInheritedProfileTest extends InstallerTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected $profile = 'testing_subsubprofile';
+
+ /**
+ * Tests sub-sub-profile inherited installation.
+ */
+ public function testDeepInheritedProfile() {
+ // Check that stable is the default theme enabled in parent profile.
+ $this->assertSame('stable', $this->config('system.theme')->get('default'));
+
+ /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
+ $module_handler = $this->container->get('module_handler');
+ // page_cache was enabled in main profile.
+ $this->assertTrue($module_handler->moduleExists('page_cache'));
+ // block was enabled in parent profile.
+ $this->assertTrue($module_handler->moduleExists('block'));
+ // syslog was enabled in this profile.
+ $this->assertTrue($module_handler->moduleExists('syslog'));
+ // A module contained in this profile was installed too.
+ $this->assertTrue($module_handler->moduleExists('grandchild_profile_module'));
+ }
+
+}
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php
index c8eb231a97..99cfb402c9 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php
@@ -741,9 +741,9 @@ public function testInstallProfileMisMatch() {
$error_log = $this->configImporter->getErrors();
// Install profiles can not be changed. Note that KernelTestBase currently
// does not use an install profile. This situation should be impossible
- // to get in but site's can removed the install profile setting from
+ // to get into but sites can change the install profile value in config or
// settings.php so the test is valid.
- $this->assertEqual(['Cannot change the install profile from <em class="placeholder"></em> to <em class="placeholder">this_will_not_work</em> once Drupal is installed.'], $error_log);
+ $this->assertEqual($error_log, ['Cannot change the install profile from <em class="placeholder"></em> to <em class="placeholder">this_will_not_work</em> once Drupal is installed.']);
}
}
diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ProfileExtensionListTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ProfileExtensionListTest.php
new file mode 100644
index 0000000000..0b4bbfa5f4
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Extension/ProfileExtensionListTest.php
@@ -0,0 +1,145 @@
+<?php
+
+namespace Drupal\KernelTests\Core\Extension;
+
+use Drupal\Core\Extension\Extension;
+use Drupal\Core\Extension\ProfileExtensionList;
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Tests the ProfileExtensionList class.
+ *
+ * @coversDefaultClass \Drupal\Core\Extension\ProfileExtensionList
+ *
+ * @group Extension
+ */
+class ProfileExtensionListTest extends KernelTestBase {
+
+ /**
+ * Tests getting profile info.
+ *
+ * @covers ::getExtensionInfo
+ */
+ public function testGetExtensionInfo() {
+ /** @var \Drupal\Core\Extension\ProfileExtensionList $profile_list */
+ $profile_list = $this->container->get('extension.list.profile');
+
+ $info = $profile_list->getExtensionInfo('testing_inherited');
+ $this->assertNotEmpty($info);
+ $this->assertSame($info['name'], 'Testing Inherited');
+ $this->assertSame($info['base profile'], 'testing');
+ $this->assertContains('config', $info['install']);
+ $this->assertContains('drupal:page_cache', $info['install']);
+ $this->assertTrue($info['hidden'], 'Profiles should be hidden');
+
+ // Test that profiles without any base return normalized info.
+ $info = $profile_list->getExtensionInfo('minimal');
+ $this->assertSame('', $info['base profile']);
+
+ // Tests three levels profile inheritance.
+ $info = $profile_list->getExtensionInfo('testing_subsubprofile');
+ $this->assertSame($info['base profile'], 'testing_inherited');
+ }
+
+ /**
+ * Tests getting profile dependency list.
+ *
+ * @covers ::getAncestors
+ */
+ public function testGetAncestors() {
+ /** @var \Drupal\Core\Extension\ProfileExtensionList $profile_list */
+ $profile_list = $this->container->get('extension.list.profile');
+
+ $profiles = $profile_list->getAncestors('testing');
+ $this->assertCount(1, $profiles);
+
+ $profiles = $profile_list->getAncestors('testing_inherited');
+ $this->assertCount(2, $profiles);
+
+ $profiles = $profile_list->getAncestors('testing_subsubprofile');
+ $this->assertCount(3, $profiles);
+
+ $first_profile = current($profiles);
+ $this->assertInstanceOf(Extension::class, $first_profile);
+ $this->assertSame($first_profile->getName(), 'testing');
+ $this->assertSame(1000, $first_profile->weight);
+ $this->assertObjectHasAttribute('origin', $first_profile);
+
+ $second_profile = next($profiles);
+ $this->assertInstanceOf(Extension::class, $second_profile);
+ $this->assertSame($second_profile->getName(), 'testing_inherited');
+ $this->assertSame(1001, $second_profile->weight);
+ $this->assertObjectHasAttribute('origin', $second_profile);
+
+ $third_profile = next($profiles);
+ $this->assertInstanceOf(Extension::class, $third_profile);
+ $this->assertSame($third_profile->getName(), 'testing_subsubprofile');
+ $this->assertSame(1002, $third_profile->weight);
+ $this->assertObjectHasAttribute('origin', $third_profile);
+ }
+
+ /**
+ * @covers ::selectDistribution
+ *
+ * @depends testGetExtensionInfo
+ */
+ public function testSelectDistribution() {
+ $profile_list = new TestProfileExtensionList(
+ $this->container->get('app.root'),
+ 'profile',
+ $this->container->get('cache.default'),
+ $this->container->get('info_parser'),
+ $this->container->get('module_handler'),
+ $this->container->get('state'),
+ $this->container->getParameter('install_profile')
+ );
+
+ $profiles = ['testing', 'testing_inherited'];
+ $base_info = $profile_list->getExtensionInfo('minimal');
+ $profile_info = $profile_list->getExtensionInfo('testing_inherited');
+
+ // Neither profile has distribution set.
+ $distribution = $profile_list->selectDistribution($profiles);
+ $this->assertEmpty($distribution, 'No distribution should be selected');
+
+ // Set base profile distribution.
+ $base_info['distribution']['name'] = 'Minimal';
+ $profile_list->profileInfo['minimal'] = $base_info;
+ // Base profile distribution should not be selected.
+ $distribution = $profile_list->selectDistribution($profiles);
+ $this->assertEmpty($distribution, 'Base profile distribution should not be selected');
+
+ // Set main profile distribution.
+ $profile_info['distribution']['name'] = 'Testing Inherited';
+ $profile_list->profileInfo['testing_inherited'] = $profile_info;
+ // Main profile distribution should be selected.
+ $distribution = $profile_list->selectDistribution($profiles);
+ $this->assertEquals($distribution, 'testing_inherited');
+ }
+
+}
+
+final class TestProfileExtensionList extends ProfileExtensionList {
+
+ /**
+ * Overridden profile info, keyed by extension name.
+ *
+ * @var array
+ */
+ public $profileInfo = [];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getList() {
+ $extensions = parent::getList();
+
+ foreach ($extensions as $name => $extension) {
+ if (isset($this->profileInfo[$name])) {
+ $extension->info = $this->profileInfo[$name];
+ }
+ }
+ return $extensions;
+ }
+
+}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.