1. Remove ResourceConfigInterface
  2. Rename ResourceConfig::getBundleId() to ResourceConfig::bundle() (for consistency with EntityInterface::bundle() and everything else in core) — handled in #2841287: Remove ResourceManager::hasBundle(), ResourceManager::getEntityTypeManager(), ResourceConfig::getPath(), and rename ResourceConfig::getBundleId()
  3. Remove ResourceManagerInterface
  4. Mark ResourceManager @internal
  5. Rename ResourceConfig to ResourceType and ResourceManager to ResourceTypeRepository (consistent with the rest of core, see #6)
  6. Remove CurrentContext::getResourceManager() (see #9)
  7. Rename CurrentContext::getResourceConfig() to CurrentContext::getResourceType() (see #11).
  8. Rename RelationShipItem::getTargetResourceConfig() to RelationShipItem::getTargetResourceType() (see #12)

You can see these steps gradually being applied in the interdiffs for the patches below.

Finally: why do steps 1-4 here and then also do steps 5 and onwards in the same patch? Because they touch the exact same lines, and are very closely related.

CommentFileSizeAuthor
#31 jsonapi_rename_resource_config-2841296-31.patch100.64 KBWim Leers
#31 interdiff.txt626 bytesWim Leers
#28 jsonapi_rename_resource_config-2841296-28.patch100.64 KBWim Leers
#28 interdiff.txt1.99 KBWim Leers
#27 jsonapi_rename_resource_config-2841296-27.patch100.52 KBWim Leers
#23 Normalizer) 2017-01-06 23-29-39.png205.61 KBe0ipso
#17 jsonapi_rename_resource_config-2841296-17.patch101.49 KBWim Leers
#17 interdiff.txt20.44 KBWim Leers
#15 jsonapi_rename_resource_config-2841296-15.patch96.37 KBWim Leers
#15 interdiff.txt11.12 KBWim Leers
#12 jsonapi_rename_resource_config-2841296-12.patch92.74 KBWim Leers
#12 interdiff.txt4.47 KBWim Leers
#11 jsonapi_rename_resource_config-2841296-11.patch90.1 KBWim Leers
#11 interdiff.txt7.14 KBWim Leers
#10 interdiff.txt1011 bytesWim Leers
#10 jsonapi_rename_resource_config-2841296-10.patch86.45 KBWim Leers
#9 jsonapi_rename_resource_config-2841296-9.patch86.51 KBWim Leers
#9 interdiff.txt8.65 KBWim Leers
#8 jsonapi_rename_resource_config-2841296-8.patch84.78 KBWim Leers
#8 interdiff.txt36.77 KBWim Leers
#7 jsonapi_rename_resource_config-2841296-7.patch64.56 KBWim Leers
#7 interdiff.txt19.97 KBWim Leers
#6 interdiff.txt56.57 KBWim Leers
#6 jsonapi_rename_resource_config-2841296-6.patch61.33 KBWim Leers
#5 jsonapi_rename_resource_config-2841296-5.patch37.87 KBWim Leers
#5 interdiff.txt1.24 KBWim Leers
#4 jsonapi_rename_resource_config-2841296-4.patch36.7 KBWim Leers
#3 jsonapi_rename_resource_config-2841296-3.patch44.05 KBWim Leers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Title: Rename ResourceConfig & ResourceManager and remove their interfaces » [PP-2] Rename ResourceConfig & ResourceManager and remove their interfaces
Status: Active » Postponed
Related issues: +#2841287: Remove ResourceManager::hasBundle(), ResourceManager::getEntityTypeManager(), ResourceConfig::getPath(), and rename ResourceConfig::getBundleId()
Wim Leers’s picture

This patch does exactly what is outlined in the IS.

Wim Leers’s picture

Issue summary: View changes
FileSize
36.7 KB
Wim Leers’s picture

FileSize
1.24 KB
37.87 KB

I hadn't actually removed ResourceConfigInterface yet (point 1 in the IS). This does that.

Wim Leers’s picture

Issue summary: View changes
FileSize
61.33 KB
56.57 KB

I renamed ResourceConfig to ResourceType and ResourceManager to ResourceTypeRepository:

 rename src/{Configuration/ResourceConfig.php => ResourceType/ResourceType.php} (95%)
 rename src/{Configuration/ResourceManager.php => ResourceType/ResourceTypeRepository.php} (90%)
 rename tests/src/Kernel/{Configuration/ResourceManagerTest.php => ResourceType/ResourceTypeRepositoryTest.php} (72%)

Why "repository"? This is consistent with EntityRepository and BlockRepository.

Why "resource type"? Because this is not configuration, but just a mere value object representing a JSON API resource type.

Wim Leers’s picture

FileSize
19.97 KB
64.56 KB

#6 already renamed some occurrences of resource_manager and resourceManager to resource_type_repository and resourceTypeRepository. This updates the remainder.

Wim Leers’s picture

FileSize
36.77 KB
84.78 KB

Similar to #7: this renames all occurrences of $resource_config to $resource_type and occurrences of $this->resourceConfig to $this->resourceType.

Wim Leers’s picture

Issue summary: View changes
FileSize
8.65 KB
86.51 KB

I noticed that I'd failed to update CurrentContext::getResourceManager consistently. Turns out that that is actually completely unnecessary. Only EntityNormalizer uses it… and it should instead just get the resource manager (now resource type repository) injected. We shouldn't use the "current context" as a secondary container.

So, this removes that method altogether.

(This change could be moved to a separate issue that would block this issue if that's preferred.)

Wim Leers’s picture

FileSize
86.45 KB
1011 bytes

In one of the above patches, I cleaned up ResourceTypeRepository in a way that broke things. This fixes it.

Wim Leers’s picture

Issue summary: View changes
FileSize
7.14 KB
90.1 KB

Rename CurrentContext::getResourceConfig() to CurrentContext::getResourceType().

Wim Leers’s picture

Issue summary: View changes
FileSize
4.47 KB
92.74 KB

Rename RelationShipItem::getTargetResourceConfig() to RelationShipItem::getTargetResourceType().

e0ipso’s picture

In a pre-review i noticed that there are still multiple instances of 'resource_config' and $resource_config. I think that we should also rename the variable names and array keys to be consistent.

Wim Leers’s picture

Yep, I was still working on that at the end of my day. I will finish this tomorrow :)

If that's the only major remark you have, then that's awesome :D But I suspect you'll have more feedback :)

Wim Leers’s picture

FileSize
11.12 KB
96.37 KB

Finally, made all comments consistent.

Wim Leers’s picture

Title: [PP-2] Rename ResourceConfig & ResourceManager and remove their interfaces » [PP-1] Rename ResourceConfig & ResourceManager and remove their interfaces

Next up: #13 + #14. Also, #2841056: Remove use of plugins landed, so just PP-1 now.

Also, while working on #15, I also wanted to do this:

@@ -18,14 +18,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
 class CurrentContext implements CurrentContextInterface {
 
   /**
-   * The resource type repository.
-   *
-   * @var \Drupal\jsonapi\ResourceType\ResourceTypeRepository
-   */
-  protected $resourceTypeRepository;
-
-  /**
-   * The current resource config.
+   * The current JSON API resource type.
    *
    * @var \Drupal\jsonapi\ResourceType\ResourceType
    */
@@ -56,23 +49,19 @@ class CurrentContext implements CurrentContextInterface {
    *   The current route match.
    */
   public function __construct(ResourceTypeRepository $resource_type_repository, RequestStack $request_stack, RouteMatchInterface $route_match) {
-    $this->resourceTypeRepository = $resource_type_repository;
     $this->requestStack = $request_stack;
     $this->routeMatch = $route_match;
+
+    $route = $this->routeMatch->getRouteObject();
+    $entity_type_id = $route->getRequirement('_entity_type');
+    $bundle = $route->getRequirement('_bundle');
+    $this->resourceType = $this->resourceTypeRepository->get($entity_type_id, $bundle);
   }
 
   /**
    * {@inheritdoc}
    */
   public function getResourceType() {
-    if (!isset($this->resourceType)) {
-      $route = $this->routeMatch->getRouteObject();
-      $entity_type_id = $route->getRequirement('_entity_type');
-      $bundle = $route->getRequirement('_bundle');
-      $this->resourceType = $this->resourceTypeRepository
-        ->get($entity_type_id, $bundle);
-    }
-
     return $this->resourceType;
   }

i.e. I wanted to remove that protected $resourceTypeRepository, because it's not actually used — it can just be used in the constructor and then call it a day. Unfortunately, there's a bug in core that gets in the way: #2841542: \Drupal\serialization\EventSubscriber\UserRouteAlterSubscriber has serializer service injected, but doesn't use it — also makes route rebuilding more expensive.

(Although, to be fair, the real problem here is that JSON API's normalizers depend on the current request/route match — the Symfony serialization system is designed to be independent of requests. Improving that is for another issue.)

Wim Leers’s picture

This then does #13 + #14.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned

And now this is ready!

Wim Leers’s picture

e0ipso’s picture

Title: [PP-1] Rename ResourceConfig & ResourceManager and remove their interfaces » Rename ResourceConfig & ResourceManager and remove their interfaces
e0ipso’s picture

Status: Postponed » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: jsonapi_rename_resource_config-2841296-17.patch, failed testing.

e0ipso’s picture

This was a big patch to go through. Good thing that I can see the changes better in PhpStorm.

diff

Some thoughts.

  1. +++ b/src/Normalizer/EntityNormalizer.php
    @@ -41,18 +41,11 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface,
    -  /**
    -   * The current JSON API request context.
    -   *
    -   * @var \Drupal\jsonapi\Context\CurrentContextInterface
    -   */
    -  protected $currentContext;
    

    Good catch.

  2. +++ b/src/Normalizer/RelationshipNormalizer.php
    @@ -24,13 +24,6 @@ class RelationshipNormalizer extends NormalizerBase {
       /**
    -   * The manager for resource configuration.
    -   *
    -   * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface
    -   */
    -  protected $resourceManager;
    -
    
    @@ -40,13 +33,13 @@ class RelationshipNormalizer extends NormalizerBase {
    -  public function __construct(ResourceManagerInterface $resource_manager, LinkManagerInterface $link_manager) {
    -    $this->resourceManager = $resource_manager;
    +  public function __construct(ResourceTypeRepository $resource_type_repository, LinkManagerInterface $link_manager) {
    +    $this->resourceTypeRepository = $resource_type_repository;
    

    I'm missing here:

    protected $resourceTypeRepository;
    
  3. +++ b/src/ResourceType/ResourceType.php
    @@ -1,6 +1,6 @@
     use Drupal\Core\Config\ConfigFactoryInterface;
     use Drupal\Core\Entity\EntityTypeManagerInterface;
    

    Can these two be dropped?

  4. +++ b/src/ResourceType/ResourceTypeRepository.php
    @@ -1,6 +1,6 @@
     use Drupal\Core\Config\ConfigFactoryInterface;
    

    Can we drop Drupal\Core\Config\ConfigFactoryInterface and Drupal\Core\Extension\ModuleHandlerInterface?

  5. +++ b/src/ResourceType/ResourceTypeRepository.php
    @@ -9,11 +9,22 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
    + * Contains the complete set of ResourceType value objects, which are auto-
    + * generated based on the Entity Type Manager and Entity Type Bundle Info: one
    + * JSON API resource type per entity type bundle. So, for example:
    + * - node--article
    + * - node--page
    + * - node--…
    + * - user--user
    + * - …
    

    Love the extra docs.

  6. +++ b/src/Routing/RouteEnhancer.php
    @@ -37,8 +37,8 @@ class RouteEnhancer implements RouteEnhancerInterface {
    +      // route (which is set based on the corresponding Resourcetype), then
    

    Typo Resourcetype to ResourceType

e0ipso’s picture

This is a BIG patch, but it does not do anything beyond the renaming and dropping some unused stuff.

Good work!

Wim Leers’s picture

2. That's already in the base class :) Not my idea, it was already there!

3+4. There are quite a few unused use statements in various places in the codebase, so I didn't play too close attention. You can remove them on commit, or we can just fix it in a big "coding standards cleanup" patch that we will need to do anyway before this can get into core. :)

1+5. :)

6. Hah, nice catch!

I take you're also convinced of the new names I'm suggesting here?

e0ipso’s picture

I take you're also convinced of the new names I'm suggesting here?

I don't really mind all that much about the names. The new names are good and have some thought and rationale behind them, so I'm on board. You did this patch, that tells me that you do mind therefor I'm up to it.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
Status: Needs work » Needs review
FileSize
100.52 KB

First, rebasing, because #2840948: Remove interfaces of JSON API-specific normalizers was committed too, which caused this to no longer apply.

(This is equivalent to the patch in #17.)

Wim Leers’s picture

The last submitted patch, 27: jsonapi_rename_resource_config-2841296-27.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: jsonapi_rename_resource_config-2841296-28.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
626 bytes
100.64 KB

LOL, a single typo was causing all those fails AFAICT! Didn't notice locally (everything passes locally), because I'm on a case-insensitive file system!

e0ipso’s picture

Status: Needs review » Fixed
Wim Leers’s picture

WOOOOOT!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.