Problem/Motivation

Some entity types can declare base fields as computed to prevent having to store their data.
Modules can alter the base fields per entity type or per bundle using dedicated hooks so they can also add new computed (or not) fields.
We should be able to alter the fields that are exported so every project can define its own rules.

Proposed resolution

Add an alter hook to filter out fields from the field list in \Drupal\default_content\Normalizer\ContentEntityNormalizer::getFieldsToNormalize()

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

DuaelFr created an issue. See original summary.

duaelfr’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

I'm dropping this here but I suppose it's going to need some testing to ensure it's not breaking anything important :)
It could benefit from a test coverage extension too.

berdir’s picture

Passing tests but not all computed fields are read-only. this might break content_moderation integration for example? Maybe better to check for read-only fields, but of course the computed fields would need to set that correctly.

alphawebgroup’s picture

That's not relevant for every case in the world...
We also should have an option where we can export/import computed fields.

marios anagnostopoulos’s picture

Status: Needs review » Needs work

Auto generated path aliases are also computed fields and probably need to be included in your export files, otherwise the entities will need to be resaved in order to generate it.

That probably means that a "read-only" check is not sufficient. Maybe we should also add some mechanism for exclusions.

I am changing this to needs work.

duaelfr’s picture

Title: Do not export Computed fields » Allow to alter exported fields
Issue summary: View changes

Changing scope and IS according to #3, #4 and #5.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new3.43 KB

Gitlab seems to be broken for now so uploading a patch instead of opening a MR

leksat’s picture

Status: Needs review » Reviewed & tested by the community

#7 works like a charm. Really like the approach! Every project can do its own thing now.

yobottehg made their first commit to this issue’s fork.

andypost’s picture

Status: Reviewed & tested by the community » Needs work

This change is fragile and needs some test

s.messaris’s picture

Issue tags: +Needs tests

sickness29 made their first commit to this issue’s fork.

sickness29’s picture

Status: Needs work » Needs review

Fixed code quality and added test, please have a look

boazpoolman’s picture

StatusFileSize
new15.17 KB

This feature is working wonders for me, thank you!

I'm uploading a patch here with all the changes from the MR.
All the credits to the authors, I'm just uploading so that I can use the patch in my composer.json.