diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install index 4bca69b..3be359c 100644 --- a/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for the rest module. */ +use Drupal\rest\Entity\RestEndpoint; + /** * Implements hook_requirements(). */ @@ -21,3 +23,20 @@ function rest_requirements($phase) { } return $requirements; } + +/** + * Install the REST endpoint entity type and convert old settings-based config. + */ +function rest_update_8001() { + \Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('rest_endpoint')); + foreach (\Drupal::config('rest.settings')->get('resources') as $key => $resource) { + $resource = RestEndpoint::create([ + 'id' => str_replace(':', '__', $key), + 'configuration' => $resource, + ]); + $resource->save(); + } + \Drupal::configFactory()->getEditable('rest.settings') + ->clear('resources') + ->save(); +} diff --git a/core/modules/rest/src/Entity/RestEndpoint.php b/core/modules/rest/src/Entity/RestEndpoint.php index cfc96f5..28ee69b 100644 --- a/core/modules/rest/src/Entity/RestEndpoint.php +++ b/core/modules/rest/src/Entity/RestEndpoint.php @@ -28,6 +28,11 @@ * label_callback = "getLabelFromPlugin", * entity_keys = { * "id" = "id" + * }, + * config_export = { + * "id", + * "plugin_id", + * "configuration" * } * ) */ @@ -74,7 +79,8 @@ public function __construct(array $values, $entity_type) { $this->logger = \Drupal::service('logger.factory')->get('rest'); $this->setContainer(\Drupal::getContainer()); parent::__construct($values, $entity_type); - // The config entity id looks like the plugin id but uses _ instead of : because : is not valid for config entities. + // The config entity id looks like the plugin id but uses __ instead of : + // because : is not valid for config entities. if (!isset($this->plugin_id) && isset($this->id)) { // Generate plugin_id on first entity creation $this->plugin_id = str_replace('__', ':', $this->id); diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index e5780a1..114b4a0 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -270,7 +270,15 @@ protected function runUpdates() { } // Ensure that the update hooks updated all entity schema. - $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates(), 'After all updates ran, entity schema is up to date.'); + $needs_updates = \Drupal::entityDefinitionUpdateManager()->needsUpdates(); + $this->assertFalse($needs_updates, 'After all updates ran, entity schema is up to date.'); + if ($needs_updates) { + foreach (\Drupal::entityDefinitionUpdateManager()->getChangeSummary() as $entity_type_id => $summary) { + foreach ($summary as $message) { + $this->fail($message); + } + } + } } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index afa5892..e6b06af 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1350,7 +1350,11 @@ function system_update_8004() { $manager = \Drupal::entityDefinitionUpdateManager(); foreach (array_keys(\Drupal::entityManager() ->getDefinitions()) as $entity_type_id) { - $manager->updateEntityType($manager->getEntityType($entity_type_id)); + // Only update the entity type if it already exists. This condition is + // needed in case new entity types are introduced after this update. + if ($entity_type = $manager->getEntityType($entity_type_id)) { + $manager->updateEntityType($entity_type); + } } }