Problem/Motivation
I've configured my site to not use a field prefix. EntityInheritRemoveSystemFields::filterFields() has field_ hardcoded so this module fails to sync field values.
Steps to reproduce
Change the default field prefix (#1393094: Make the field prefix in Field ui configurable), create a field on a content type, and then edit and save a node which should inherit.
Proposed resolution
Switch to using the contents of 'field_storage_config' for comparison which is the list of fields displayed on /admin/reports/fields
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_inherit-respect_field_prefix-3224101-2.patch | 958 bytes | ericras |
Comments
Comment #2
ericras commentedComment #3
alberto56 commentedSetting to needs work based on the following issues.
If you have Docker installed on your development machine and you are using Mac or Linux, you can do the following:
(Please make sure to apply your patch to the latest dev version of the code, I made a change tonight)
First issue: dependency injection
So the fix to this should be rather simple: instead of using
\Drupal::entityTypeManager()You can use
$app->getEntityTypeManager()In this case $app is an argument to the application singleton, which has entityTypeManager injected into it as a service.
Second issue: automated unit tests
Again, if you can docker, you can run:
So this has to do with the fact that \Drupal is hard-coded and not dependency-injected.
We use a version of PHPUnit which has no knowledge of Drupal, so we need to mock everything which is related to Drupal.
The actual unit test for EntityInheritRemoveSystemFields::filterFields() is in tests/src/Unit/Plugin/EntityInheritPlugin/EntityInheritRemoveSystemFieldsTest.php. What I would do is wrap your check for whether a field is valid or not within another method, say $this->fieldExists() or something, then mock that in the unit test using the technique described in https://blog.nona.digital/mocking-in-phpunit/.
Finally, all tests will need to pass when you have Docker running and you run:
./scripts/ci.shbefore we commit the patch. Thanks!