Method to enable a resource type field disabled by a previous ResourceTypeBuildEvent subscriber

Created on 3 February 2020, almost 5 years ago
Updated 18 February 2023, over 1 year ago

If a ResourceTypeBuildEvent disables a field, for example:

      // Disable the internal Drupal identifiers.
      if (strpos($field->getPublicName(), 'drupal_internal__') === 0) {
        $event->disableField($field);
      }

A lower priority subscriber cannot undo that change. There is no "undisableField"

Solution

Added ResourceTypeBuildEvent::enableField which enables a field.

Todo

  1. Add a change record for this change.
✨ Feature request
Status

RTBC

Version

10.1 ✨

Component
JSON APIΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
  • API addition

    Enhances an existing API or introduces a new subsystem. Depending on the size and impact, possibly backportable to earlier major versions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Verified the test coverage running locally without the fix. I got

    Error : Call to undefined method Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent::enableField()

    Which is good!

    All threads are resolved on the MR
    All tests are green
    Change record is added and make sense (to me at least)
    New functions are typehinted

    This looks good to me.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    There are several other options here. You could alter the service that subscribes the event or you could implement an event subscriber with a higher priority and stop propagation. I'm not sure that adding enableField() to fight it out with disableField() is going to improve the situation. I can imagine people adding an event to disable a field, that was disabled and then enabled. Feels odd.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Alright issue should be reworked based on #22 or explained why this is the better approach.

    Decision should be documented in issue summary please

    Thanks.

  • πŸ‡ΊπŸ‡ΈUnited States matthand Riverdale Park, Maryland

    Is there a way to re-enable the UUID field that is disabled on node resources by JSON:API without this new enableField method? I don't think so. Real world scenario of trying to match a legacy Drupal 8 JSON:API endpoint to prevent consumer apps requiring a rebuild.

  • Merge request !8808Resolve #3110831 "Cannot un disable a 10 3" β†’ (Open) created by z3cka
  • Pipeline finished with Failed
    4 months ago
    Total: 480s
    #227032
  • πŸ‡ΊπŸ‡ΈUnited States z3cka

    I agree that this can probably be handled better, but until a better solution is provided, I went ahead and rebased the temp fix on to the Drupal 10.3.x branch for those that need a compatible patch.

  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    I really think this is the way, it might need some priority juggling to make work in your application but that should be fine. I'll update the MR to 11.x and make sure codestyle and everything is up to date.

  • Pipeline finished with Failed
    4 months ago
    Total: 544s
    #228652
  • Pipeline finished with Failed
    4 months ago
    Total: 704s
    #228666
  • Pipeline finished with Success
    4 months ago
    Total: 476s
    #228684
  • Status changed to Needs review 4 months ago
  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    Moved all changed to 11.x, also updates a return type that didnt make sense. I think this is good like this. I've updated the issue summary also.

    I still think this is the best option for adjusting, even though this could mean you enable and disable multiple times. But i don't think this will be an actually issue in implementations.

  • Pipeline finished with Success
    4 months ago
    Total: 460s
    #237544
  • Status changed to RTBC 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Reading the CR and it appears to contain good detail with a nice example

    Test-only feature has already been ran

    1) Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testResourceTypeFieldEnabling
    Error: Call to undefined method Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent::enableField()
    /builds/issue/drupal-3110831/core/modules/jsonapi/tests/modules/jsonapi_test_resource_type_building/src/EventSubscriber/LateResourceTypeBuildEventSubscriber.php:41
    /builds/issue/drupal-3110831/vendor/symfony/event-dispatcher/EventDispatcher.php:206
    /builds/issue/drupal-3110831/vendor/symfony/event-dispatcher/EventDispatcher.php:56
    /builds/issue/drupal-3110831/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php:165
    /builds/issue/drupal-3110831/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php:132
    /builds/issue/drupal-3110831/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php:131
    /builds/issue/drupal-3110831/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php:209
    /builds/issue/drupal-3110831/core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php:246
    ERRORS!
    Tests: 13, Assertions: 192, Errors: 1.
    

    So coverage is there.

    Added some super nitpicky :void returns directly.

    Believe all feedback has been addressed.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Committed to 11.x for 11.1.0 and backported to 10.4.x as a minor API addition to keep things in sync. Also published the change record.

    Committed and pushed a1c6ae78c3 to 11.x and 257fb3b34b to 10.4.x. Thanks!

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    We'll get there, step to step.

  • Status changed to Fixed about 1 month ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024