Problem/Motivation
When a base field (e.g. entity path) properties are changed (e.g. it is made non-translatable), it's isInternal() method is inherited from FieldConfigBase, so that any computed field becomes internal though initially the field might be non-internal. This, for example, will remove the field from JSON:API results and might have other undesired consequences.
Steps to reproduce
- Create node and set up JSON:API for the node to be exposed via API.
- Make sure the path is exposed in the attributes section.
- Mark URL Alias as untranslatable and clear caches.
- See that the path has disappeared from the JSON:API response.
Proposed resolution
The correct approach is to inherit the internal property from the base field definition like other properties like "computed" and "read only" are.
Remaining tasks
Change record
Review code.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | interdiff_42-45.txt | 512 bytes | ravi.shankar |
| #45 | 3274419-45.patch | 2.16 KB | ravi.shankar |
| #42 | 3274419-42.patch | 2.15 KB | marios anagnostopoulos |
| #36 | after-patch.png | 180.39 KB | joaopauloc.dev |
| #36 | before-patch.png | 195.21 KB | joaopauloc.dev |
Issue fork drupal-3274419
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
alex.bukach commentedComment #3
alex.bukach commentedComment #4
alex.bukach commentedComment #5
alex.bukach commentedThe referenced issues propose to delete base field override config to fix the issue. However this does not look to be an appropriate solution if the field actually needs to be overridden like in the case described.
Comment #6
apmsooner commentedPatch works great. Cleared cache right after running patch and path showed right up for me on jsonapi routes.
Comment #7
apmsooner commentedComment #9
yogeshmpawarFailed tests are unrelated.
Comment #12
tbadaczewski commentedI'm experiencing this problem, and since the JSON:API is so critical in providing content for my GatsbyJS frontend it's really hurting my attempts at generating a multi-lingual site.
Comment #13
alex.bukach commented@tbadaczewski did you try the patch above?
Comment #14
pozi commentedPatch worked for me, thank you!
Comment #15
drugan commentedI've run the test against 9.5.x-dev and seems the error is unrelated.
RTBC for the #2 patch.
Comment #16
ravi.shankar commentedBack to RTBC as per comments #7, #9.
Comment #17
drugan commentedComment #19
alexpottThis makes sense to me but it'd be great to add some test coverage. I would have thought it would be possible to add coverage of this to \Drupal\KernelTests\Core\Field\Entity\BaseFieldOverrideTest
Comment #20
marios anagnostopoulos commentedThe internal property is also used by the default content module to determine what field to export.
I made some changes to the provided patch as per this issue https://www.drupal.org/project/drupal/issues/2321071
Also I would suggest to change the syntax for the 10.x branch to
return $base_field_definition?->isInternal();since we have php8+ goodies there.For that reason I created a second branch for the 10.1.x
Comment #21
marios anagnostopoulos commentedNo pr yet, since tests are pending.
Comment #25
marios anagnostopoulos commentedI ended up making a new branch for 9.5.x since the rebase was taking forever :S
I made the proposed changes. Let me know if it's good to go, so that I can apply the same changes to the 10.x branch
Cheers!
Comment #26
marios anagnostopoulos commentedComment #31
shubham chandra commentedapplied patch #2 in Drupal 10.1.x
Comment #32
shubham chandra commentedapplied patch #2 in Drupal 10.1.x
Comment #33
marios anagnostopoulos commented@shubham-chandra The changes are in a pr for the 10.1.x branch already, but in case you need a patch, there you go.
Comment #35
marios anagnostopoulos commentedSeems like the js failing tests issue is fixed (?)
I will be changing this to needs review
Comment #36
joaopauloc.dev commentedReviewed and tested, screenshot attached as evidence.
Comment #37
alexpottThe implementation of
isInternal()should bereturn $this->getBaseFieldDefinition()->isInternal();. This method should never return NULL andgetBaseFieldDefinitionis guaranteed to either return a definition or error because an array key is not set. The change should be the same for 9.5.x and 10.xComment #38
marios anagnostopoulos commentedI will change it back then. I included the null-safe because I saw that a similar approach was used here
I will add a note to this issue as well.
Comment #39
alexpottThat issue is changing how
getBaseFieldDefinition()works - if that one lands after this it'll need to be make the change but and vice versa but that issue has not landed yet.Comment #40
marios anagnostopoulos commentedI made the suggested corrections.
We could also add return type hinting for bool at the 10.x branch, or is it better to do it later in a different issue for more functions than just this (If at all) ?
Comment #41
alexpottLet's not add return typehinting... for new methods / interfaces sure but exsiting stuff let's leave alone.
Can you post a patch some we can test on multiple branches? Thanks.
Comment #42
marios anagnostopoulos commentedSure!
Comment #43
marios anagnostopoulos commented9.5 has some js test failure (AFAI can understand) and the second run passed.
Is there anything else to be done?
Comment #44
smustgrave commentedpublic function isInternal() {Should have a typehint return
Also adding a new function will require a change record.
Comment #45
ravi.shankar commentedAdded type hind in
isInternalmethod, keeping the status needs work for change record.Comment #47
berdirI unpublished the change record.
Comment #48
efpapado commentedSetting to Needs review.
Comment #50
smustgrave commentedFixed up the Change record some.
Rest looks fine.
Comment #51
alexpott@efpapado that MR against 11.x is not necessary. The MR against 10.1.x cna be applied to 11.x just fine.
Committed and pushed f91e76e505e to 11.x and 4e682c3a68e to 10.2.x. Thanks!
Comment #54
alexpottDiscussed with @longwave - we agreed to backport to 10.1.x and remove the CR as it is not that helpful in this case.
Comment #56
wim leers😮 wow, this was an important oversight in #2871591: Allow ComplexData in TypedData to specify computed properties that should be exposed in normalization and other contexts! Nice find.