This is part of #2829398: Clean up JsonApiResource: the annotation, plugin type, plugin manager, plugin implementations, the dynamic routes generator and the request handler.
Wim Leers created an issue. See original summary.
This is blocked on #2841050: Make ResourceConfig an actual value object: immutable, with no services injected, which is blocked on #2841048: Remove ResourceConfig::getGlobalConfig(), and stop injecting the config factory service in ResourceConfig value objects.
Also, this is a net reduction: 8 files changed, 48 insertions, 310 deletions :)
8 files changed, 48 insertions, 310 deletions
+++ b/jsonapi.services.yml @@ -91,9 +91,6 @@ services: - plugin.manager.resource.processor: - class: Drupal\jsonapi\Plugin\JsonApiResourceManager - parent: default_plugin_manager
Remove the plugin manager.
+++ /dev/null @@ -1,79 +0,0 @@ -class ResourceDeriver extends DeriverBase implements ContainerDeriverInterface {
Remove the sole plugin's deriver.
+++ /dev/null index 560b703..0000000 --- a/src/Plugin/JsonApiResourceInterface.php
Remove the plugin interface.
+++ b/src/Routing/Routes.php @@ -52,13 +52,13 @@ class Routes implements ContainerInjectionInterface { - $this->resourcePluginManager = $resource_plugin_manager; ... + $this->resourceManager = $resource_manager;
Switch from the plugin manager to the resource manager.
+++ b/src/Routing/Routes.php @@ -97,70 +94,62 @@ class Routes implements ContainerInjectionInterface { + ->setRequirement('_bundle', $resource_config->getBundleId()) ... - if ($bundle) { - $route_collection->setRequirement('_bundle', $bundle);
Turns out this is a simplification we can make here.
+++ b/src/Routing/Routes.php @@ -79,16 +79,13 @@ class Routes implements ContainerInjectionInterface { - foreach ($this->resourcePluginManager->getDefinitions() as $plugin_id => $plugin_definition) { - $entity_type = $plugin_definition['entityType']; - // For the entity type resources the bundle is NULL. - $bundle = $plugin_definition['bundle']; - $partial_path = $plugin_definition['data']['partialPath']; - $route_keys = explode(':', $plugin_id); - $route_key = end($route_keys) . '.'; - // Add the collection route. + foreach ($this->resourceManager->all() as $resource_config) { @@ -97,70 +94,62 @@ class Routes implements ContainerInjectionInterface { - ->setRequirement('_entity_type', $entity_type) - ->setRequirement('_permission', $plugin_definition['permission']) + ->setRequirement('_entity_type', $resource_config->getEntityTypeId()) ... + ->setRequirement('_permission', 'access content')
This converts from using the plugin manager to the resource manager. This is basically the key change.
This is also basically the only thing we need to change when we drop the use of plugins.
Which just goes to show how little we used plugins :)
Hah, apparently I forgot to remote the annotation.
The net reduction is now even better: 9 files changed, 48 insertions, 364 deletions :)
9 files changed, 48 insertions, 364 deletions
#2841050: Make ResourceConfig an actual value object: immutable, with no services injected landed, this is now unblocked!
The last submitted patch, 6: jsonapi_remove_plugin-2841056-6.patch, failed testing.
Because #2841050: Make ResourceConfig an actual value object: immutable, with no services injected was modified since creating #6, the patch in #6 no longer applies. Here's a rebased patch.
Dammit, cross-posted.
The last submitted patch, 10: jsonapi_remove_plugin-2841056-9.patch, failed testing.
Ah, of course, I rebased the patch so it applies, but the changes in #2841050-15: Make ResourceConfig an actual value object: immutable, with no services injected require another change to happen here too. Patch coming…
And done.
The rationale explanation in #5 still applies. #10 and #14 were only necessary to adjust for the modifications to the patch in #2841050: Make ResourceConfig an actual value object: immutable, with no services injected made after #2+#6 were created.
This blocks #2841056: Remove use of plugins.
Eh, #2841287: Remove ResourceManager::hasBundle(), ResourceManager::getEntityTypeManager(), ResourceConfig::getPath(), and rename ResourceConfig::getBundleId() of course.
+++ b/src/Routing/Routes.php @@ -97,70 +94,62 @@ class Routes implements ContainerInjectionInterface { - if ($bundle) { - $route_individual->setRequirement('_bundle', $bundle); - }
I checked, and this change does not conflict with the \Drupal\jsonapi\Routing\RouteEnhancer. So, :+1:
I'm merging this.
fix(Maintainability) Remove use of plugins (#2841056 by Wim Leers)
Yay!
Automatically closed - issue fixed for 2 weeks with no activity.
Comments
Comment #2
wim leersThis is blocked on #2841050: Make ResourceConfig an actual value object: immutable, with no services injected, which is blocked on #2841048: Remove ResourceConfig::getGlobalConfig(), and stop injecting the config factory service in ResourceConfig value objects.
Comment #3
wim leersComment #4
wim leersAlso, this is a net reduction:
8 files changed, 48 insertions, 310 deletions:)Comment #5
wim leersRemove the plugin manager.
Remove the sole plugin's deriver.
Remove the plugin interface.
Switch from the plugin manager to the resource manager.
Turns out this is a simplification we can make here.
This converts from using the plugin manager to the resource manager. This is basically the key change.
This is also basically the only thing we need to change when we drop the use of plugins.
Which just goes to show how little we used plugins :)
Comment #6
wim leersHah, apparently I forgot to remote the annotation.
The net reduction is now even better:
9 files changed, 48 insertions, 364 deletions:)Comment #7
e0ipsoComment #8
wim leers#2841050: Make ResourceConfig an actual value object: immutable, with no services injected landed, this is now unblocked!
Comment #10
wim leersBecause #2841050: Make ResourceConfig an actual value object: immutable, with no services injected was modified since creating #6, the patch in #6 no longer applies. Here's a rebased patch.
Comment #11
wim leersDammit, cross-posted.
Comment #13
wim leersAh, of course, I rebased the patch so it applies, but the changes in #2841050-15: Make ResourceConfig an actual value object: immutable, with no services injected require another change to happen here too. Patch coming…
Comment #14
wim leersAnd done.
Comment #15
wim leersThe rationale explanation in #5 still applies. #10 and #14 were only necessary to adjust for the modifications to the patch in #2841050: Make ResourceConfig an actual value object: immutable, with no services injected made after #2+#6 were created.
Comment #16
wim leersThis blocks #2841056: Remove use of plugins.
Comment #17
wim leersEh, #2841287: Remove ResourceManager::hasBundle(), ResourceManager::getEntityTypeManager(), ResourceConfig::getPath(), and rename ResourceConfig::getBundleId() of course.
Comment #18
e0ipsoI checked, and this change does not conflict with the \Drupal\jsonapi\Routing\RouteEnhancer. So, :+1:
I'm merging this.
Comment #20
e0ipsoComment #21
wim leersYay!