Problem/Motivation
Follow-up from #2690007: Remove drupal_render deprecated method and refactor non-functional cleanups (see comment #29).
In that issue we have converted some entity manager wrapper in EntityReferenceRevisionsEntityFormatter (to call getViewModeOptions) and EntityReferenceRevisionsItem (to call loadEntityByUuid), and we need to test entity reference revisions default values and configuration dependencies.
Proposed resolution
- add missing schema for field type value
Basically, what you need to do is the following:
'default_value' => [
[
'target_id' => $composite->id(),
'revision_id' => $composite->getRevisionId(),
]
]To the field config, so it uses that reference as the default. When you try that, you'll notice that you get an invalid config schema error, we are missing schema for the field type value.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | test_err_default_values_and_config_dependencies-2711429-35.patch | 11.79 KB | tduong |
| #35 | test_err_default_values_and_config_dependencies-2711429-35-test_only.patch | 8.76 KB | tduong |
| #35 | interdiff-2711429-32-35.txt | 1.4 KB | tduong |
| #32 | interdiff-2711429-29-32.txt | 8.94 KB | tduong |
| #29 | interdiff-2711429-26-29.txt | 2.31 KB | tduong |
Comments
Comment #2
tduong commentedHere there is the test that get the missing config schema error message.
Comment #4
tduong commentedComment #5
tduong commentedAdded schema for field type default value.
Comment #7
tduong commentedRerolled.
Comment #9
miro_dietikerPlease don't mix unrelated code cleanups with functional fixes and adding tests.
It's really hard to review code changes to then realise they have no impact.. and finally finding the relevant pieces in all the changes.
The functional changes look pretty fine.
Comment #10
berdirThis is not related to composite. In fact, having a default value with composite doesn't really work.
Lets make a new test instead.
Comment #11
tduong commentedMoved test to
EntityReferenceRevisionsAdminTestand fixed it, used a Node instead of a composite entity. Reverted everything fromEntityReferenceRevisionsCompositeTest.Comment #13
berdirYes, having the test separate is much better to review.
Not sure if we shouldn't put it in a separate test class, possibly also a kernel test since we don't need a UI.
To test that the default value works, you want to create the node without explicitly specifying the node.
This is not checking anything, just your own code above. It doesn't call that function.
Instead, you simply want to check that $node2->target_node_reference->entity has the same id and revision id as $node 1.
Additionally, after setting the default value, save $node1 with a new revision_id, keep the old one. The default value should reference the first version, not the new one.
Second, instead of $node1 and $node2, use $node_target and $node_host or something like that.
Then this isn't needed.
This is the part that actually checks the default value dependencies.
This is where you need to check for the UUID of the content entity, if it's missing, then it doesn't work yet.
Comment #14
tduong commentedAutocomplete is not working, unless I explicitly set it on node creation. Tried to set entity form/view display to check it before/after saving the new node, but the default value is actually set correctly... I don't have any more ideas what is happening and how to fix it...
Copied also in a unit test, I have some random problem with setComponent().
Comment #17
berdirOk, took me quite a bit of debugging too but the problem was actually trivial. It's target_revision_id, not just revision_id.
As written above, I'd prefer to have this test method in \Drupal\Tests\entity_reference_revisions\Kernel\EntityReferenceRevisionsSaveTest, remove all the UI and login stuff.
Comment #18
berdirComment #20
tduong commentedAaah these trivial bugs...
Removed test from the web test and updated the unit test one.
Thanks for the big feedback :)
Comment #22
berdirThose are not settings, they are default value (and also wrong, now).
=> remove.
you shouldn't have to save the field twice, remove the first call.
We don't really set: // Resave the target node so that the default revision is not he one we want to use.
If you do want to assert this then move it up and do it after resaving the node.
It's way easier to access those values on the node object instead of using toArray(). Just write $node_host_after->target_node_reference->target_id.
The uuid check is also unnecessary and unrelated.
This missing the actually relevant part here. The content dependency on the uuid of $node_target.
Comment #23
tduong commented1-5 done.
6. not sure how to get the uuid from content dependency (?)
Comment #25
berdirIt has to be in $dependencies. If it is not there, then it's not working yet and you need to debug calculateDependencies().
Comment #26
tduong commentedAdded target_uuid to the default value configuration/schema, fixed the test.
Comment #28
berdirThis means we're not testing that the target_uuid is actually stored properly when configuring this in the UI. Not sure if that's worth doing.
I'm also not sure if we need our custom code for this. Is the calculateDependencies() method different from the parent class? Maybe we can just remove it.
Without a revision UUID, it's pretty bogus anyway.
Comment #29
tduong commentedDebugging
$default_valuein EntityReferenceRevisionsItem::calculateDependencies() there are only our target_id and target_revision_id, so I thought that we were missing target_uuid in the schema, but yeah, wasn't sure that it was the right thing or just a "hardcoded workaround"...Not sure, I've put a debug in the parent method, but it doesn't even print anything from there... and in EntityReferenceRevisionsItem::calculateDependencies() we never call the parent method...
Comment #31
berdirI think you misunderstood me.
target_uuid isn't going to magically work. We do need it.
The only question I have is if it is actually set if you select a default in the UI. I think we use standard widgets and extend from core, so it *should* work. Not sure if it's worth to add a test for this. Looking at \Drupal\entity_reference_revisions\Tests\EntityReferenceRevisionsAdminTest::testEntityReferenceRevisions, it might just work if you create the node before the field and then put that node into the $field_edit argument of static::fieldUIAddNewField(). Then you can check the UI part there and also make sure that adding it actually adds the target_uuid to the field default value.
What I mean with calculateDependencies() is that as far as I see, it's pretty much a duplicate of the parent implementation. I would recommend you just remove, and if the test still passes, then I think we can just move forward with the core implementation.
Comment #32
tduong commentedYes, thank you for the hints!
Removed
EntityReferenceRevisionsItem::calculateDependencies(), fixedEntityReferenceRevisionsSaveTest::testEntityReferenceRevisionsDefaultValue()to cover the dependencies properties part and extendedEntityReferenceRevisionsAdminTest:: testEntityReferenceRevisions()to test the default value target_uuid part.Comment #34
berdirSmall misunderstanding, I didn't mean to remove the uuid from the kernel test, we still want to have that there. Just re-add the removed/commented code from before.
Comment #35
tduong commentedReverted changes in the kernel test.
Comment #37
berdirNow we're good to go I think.
Comment #38
miro_dietikerCommitted.