Skip to content
Snippets Groups Projects

Issue #3110831: Cannot un-disable a resource type field disabled by a previous ResourceTypeBuildEvent subscriber

Issue #3110831: Cannot un-disable a resource type field disabled by a previous ResourceTypeBuildEvent subscriber

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Wim Leers
  • Wim Leers
  • Wim Leers
  • Casey Grzecka
  • Works as expected! I was able to re-enable a field, (drupal_internal__order_id) that was disabled by the commerce_api module with this simple event subscriber:

    <?php
    
    class CommerceApiOrderIdSubscriber implements EventSubscriberInterface {
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents() {
        return [
          ResourceTypeBuildEvents::BUILD => 'onResourceTypeBuild',
        ];
      }
    
      /**
       * Customizes commerce resource types.
       *
       * @param \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent $event
       *   The event.
       */
      public function onResourceTypeBuild(ResourceTypeBuildEvent $event): void {
        $resourceTypeName = $event->getResourceTypeName();
    
        if ($resourceTypeName === 'order--default') {
          foreach ($event->getFields() as $field) {
            if ($field->getPublicName() === 'drupal_internal__order_id') {
              if (!$field->isFieldEnabled()) {
                $event->enableField($field);
              }
            }
          }
        }
      }
    }

    +1 for merge after nits are resolved :-).

  • Björn Brala added 1 commit

    added 1 commit

    Compare with previous version

  • Björn Brala changed the description

    changed the description

  • Björn Brala changed target branch from 9.4.x to 10.1.x

    changed target branch from 9.4.x to 10.1.x

  • Björn Brala added 2 commits

    added 2 commits

    • 0e873c38 - z3cka: The should read: "Enables the given field on the resource type to be built."
    • c34eb7ad - :thinking: Shouldn't this be chainable? If not: let's add void as the return type.

    Compare with previous version

  • Björn Brala added 1 commit

    added 1 commit

    • 5c5b4eed - winleers: return type missing.

    Compare with previous version

  • Björn Brala resolved all threads

    resolved all threads

  • Björn Brala added 1412 commits

    added 1412 commits

    • 5c5b4eed...d8e59907 - 1404 commits from branch project:10.1.x
    • e2c6544e - Allow enabling a ResourceTypeField.php
    • 774c766b - Add enableField to ResourceTypeBuildEvent
    • b7140fca - Test enableField event.
    • 4eb84a0f - Small nit
    • c524b26b - z3cka: The should read: "Enables the given field on the resource type to be built."
    • c51f1e56 - :thinking: Shouldn't this be chainable? If not: let's add void as the return type.
    • ebf994ce - winleers: return type missing.
    • 28746fb3 - winleers: Let's add declare(strict_types = 1);

    Compare with previous version

  • Casey Grzecka mentioned in merge request !8808

    mentioned in merge request !8808

  • Björn Brala changed target branch from 10.1.x to 11.x

    changed target branch from 10.1.x to 11.x

  • Björn Brala added 3196 commits

    added 3196 commits

    • 28746fb3...26684ff0 - 3188 commits from branch project:11.x
    • 85b5989b - Allow enabling a ResourceTypeField.php
    • 4fc42d73 - Add enableField to ResourceTypeBuildEvent
    • 359907fa - Test enableField event.
    • 20a8f496 - Small nit
    • 7331932c - z3cka: The should read: "Enables the given field on the resource type to be built."
    • c342742f - :thinking: Shouldn't this be chainable? If not: let's add void as the return type.
    • 4b0aaead - winleers: return type missing.
    • 0b6bc59b - winleers: Let's add declare(strict_types = 1);

    Compare with previous version

  • Björn Brala added 1 commit

    added 1 commit

    • 6e3e348a - add name tag again to service

    Compare with previous version

  • Björn Brala added 1 commit

    added 1 commit

    Compare with previous version

  • 214 214 $this->assertTrue($this->resourceTypeRepository->getByTypeName('node--page')->isFieldEnabled('uid'));
    215 215 }
    216 216
    217 /**
    218 * Tests that resource type fields can be re-enabled per resource type.
    219 */
    220 public function testResourceTypeFieldEnabling() {
  • 20 */
    21 public static function getSubscribedEvents(): array {
    22 return [
    23 ResourceTypeBuildEvents::BUILD => [
    24 ['enableResourceTypeFields'],
    25 ],
    26 ];
    27 }
    28
    29 /**
    30 * Disables any resource type fields that have been aliased by a test.
    31 *
    32 * @param \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent $event
    33 * The build event.
    34 */
    35 public function enableResourceTypeFields(ResourceTypeBuildEvent $event) {
  • added 1 commit

    • e384d011 - Apply 2 suggestion(s) to 2 file(s)

    Compare with previous version

  • Please register or sign in to reply
    Loading