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

  1. Create node and set up JSON:API for the node to be exposed via API.
  2. Make sure the path is exposed in the attributes section.
  3. Mark URL Alias as untranslatable and clear caches.
  4. 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

Issue fork drupal-3274419

Command icon 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

Alex Bukach created an issue. See original summary.

alex.bukach’s picture

Assigned: alex.bukach » Unassigned
Status: Active » Needs review
StatusFileSize
new573 bytes
alex.bukach’s picture

alex.bukach’s picture

The 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.

apmsooner’s picture

Patch works great. Cleared cache right after running patch and path showed right up for me on jsonapi routes.

apmsooner’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work
yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

Failed tests are unrelated.

Status: Reviewed & tested by the community » Needs work

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tbadaczewski’s picture

I'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.

alex.bukach’s picture

@tbadaczewski did you try the patch above?

pozi’s picture

Patch worked for me, thank you!

drugan’s picture

I've run the test against 9.5.x-dev and seems the error is unrelated.

RTBC for the #2 patch.

ravi.shankar’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC as per comments #7, #9.

drugan’s picture

Marios Anagnostopoulos made their first commit to this issue’s fork.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This 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

marios anagnostopoulos’s picture

The 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

marios anagnostopoulos’s picture

No pr yet, since tests are pending.

marios anagnostopoulos’s picture

I 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!

marios anagnostopoulos’s picture

Status: Needs work » Needs review

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shubham chandra’s picture

Issue tags: -Needs tests
StatusFileSize
new707 bytes

applied patch #2 in Drupal 10.1.x

shubham chandra’s picture

StatusFileSize
new975 bytes

applied patch #2 in Drupal 10.1.x

marios anagnostopoulos’s picture

StatusFileSize
new2.89 KB

@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.

Status: Needs review » Needs work

The last submitted patch, 33: 3274419-33.patch, failed testing. View results

marios anagnostopoulos’s picture

Status: Needs work » Needs review

Seems like the js failing tests issue is fixed (?)
I will be changing this to needs review

joaopauloc.dev’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new195.21 KB
new180.39 KB

Reviewed and tested, screenshot attached as evidence.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The implementation of isInternal() should be return $this->getBaseFieldDefinition()->isInternal();. This method should never return NULL and getBaseFieldDefinition is 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.x

marios anagnostopoulos’s picture

I 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.

alexpott’s picture

That 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.

marios anagnostopoulos’s picture

I 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) ?

alexpott’s picture

Status: Needs work » Needs review

Let'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.

marios anagnostopoulos’s picture

StatusFileSize
new2.15 KB

Sure!

marios anagnostopoulos’s picture

9.5 has some js test failure (AFAI can understand) and the second run passed.
Is there anything else to be done?

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs change record

public function isInternal() {
Should have a typehint return

Also adding a new function will require a change record.

ravi.shankar’s picture

StatusFileSize
new2.16 KB
new512 bytes

Added type hind in isInternal method, keeping the status needs work for change record.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berdir’s picture

I unpublished the change record.

efpapado’s picture

Status: Needs work » Needs review
Issue tags: +DrupalCon Lille 2023

Setting to Needs review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Fixed up the Change record some.

Rest looks fine.

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

@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!

  • alexpott committed f91e76e5 on 11.x
    Issue #3274419 by Marios Anagnostopoulos, Shubham Chandra, ravi.shankar...

  • alexpott committed 4e682c3a on 10.2.x
    Issue #3274419 by Marios Anagnostopoulos, Shubham Chandra, ravi.shankar...
alexpott’s picture

Version: 10.2.x-dev » 10.1.x-dev

Discussed with @longwave - we agreed to backport to 10.1.x and remove the CR as it is not that helpful in this case.

  • alexpott committed 06c8b1dd on 10.1.x
    Issue #3274419 by Marios Anagnostopoulos, Shubham Chandra, ravi.shankar...
wim leers’s picture

This, for example, will remove the field from JSON:API results and might have other undesired consequences.

😮 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.