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.
I think we could use https://www.drupal.org/project/dynamic_entity_reference for our field and get a lot of win out of it.
Comment | File | Size | Author |
---|---|---|---|
#59 | interdiff-2315599-59.txt | 609 bytes | thenchev |
#59 | consider_dynamic_entity-2315599-59.patch | 75.78 KB | thenchev |
| |||
#58 | interdiff-2315599-58.txt | 7.39 KB | thenchev |
#58 | consider_dynamic_entity-2315599-58.patch | 75.8 KB | thenchev |
| |||
#55 | interdiff-2315599-55.txt | 15.25 KB | thenchev |
Comments
Comment #1
mikran CreditAttribution: mikran commentedNow that entityreference is in core the future statement on module page is mostly invalidated and it is good for Relation's future to play nicely with other modules. We definitely should replace endpoints with that.
Comment #2
mikran CreditAttribution: mikran commentedI just deleted relation_endpoint module and added dynamic_entity_reference to replace that on branch
8.x-1.x-der
. There is probably going to be challenges with directionality. So far r_index = 0 has meant that entity is source for all others (1:n) but with delta ordering this could probably be solved with 2 instances for directional relations (n:m). What drawbacks would there be for such solution? We wouldn't need our own config for source & target entity bundles. Querying related entities would be harder if you want to ignore directionality.Comment #3
chx CreditAttribution: chx commentedI have been out of development for years, but to be honest, I do not understand. The only change to the architecture is that we have a 3rd party module instead of relation_endpoint and yes delta stands in for r_index. I am not quite sure what the problem is? Same joins, same ideas, just different table and different column names.
Comment #4
mikran CreditAttribution: mikran commentedI was thinking about the widget and entity bundle config that comes with dynamic entity reference. There you can reorder items and all items share the same entity limitations. Both of these are problematic for directional relations as we want to support different bundle settings for source and target entities.
Comment #5
mikran CreditAttribution: mikran commentedhmm. one option could be to create a new edit widget for directional relations. Built in widget works just fine for non-directional relations with added extra validation for min arity and uniqueness of endpoints.
Comment #6
chx CreditAttribution: chx commentedFor directional you might need to disable reordering... at least the first needs to be the first. Tricky I know :(
Comment #7
chx CreditAttribution: chx commentedPerhaps break the first out on its own?
Comment #8
mikran CreditAttribution: mikran commentedYeah it's probably better to break the first out. Reordering is a cool feature.
Comment #9
mikran CreditAttribution: mikran commentedI've added a new add relation UI to make widget testing a bit easier
Comment #10
jibranThanks @chx for creating the issue. @mikran please have a look at DER issue queue and let me and @larowlan now if we can be any help. Feel free to create feature requests there. Can you please post some roadmap or updates of your work so that I can keep up with it? Thank you for using DER.
Comment #11
mikran CreditAttribution: mikran commentedOkay so delta is used to replace r_index in storage, but, delta can not be used as condition in queries, right?
Comment #12
chx CreditAttribution: chx commentedhttps://www.drupal.org/node/2384459
Comment #13
mikran CreditAttribution: mikran commentedFrom now on the DER branch is built on top of the latest patch from #2384459: Add entity query condition for delta in EFQ as it's clear that this project can't continue without that.
Patches that are not directly related to DER should still be rolled against 8.x-1.x branch first and I'll then merge them to 8.x-1.x-der so both branches are somewhat usable. (and once it's 100% sure that DER is the way to go that branch will be merged to 8.x-1.x).
Comment #14
mikran CreditAttribution: mikran commented#2407587: Allow multiple target entity types in the entity reference field
That most likely means that we don't need Dynamic Entity Reference as dependency and that definitely means that this is the way forward and I'll soon merge this branch to main 8.x-1.x branch for easier development.
Comment #15
dpiLooks uncertain for now, since #2407505: [meta] Finalize the menu links (and other user-entered paths) system is going in a different direction.
Do we have a problem with depending on dynamic_entity_reference?
Comment #16
mikran CreditAttribution: mikran commentedNo we don't.
DER version works better already so maybe it's waste of time to keep 2 branches active?
Comment #17
chx CreditAttribution: chx commentedSome ideas from https://www.drupal.org/project/field_lock_multi_values could be used to disable reordering, alas it's D7 ATM.
Comment #18
mikran CreditAttribution: mikran commentedAnd a patch.
Comment #19
donquixote CreditAttribution: donquixote as a volunteer commented(Forgive me if my post is poorly informed. I just started looking at the relation module.)
Why not use regular non-dynamic entity reference?
As I see it, there are two relevant cases:
1. Possibly symmetric, possibly transitive, relation, within the same entity type.
2. Directional relation, which can have distinct source and target entity type.
For 1., a multiple-value entityreference field can be used.
For 2., two single-value entityreference fields can be used.
Maybe there is an exotic 3rd case, where a symmetric and/or transitive relation exists across entity types. But this seems rather rare.
Maybe also a 4th case, directional relation with more than 2 end points.
In these special cases we could use dynamic entity reference, or just additional entity reference fields.
If the different cases are treated separately, simple entityreference will be sufficient most of the time.
See also #2684867: Equivalent to custom entity type + 2x entity reference?
Comment #20
donquixote CreditAttribution: donquixote as a volunteer commentedIn fact, for the most simple case of directional relation from one entity type to another, it would be sufficient to just have 2 integer columns in the main relation table.
Of course this would mean that this table cannot be reused for other non-symmetric relation types. And thus, there would have to be different relation entity types, for different types of relations. Maybe not desirable.
Comment #21
chx CreditAttribution: chx commentedentity reference hardwires the target entity type as a setting. relation doesn't. End.
Comment #22
donquixote CreditAttribution: donquixote as a volunteer commentedBut in most real-world cases, hard-wiring the source and target type is the intended behavior.
This would allow to use entityreference for these cases, and only use dynamic entity reference for cases that need to have a dynamic source and target type.
Obviously, if the same approach should be used across all relations, then it has to be dynamic entity reference.
Comment #23
chx CreditAttribution: chx commentedI believe it would be a maintenance nightmare to maintain two code paths depending on how many entity types an endpoint can be. Such flexibility always been the best and worst feature of relation.
Comment #24
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedBoth #2384459: Add entity query condition for delta in EFQ and code in this module changed a lot. This patch definitely needs a reroll.
Comment #25
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedThat patch is quite a bit behind the 8.x-1.x-der branch so here is the latest.
Comment #26
james.williams CreditAttribution: james.williams at ComputerMinds commentedHere's a re-rolled patch based on all the latest code :-)
Comment #27
james.williams CreditAttribution: james.williams at ComputerMinds commentedBuilding on the last patch (comment 26), this patch also fixes the following:
* Show the 'add relation' action on the relation list page correctly
* Query target columns of the DER field table rather than those that were for relation_endpoint
* Fix links & redirects for the add relation page
* Fixed error on creation of relations from add relation page.
* Configured DER instance appropriately for a relation, given the relation's allowed bundles settings (this makes use of #2405467-22: Add EntityType and Bundle constraint on entity property of DynamicEntityReferenceItem, which ensures validation actually happens and gives the user feedback)
Comment #28
james.williams CreditAttribution: james.williams at ComputerMinds commentedUnfortunately the item in my last point in my previous comment does not work correctly, and I've run out of time to work on this. I hadn't realised that the allowed entity types are *only* set on the FieldStorage, whereas only the allowed *bundles* are set on the field instance - which then also meant relation+DER weren't appropriate for my use case either so I've had to move on.
Here's the 'fix' for the error that would otherwise occur (with interdiff), and TODOs in code for the outstanding problems that I had intended to work on, so someone else should at least be able to pick this up now. I would suggest at least updating the 8.x-1.x-der branch with this perhaps, so that it is still more usable for others to make progress with?
Comment #29
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedpatches 26, 27 and 28 committed to der branch, thanks!
Comment #30
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedOk let's change this to 'Needs review', is there something that we absolutely have to do before merging this to main branch?
DER provides so much more features than current state of relation endpoints that I think all efforts should be focused on just one branch now.
Comment #31
james.williams CreditAttribution: james.williams at ComputerMinds commentedAs I said in my last comment, the allowed bundles of relations go through validation, via the work done under #2405467-22: Add EntityType and Bundle constraint on entity property of DynamicEntityReferenceItem, but the validation done is not correct. Please see the '@TODO' comments in the code. The allowed bundle settings are not where the current code expected them to be, so the code needs changing to adapt, though that will become trickier as that means the validation cannot simply be done at the level of the DER field items.
Comment #34
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedComment #35
jibran#2405467: Add EntityType and Bundle constraint on entity property of DynamicEntityReferenceItem is fixed. Can you please try a new dev release and report any bugs regarding that issue? Thanks!
Comment #36
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commented-der
branch is quite out of date. We would need to merge8.x-1.x
and resolve conflicts. We also need to look at tests, which are currently failing in-der
branch.@Denchev will look at bundle validation and provide feedback.
Let's make this ready for merging and push it over the finish line.
Comment #37
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commented@Denchev rerolled
-der
branch and I pushed the update. Attaching 8.x-1.x...8.x-1.x-der patch to see what testbot thinks about it.Comment #39
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedHere are some test fixes. There should be a few remaining related to directional relationship. Working on that part.
Comment #41
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedForgot about that. We need the test dependency.
Comment #43
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedDone.
Comment #44
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedpatch from #39
Comment #46
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedWhile working on the test fails I had problems with the condition:
in relation.module relation_query_add_related() it just looks like its ignored.
This is the query i get in the end:
it works when i delete the second inner join and changed the relation__endpoints_2 to relation__endpoints. Maybe someone has an idea, looks like a bug?
Comment #47
jibran1.0 is out :D
Shouldn't we add DER here as well?
Comment #48
BerdirThis is actually documented, yay me and @slashrsm ;)
If you want another condition to be considered in combination with a delta, you need to include %delta in the path.
That's because the query builder takes the prefix of the condition as an identifier for the joins it builds. Same prefix = same join.
It might work if you always include it, not sure, otherwise do it as an if/else with two separate conditions.
Comment #49
thenchev CreditAttribution: thenchev at MD Systems GmbH commented#47.1 Nice! changed
#47.2 Yes definitely. Removed by mistake.
#48 Thanks for the help. This helped. I think there are more fails. looking into it...
Comment #51
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedComment #53
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedyea, not getting the delta like this..
Comment #54
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedGreat progress. Few comments:
Let's convert those two to one-liners. No need for variable assignments IMO.
Comment is nice, but probably shouldn't be TODO. Is there anything actionable here?
This isn't DER actually. It is core's default selection plugin.
Strange thing about it is the fact that it actually allows wildcard for bundles, but it doesn't allow this to be selected in UI. Go figure... We should probably open an issue about that if it is not already.
See: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Entity/Plugi...
Core now provides generic logic for that. We should use that.
See #2666792: Provide a route provider for add-page of entities for more info and #2716135: Use add page implementation from core for example implementation.
Do we really need to assign new variable?
Var that we're building here seems to be unused with the new code.
Comment #55
thenchev CreditAttribution: thenchev at MD Systems GmbH commented1. done.
2. Left the comment for now. Not sure but can't we add the selected entity type ids from Relation type. That what i did here.
3. Also left the comment for reference, will remove if were ok with the changes. #2831751: In default selection plugin allow wildcard
4. Should be done.
5. Looks more readable like this but changed it like proposed.
6. We are not using the RelationListBuilder?
Comment #56
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedJust one more note on this.
Currently when we edit an already created relation type the endpoints field, that already exists is not updated.
I can create a followup issue for this...
Comment #57
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedWe are. But not the
$entities
array built in that loop.No, it does not. Specially if done right. (
$endpoint->target_type
and$endpoint->target_id
)Yes, please do. Is this the only follow-up that we need or are there more? Is validation complete?
I think that we want to keep this template. Why did you decide to remove it?
Comment #58
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedSorry missed that...
1. Removed the foreach
2. Fixed endpoints part
3. Yes, there might be one more. Have to test it to confirm but... For all the entities that are not selected when we create the relation type i set the target bundle to an empty array. That way we don't allow any bundle from that entity. If a new entity is added, i think, it will pass validation. I will leave a comment when i know for sure.
4. Reverted that change, I thought we didn't need it.
Comment #59
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedForgot to uncomment the locked. Was for testing.
Comment #60
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedLooks good to me. There are follow-ups, but I think that we can commit this and tackle those afterwards.
Comment #61
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedFollowups:
#2833635: Update endpoints field when relation type is updated
#2833645: After adding new entity fatal when creating relation
Comment #62
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedNice!
This will break all existing d8 installations, and as we don't have releases yet we don't have any good way to communicate this major change. I can think of 2 options. We can add a notice text to relation module page or we can open a new 8.x-2.x branch for this new relation architecture.
We've clearly communicated that there will be absolutely no upgrade path so that isn't a problem. But I know I will have to update a installation or two so there will be at least some experimental update scripts coming in future. To make that a bit easier I vote for 8.x-2.x branch.
Comment #63
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedWorks for me. I think that we should clearly state that there is no further development planned on 1.x branch.
Comment #66
mikran CreditAttribution: mikran at Mediamaisteri Oy commentedNew 8.x-2.x branch has now been opened for this.