Problem/Motivation

DER field makes your field dependent on every module that provides an entity type.

Proposed resolution

Only add dependencies to referenceable entity types.

Remaining tasks

  • Tests.
  • Upgrade path.
  • Upgrade path test.
  • Review.
  • Commit.

User interface changes

None

API changes

None

Data model changes

None

Comments

jibran created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
StatusFileSize
new1007 bytes

It's an easy fix but we have to update existing DER field storage config.

jibran’s picture

StatusFileSize
new0 bytes

We are not changing the existing config schema. We only need to update the existing config object so added a post-update hook.

Status: Needs review » Needs work

The last submitted patch, 3: only_add_dependencies-2839178-3.patch, failed testing.

jibran’s picture

StatusFileSize
new1.99 KB
jibran’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Nice work

dpi’s picture

Title: Only add dependencies to referenceable entity types » Fix incorrect DER field dependency calculation
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I see that it DER was already attempting to "add dependencies to referencable entity types", its just that its implementation was broken. Updated issue title to reflect this.

Why not create a hook_update_N to run these updates? instead of a post_update. You should only need to set dependencies once manually. Subsequent updates to field storage will be made with DynamicEntityReferenceItem::calculateStorageDependencies

(Note: First hook_update_N should be be 8101)

Needs tests for all variants of DynamicEntityReferenceItem::getTargetTypes

jibran’s picture

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

Why not create a hook_update_N to run these updates? instead of a post_update. You should only need to set dependencies once manually.

Update hooks are used when we change the config schema which we are not in this case because we are allowed to change the schema during update hook there is a chance the schema can be invalid and therefore we can't use entity API in update hooks. To avoid the invalid schema situation during the site update process hook_post_update is introduced so the use of post_update hook is perfectly valid in this case.

Needs tests for all variants of DynamicEntityReferenceItem::getTargetTypes

Well it'd be great to have the tests for this but upgrade path test to update field config are not easy to write you need to update the whole config table manually to add fields on top of that you have to enable the DER during the DB import which is also a pain. I don't want to invest so much energy in re-saving of a config entity. If someone is interested in writing the test please feel free to report a follow-up task. I'll be more than happy to help them out.

Anyway, thanks for the review. Your input is always useful. And thank you for reporting #2844921: Rename dynamic_entity_reference_update_8001.

While writing the reply is reviewed the patch again and I think it is ready. Let's get this in and if someone will hit a bug we can always write tests for it then. :P

  • jibran committed e6dfb7d on 8.x-1.x
    Issue #2839178 by jibran, larowlan, dpi: Fix incorrect DER field...
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x-1.x. Because 8.x-2.x in alpha so I didn't commit the post_update hook. Thanks!

  • jibran committed 3a3ab6d on 8.x-2.x
    Issue #2839178 by jibran, larowlan, dpi: Fix incorrect DER field...
dpi’s picture

To avoid the invalid schema situation

Modify the config directly via configFactory. Example of dep update in field_update_8002.

Well it'd be great to have the tests for this but upgrade path test to update field config ar

I didn't mean update path tests, although that would be great.

I mean to test that dependencies were created depending on target types:

  • Create some DER field [storage]
  • Set the target_type manually (test each variant)
  • Save the storage.
  • Then assert the dependencies were added.
jibran’s picture

Modify the config directly via configFactory. Example of dep update in field_update_8002.Modify the config directly via configFactory. Example of dep update in field_update_8002.

Well, that should be done in post_update hook. Let me confirm that with @alexpott and @amateescu.

I mean to test that dependencies were created depending on target types:

Oh! for this yeah we can add some asserts to an existing KTB. We are creating tons of fields in tests.

dpi’s picture

I found the entity_reference dependency test:

\Drupal\KernelTests\Core\Entity\EntityReferenceFieldTest::testEntityReferenceFieldDependencies

Obviously DER would need to add more tests than this.

dpi’s picture

Status: Fixed » Active

Changing to active, at least for the tests.

dpi’s picture

Tests for settings variants modifying dependencies.

---

A new test class was created instead of using DynamicEntityReferenceFieldTest, rationale:

  • Create a different unsaved field storage each time
  • The field config instance is not required, only storage
  • I need more referable entity types, not just the one defined in its class constants.

The reason there is another test entity is so that a new provider is made available for diffing.

I used the $canonicalize param in assertEquals. This ignores order of array values, and therefore keeps the $expected variables clean.

For my reference: https://github.com/dpi/dynamic_entity_reference/tree/field-dependencies-...

dpi’s picture

Status: Active » Needs review
StatusFileSize
new6.04 KB

You might need this

jibran’s picture

Awesome! work. Here is a test only patch.

Status: Needs review » Needs work

The last submitted patch, 19: fix_incorrect_der_field-2839178-19-test-only.patch, failed testing.

dpi’s picture

0/4 new tests pass. Looks good to go.

  • jibran committed d8cf3e0 on 8.x-1.x authored by dpi
    Issue #2839178 by jibran, dpi, larowlan: Fix incorrect DER field...

  • jibran committed cb006c6 on 8.x-2.x authored by dpi
    Issue #2839178 by jibran, dpi, larowlan: Fix incorrect DER field...
jibran’s picture

Status: Needs work » Fixed

Indeed. Thanks! Committed and pushed to 8.x-1.x and 8.x-2.x

Status: Fixed » Closed (fixed)

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