Issue #3110831: Cannot un-disable a resource type field disabled by a previous ResourceTypeBuildEvent subscriber
Merge request reports
Activity
- Resolved by Björn Brala
- Resolved by Björn Brala
- Resolved by Björn Brala
- Resolved by Björn Brala
- Resolved by Björn Brala
Works as expected! I was able to re-enable a field, (
drupal_internal__order_id
) that was disabled by thecommerce_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 :-).
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 -
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);
Toggle commit list-
5c5b4eed...d8e59907 - 1404 commits from branch
mentioned in merge request !8808
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 -
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);
Toggle commit list-
28746fb3...26684ff0 - 3188 commits from branch
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() { changed this line in version 11 of the diff
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) { changed this line in version 11 of the diff
Please register or sign in to reply