Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify default JSON:API Extras enhancers link fields globally #17266

Merged
merged 33 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f499b1f
save progress with a working solution
alexfinnarn Feb 16, 2024
6a73d9c
dummy commit
alexfinnarn Feb 16, 2024
894364e
add patch for jsonapi_extras
alexfinnarn Feb 16, 2024
05896f0
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Feb 16, 2024
ca8ad33
updating lock file content hash
alexfinnarn Feb 16, 2024
432f15e
add settings for link enhancer
alexfinnarn Feb 19, 2024
845e00f
remove sample code for creating field type enhancer config
alexfinnarn Feb 20, 2024
9df5ac4
adjust config for field type enhancers
alexfinnarn Feb 22, 2024
aeb24f2
updating patch for jsonapi_extras
alexfinnarn Feb 23, 2024
6acc86a
add exported config for field type enhancers
alexfinnarn Feb 23, 2024
081a121
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Feb 23, 2024
877ce22
delete un-needed code
alexfinnarn Feb 23, 2024
03de46f
update composer commit hash
alexfinnarn Feb 23, 2024
ff1c9b4
updating patch for jsonapi_extras
alexfinnarn Feb 23, 2024
c49d422
update patch to include cache tag information
alexfinnarn Feb 27, 2024
dbe29e1
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Feb 27, 2024
5f6a765
adding a note to the readme doc for json:api
alexfinnarn Feb 27, 2024
b3fd87e
fixing patch so it can apply
alexfinnarn Feb 27, 2024
6b6ec00
take out caching to debug on Tugboat
alexfinnarn Feb 27, 2024
0d53ccb
add back in caching since it wasn't the issue
alexfinnarn Feb 27, 2024
7a2b863
limit config form fields to deal with input_max_vars issue
alexfinnarn Feb 28, 2024
c5edf44
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Feb 28, 2024
4bbc9ed
update composer content hash
alexfinnarn Feb 28, 2024
b6ab456
update readme
alexfinnarn Feb 28, 2024
0f2939b
add functional test for field type enhancer for link fields
alexfinnarn Feb 28, 2024
d00e5ed
update comment
alexfinnarn Feb 28, 2024
0be1e22
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Feb 28, 2024
dcfa328
updating composer content hash
alexfinnarn Mar 13, 2024
d92fce9
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Mar 13, 2024
61a482f
updating composer content hash
alexfinnarn Mar 13, 2024
3c4dae2
updating composer content hash
alexfinnarn Mar 14, 2024
4eef7d5
Merge branch 'main' into VACMS-17021-default-field-type-enhancers
alexfinnarn Mar 14, 2024
ee323f9
updating composer content hash
alexfinnarn Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions READMES/jsonapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,34 @@ You can find JSON:API tests in the following places:

- 'tests/phpunit/API/JsonApiRequestTest' - Tests GET requests and associated configuration.
- 'tests/phpunit/API/JsonApiExplorerUITest' - Tests Swagger UI for OpenAPI documentation.

## Field Type Enhancers

JSON:API Extras allows "field enhancers" to change the normalized output sent back in a response. These are set in
configuration on "/admin/config/services/jsonapi/resource_types", but there is no way to use current configuration
and code to set a default field enhancer for all field instances of the same field type. We are calling this feature
"field type enhancers" to contrast with the current field instance enhancers tied to resources.

On "/admin/config/services/jsonapi/field_types", we added a configuration form where you can add a field type
enhancer that will apply to all fields of that type. However, if you set a field instance enhancer, that will
override the field type enhancer. So, users can set an enhancer for most of the field instances of one field type
but then customize each field instance as needed.

This custom code is in a patch, but we are trying to incorporate it into the main `jsonapi_extras` module in this issue:
https://www.drupal.org/project/jsonapi_extras/issues/3025283

To use the field instance enhancers:

1. Go to "/admin/config/services/jsonapi/resource_types" and click to edit the resource type you are working with.
2. Check the fields you want alter output for to see if they already have an enhancer applied.
3. If there is an enhancer configured for that field instance, then that is what will be used for JSON:API responses.
4. If you want to use a field type enhancer, remove the configured field instance enhancer.

To use the field type enhancers:

1. Go to "/admin/config/services/jsonapi/field_types" and check the "Included Field Types" text area.
2. If you see your field added and have an enhancer configuration form visible, then skip to step #4.
3. If the field isn't included, then add it to the textarea and save the form.
4. Adjust the enhancer type and settings to achieve the output you want for that field type and save the form.
5. All field types should now be transformed by the selected enhancer for JSON:API responses, unless a field
instance enhancer is overriding the field type enhancer.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@
"3226473 - Opt-in system delete.": "https://www.drupal.org/files/issues/2023-03-28/3226473-opt-in-system-delete-2.patch",
"3061620 - Cancel closes all forms": "https://www.drupal.org/files/issues/2022-07-21/inline_entity_form-close-only-forms-where-close-clicked-3061620-13.patch"
},
"drupal/jsonapi_extras": {
"3025283 - Default field enhancer for each field type": "patches/field-type-enhancer-3025283-3.patch"
},
"drupal/jsonapi_menu_items": {
"3276561 - Add support for the Menu Item Extras module": "https://www.drupal.org/files/issues/2022-08-01/3276561-05-menu_item_extras_support.patch"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c9df9e950f406065f385e866e17e4a72",
"content-hash": "e9a118f67eb61dfb52ad2120983a525f",
"packages": [
{
"name": "asm89/stack-cors",
Expand Down
12 changes: 12 additions & 0 deletions config/sync/jsonapi_extras.jsonapi_field_type_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
disabled: false
resourceFields:
link:
fieldName: link
enhancer:
id: url_link
settings:
absolute_url: 0
type: config_entity
label: 'JSON:API Field Type Config'
includedFieldTypes:
- link
Loading
Loading