Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When you add fields in a referenced entity in the IndexAddFieldsForm only base fields of the referenced entities are shown.
For example:
- create a new content type
- add a reference field to a taxonomy
- in the taxonomy add a text field in the UI
- create a search api index of type content
- go to add fields
- expand the taxonomy reference field you created in the second step
- only the base fields of the taxonomy are shown, but the the new text field is missing and can't be indexed
Comment | File | Size | Author |
---|---|---|---|
#29 | 2680405-29--nested_non_base_fields.patch | 11.35 KB | drunken monkey |
Comments
Comment #2
miiimoooI'm attaching a patch that fixes the problem. The issue is caused by the getPropertyDefinitions method in core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php
It doesn't correctly get the bundles (and even if it did it would only work if there was only one bundle see https://www.drupal.org/node/2169813)
The patch has a small cosmetic problem: it adds the fields with a parent of Array which I hope is easy to fix.
Comment #3
miiimoooComment #4
jjcarrionI have fixed the "cosmetic" problem renaming the $label. I'm attaching the patch and the interdiff.
It works fine for me and I'll test it more during these days. Great work miiimooo!
Comment #5
jjcarrionIt's seems that with the patch we have lost some filters in the view:
Anyway, in the database the information is stored properly.
Anyone can point me where should be the problem?
Comment #6
jjcarrionI have solved the issue that doesn't show the fields in the view with this patch.
But I'm getting a new error when I save the view.
I have seen that this error is similar to #2664286: Cannot use date filters on index but in this case it's not a date type.
If somebody knows where could be the problem I can try to solve it. Thanks in advance!
Comment #7
drunken monkeyAre you sure that error is caused by this patch? It seems rather unconnected.
In any case, thanks for creating this issue and working on it, the solution already looks quite good.
Contrary to the second change, in
Field
, it seems here you forgot to initialize$nested_properties
for complex properties.In any case, though, instead of duplicating code, we should maybe add this to the
Utility
class – either just for getting the child properties of the given properties, or already in a form that allows drilling down (if that makes sense and is possible to refactor/abstract.Also, as always when breaking things that worked previously, it would be great if we could add a check somewhere in our testing suite that makes sure this won't happen again. Probably, just a few lines in
IntegrationTest
would suffice.Comment #8
jjcarrionHi drunken monkey,
I'm not sure that the error that I'm getting because of the patch, but I get that error with the fields that now I can add after applying the patch.
Anyway, I'm agree with you that can be another issue, so I'll do that refactor and I'll try to do that test.
In my project I'm using a custom controller and I'm querying search_api from there because of the error, so I'll try to do this during the weekend.
Thanks for you help!
Comment #9
jjcarrionI haven't made the test yet, but here it's the refactor to not duplicate the code. I have created the `getNestedProperties` method in the `Utility` class. I hope that could be Ok.
Comment #10
yobottehg CreditAttribution: yobottehg commentedis it possible to take entity_reference_revisions new composite relationship into account so it is possible to index paragraphs in the future ?
The current patch works with paragraphs but i'm not sure it works after the migration to the new entity_reference_revisions composite relationship.
Comment #11
drunken monkey@ jjcarrion: While #6 still applies for me, #9 somehow doesn't. Did you maybe make some mistake while creating it?
@ yobottehg: I'm sorry, but I can't take all contrib modules into account. If your module doesn't work with the Search API out-of-the-box, you can always override the datasource, or provide your own new one. I'll only fix problems if you can show me we're using the Entity API incorrectly, or if a change would be generally beneficial.
Also, in what way is that related to this issue?
Comment #12
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commented@yobottehg, we should still be fine as entity_reference_revisions DataType extends the EntityReference (which implements the DataReferenceInterface which search_api expects) class so "instanceof DataReferenceInterface" will still return TRUE on ERR field which should make the extraction work.
Didn't test it though.
Comment #13
yobottehg CreditAttribution: yobottehg commented@ drunken monkey sorry for crashing this issue, but it's related. And thanks @jeroen.b for clarifing.
Comment #14
jjcarrionI have reroll the patch to make it work with the actual version, I was touching some code standards that were breaking the patch.
Here is the new patch, but nothing about the testing part yet. If somebody can point me a similar test that I can start with I can try it as well.
Thanks!
Comment #15
drunken monkeyI'd probably do it in
IntegrationTest
: just go to an appropriately nested path and see if one of the non-base fields there is present.Problem is, though, I don't think there's any appropriate reference on nodes currently in there, so you'd have to add one – probably best just an entity reference to a different node, that way you don't have to add an additional module (I think).
Would be great, if you could work on that, thanks! (Also thanks for the re-roll!)
(Setting to "Needs review" for the test bot, still needs tests, as said.)
Comment #18
drunken monkeyGood to see all existing tests pass, at least. Setting to "Needs work" for the tests.
Comment #19
johnchqueThanks everyone for the previous patches, we are using this with entity reference revision and we found out that the patch #14 fixes our problem. I added some tests here, not really sure if this is enough or if we should check something else.
Comment #20
BerdirThat's a good start, but that's just seeing the field.
I think we also want to test actually adding that field, indexing content that has such a reference and checking that it is being indexed (I guess the easiest way to do that is to just search for the text inside the reference?)
Comment #21
drunken monkeyThanks for adding the test!
See the attached for a re-roll and a few minor fixes.
Berdir is right, though, we should also test indexing of the nested fields – and, since I just made a modification there, too, also that the dependencies for these fields are computed correctly.
Indexing will have to be tested in a different test, though, unless we add some way to inspect the indexed items with the test backend (which could be handy, though).
Comment #26
johnchque@drunken monkey thank you for the patch, I've been looking into it but could not realize why the tests are failing. Do the tests need an extra fix?
Comment #27
drunken monkeyLet's try it like this?
Comment #28
borisson_This looks like a good solution, it has test coverage as well. Woo!
Comment #29
drunken monkeyAs noted in #20 and #21, it didn't have quite enough test coverage yet.
Should be fixed with the attached patch, though. If the test bot and one of you agree, I'd say this is RTBC.
Comment #30
johnchqueThis looks good to me! Thank you so much @drunken monkey!
Comment #32
drunken monkeyExcellent, good to hear!
Committed.
Thanks again, everyone!
Comment #33
drunken monkey