From 135ca1c04f07a62fd2f991c3f3d68e112ca84ea4 Mon Sep 17 00:00:00 2001
From: Dries <dries@buytaert.net>
Date: Fri, 11 Jul 2014 12:24:15 -0400
Subject: [PATCH] Issue #2294177 by alexpott: Allow Drupal\Core to provide
 [config] entity types.

---
 core/lib/Drupal/Core/Config/ConfigInstaller.php               | 2 ++
 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php       | 2 +-
 core/lib/Drupal/Core/Plugin/DefaultPluginManager.php          | 2 +-
 .../Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php  | 3 ++-
 core/modules/config_translation/src/ConfigMapperManager.php   | 2 +-
 core/modules/field/src/ConfigImporterFieldPurger.php          | 2 +-
 .../Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php     | 4 ++--
 7 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php
index c8defe72e5e8..6fe1afaa272d 100644
--- a/core/lib/Drupal/Core/Config/ConfigInstaller.php
+++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php
@@ -107,6 +107,8 @@ public function installDefaultConfig($type, $name) {
     $extension_config = $this->configFactory->get('core.extension');
     $enabled_extensions = array_keys((array) $extension_config->get('module'));
     $enabled_extensions += array_keys((array) $extension_config->get('theme'));
+    // Core can provide configuration.
+    $enabled_extensions[] = 'core';
 
     foreach ($collection_info->getCollectionNames(TRUE) as $collection) {
       $config_to_install = $this->listDefaultConfigCollection($collection, $type, $name, $enabled_extensions);
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index 4c0286ae2f05..210e259618c3 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -358,7 +358,7 @@ protected function addDependency($type, $name) {
     // explicitly declare the dependency. An explicit dependency on Core, which
     // provides some plugins, is also not needed.
     // @see \Drupal\Core\Config\Entity\ConfigEntityDependency::hasDependency()
-    if ($type == 'module' && ($name == $this->getEntityType()->getProvider() || $name == 'Core')) {
+    if ($type == 'module' && ($name == $this->getEntityType()->getProvider() || $name == 'core')) {
       return $this;
     }
 
diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
index 4059e100e599..e1d0731dc3b9 100644
--- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
+++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
@@ -234,7 +234,7 @@ protected function findDefinitions() {
       if (is_object($plugin_definition) && !($plugin_definition = (array) $plugin_definition)) {
         continue;
       }
-      if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('Core', 'Component')) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) {
+      if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('core', 'component')) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) {
         unset($definitions[$plugin_id]);
       }
     }
diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
index 130cb62600bb..b7a2dfdbcd36 100644
--- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
+++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
@@ -9,6 +9,7 @@
 
 use Drupal\Component\Annotation\AnnotationInterface;
 use Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery as ComponentAnnotatedClassDiscovery;
+use Drupal\Component\Utility\Unicode;
 
 /**
  * Defines a discovery mechanism to find annotated plugins in PSR-0 namespaces.
@@ -105,7 +106,7 @@ protected function getProviderFromNamespace($namespace) {
     preg_match('|^Drupal\\\\(?<provider>[\w]+)\\\\|', $namespace, $matches);
 
     if (isset($matches['provider'])) {
-      return $matches['provider'];
+      return Unicode::strtolower($matches['provider']);
     }
 
     return NULL;
diff --git a/core/modules/config_translation/src/ConfigMapperManager.php b/core/modules/config_translation/src/ConfigMapperManager.php
index bb3ce658fa99..8eb373542bf0 100644
--- a/core/modules/config_translation/src/ConfigMapperManager.php
+++ b/core/modules/config_translation/src/ConfigMapperManager.php
@@ -150,7 +150,7 @@ protected function findDefinitions() {
     // If this plugin was provided by a module that does not exist, remove the
     // plugin definition.
     foreach ($definitions as $plugin_id => $plugin_definition) {
-      if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('Core', 'Component')) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
+      if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('core', 'component')) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
         unset($definitions[$plugin_id]);
       }
     }
diff --git a/core/modules/field/src/ConfigImporterFieldPurger.php b/core/modules/field/src/ConfigImporterFieldPurger.php
index a33df394a553..74f7acde1d91 100644
--- a/core/modules/field/src/ConfigImporterFieldPurger.php
+++ b/core/modules/field/src/ConfigImporterFieldPurger.php
@@ -114,7 +114,7 @@ protected static function initializeSandbox(array &$context, ConfigImporter $con
    */
   public static function getFieldsToPurge(array $extensions, array $deletes) {
     $providers = array_keys($extensions['module']);
-    $providers[] = 'Core';
+    $providers[] = 'core';
     $fields_to_delete = array();
 
     // Gather fields that will be deleted during configuration synchronization
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index e5dea6dcdfad..aae74eb37fcf 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -186,11 +186,11 @@ public function testAddDependency() {
     $method = new \ReflectionMethod('\Drupal\Core\Config\Entity\ConfigEntityBase', 'addDependency');
     $method->setAccessible(TRUE);
     $method->invoke($this->entity, 'module', $this->provider);
-    $method->invoke($this->entity, 'module', 'Core');
+    $method->invoke($this->entity, 'module', 'core');
     $method->invoke($this->entity, 'module', 'node');
     $dependencies = $this->entity->get('dependencies');
     $this->assertNotContains($this->provider, $dependencies['module']);
-    $this->assertNotContains('Core', $dependencies['module']);
+    $this->assertNotContains('core', $dependencies['module']);
     $this->assertContains('node', $dependencies['module']);
 
     // Test sorting of dependencies.
-- 
GitLab